Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "string-auto-indent"
version = "0.1.0"
version = "0.1.1"
authors = ["Jeremy Harris <jeremy.harris@zenosmosis.com>"]
edition = "2021"
description = "Normalizes multi-line string indentation while preserving platform-specific line endings."
Expand Down
137 changes: 37 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,122 +21,59 @@ When working with multi-line strings inside indented code blocks, unwanted leadi

`string-auto-indent` provides an automated way to normalize multi-line strings without modifying the first line's indentation.

## Installation
## Install

```sh
cargo add string-auto-indent
```

## Usage

## Example 1: Basic Indentation

This example removes unnecessary leading spaces while preserving the relative indentation of nested lines.

```rust
use string_auto_indent::{auto_indent, LineEnding};

let text = r#"
String Auto Indent

Level 1
Level 2
Level 3
"#;

// Expected output after applying auto indentation
let expected = r#"
String Auto Indent

Level 1
Level 2
Level 3
let excessively_indented_text = r#"
Best Practices for Text Indentation
-----------------------------------

1. Importance of Proper Indentation
a. Enhances readability by clearly defining structure.
b. Prevents misinterpretation of hierarchical content.
c. Improves maintainability in collaborative environments.

2. Common Indentation Guidelines
a. Use consistent spacing (e.g., 2 or 4 spaces per level).
b. Avoid mixing spaces and tabs to ensure uniform formatting.
c. Align nested elements to maintain structural clarity.
1b. Maintain relative indentation depth across all nested elements.
2b. Ensure indentation reflects logical hierarchy.
"#;


// Expected output after applying `auto_indent`
let normalized_indentation = r#"
Best Practices for Text Indentation
-----------------------------------

1. Importance of Proper Indentation
a. Enhances readability by clearly defining structure.
b. Prevents misinterpretation of hierarchical content.
c. Improves maintainability in collaborative environments.

2. Common Indentation Guidelines
a. Use consistent spacing (e.g., 2 or 4 spaces per level).
b. Avoid mixing spaces and tabs to ensure uniform formatting.
c. Align nested elements to maintain structural clarity.
1b. Maintain relative indentation depth across all nested elements.
2b. Ensure indentation reflects logical hierarchy.
"#;

// Verify that `auto_indent` correctly normalizes indentation
assert_eq!(
auto_indent(text),
expected,
auto_indent(excessively_indented_text),
normalized_indentation,
"The auto_indent function should normalize leading whitespace."
);

// Ensure the original text is not identical to the expected output
// This confirms that `auto_indent` actually modifies the string.
assert_ne!(
text,
expected,
"The original text should *not* be identical to the expected output before normalization."
);
```

### Example Output

#### With `auto-indent`

```text
String Auto Indent

Level 1
Level 2
Level 3
```

#### Without `auto-intent`

```text
String Auto Indent

Level 1
Level 2
Level 3
```

## Example 2: Mixed Indentation

This example demonstrates how `auto_indent` normalizes inconsistent indentation while preserving the relative structure of nested content.

```rust
use string_auto_indent::{auto_indent, LineEnding};

let text = r#"
String Auto Indent

1. Point 1
a. Sub point a
b. Sub point b
2. Point 2
a. Sub point a
b. Sub piont b
1b. Sub piont 1b
"#;

// Expected output after applying auto indentation
let expected = r#"
String Auto Indent

1. Point 1
a. Sub point a
b. Sub point b
2. Point 2
a. Sub point a
b. Sub piont b
1b. Sub piont 1b
"#;

// Verify that `auto_indent` correctly normalizes indentation
assert_eq!(
auto_indent(text),
expected,
"The auto_indent function should normalize leading whitespace."
);

// Ensure the original text is not identical to the expected output
// This confirms that `auto_indent` actually modifies the string.
assert_ne!(
text,
expected,
"The original text should *not* be identical to the expected output before normalization."
);
```

## How It Works
Expand Down