@@ -21,122 +21,59 @@ When working with multi-line strings inside indented code blocks, unwanted leadi
2121
2222` string-auto-indent ` provides an automated way to normalize multi-line strings without modifying the first line's indentation.
2323
24- ## Installation
24+ ## Install
2525
2626``` sh
2727cargo add string-auto-indent
2828```
2929
3030## Usage
3131
32- ## Example 1: Basic Indentation
33-
34- This example removes unnecessary leading spaces while preserving the relative indentation of nested lines.
35-
3632``` rust
3733use string_auto_indent :: {auto_indent, LineEnding };
3834
39- let text = r # "
40- String Auto Indent
41-
42- Level 1
43- Level 2
44- Level 3
45- " # ;
46-
47- // Expected output after applying auto indentation
48- let expected = r # "
49- String Auto Indent
50-
51- Level 1
52- Level 2
53- Level 3
35+ let excessively_indented_text = r # "
36+ Best Practices for Text Indentation
37+ -----------------------------------
38+
39+ 1. Importance of Proper Indentation
40+ a. Enhances readability by clearly defining structure.
41+ b. Prevents misinterpretation of hierarchical content.
42+ c. Improves maintainability in collaborative environments.
43+
44+ 2. Common Indentation Guidelines
45+ a. Use consistent spacing (e.g., 2 or 4 spaces per level).
46+ b. Avoid mixing spaces and tabs to ensure uniform formatting.
47+ c. Align nested elements to maintain structural clarity.
48+ 1b. Maintain relative indentation depth across all nested elements.
49+ 2b. Ensure indentation reflects logical hierarchy.
50+ " # ;
51+
52+
53+ // Expected output after applying `auto_indent`
54+ let normalized_indentation = r # "
55+ Best Practices for Text Indentation
56+ -----------------------------------
57+
58+ 1. Importance of Proper Indentation
59+ a. Enhances readability by clearly defining structure.
60+ b. Prevents misinterpretation of hierarchical content.
61+ c. Improves maintainability in collaborative environments.
62+
63+ 2. Common Indentation Guidelines
64+ a. Use consistent spacing (e.g., 2 or 4 spaces per level).
65+ b. Avoid mixing spaces and tabs to ensure uniform formatting.
66+ c. Align nested elements to maintain structural clarity.
67+ 1b. Maintain relative indentation depth across all nested elements.
68+ 2b. Ensure indentation reflects logical hierarchy.
5469" # ;
5570
5671// Verify that `auto_indent` correctly normalizes indentation
5772assert_eq! (
58- auto_indent (text ),
59- expected ,
73+ auto_indent (excessively_indented_text ),
74+ normalized_indentation ,
6075 " The auto_indent function should normalize leading whitespace."
6176);
62-
63- // Ensure the original text is not identical to the expected output
64- // This confirms that `auto_indent` actually modifies the string.
65- assert_ne! (
66- text ,
67- expected ,
68- " The original text should *not* be identical to the expected output before normalization."
69- );
70- ```
71-
72- ### Example Output
73-
74- #### With ` auto-indent `
75-
76- ``` text
77- String Auto Indent
78-
79- Level 1
80- Level 2
81- Level 3
82- ```
83-
84- #### Without ` auto-intent `
85-
86- ``` text
87- String Auto Indent
88-
89- Level 1
90- Level 2
91- Level 3
92- ```
93-
94- ## Example 2: Mixed Indentation
95-
96- This example demonstrates how ` auto_indent ` normalizes inconsistent indentation while preserving the relative structure of nested content.
97-
98- ``` rust
99- use string_auto_indent :: {auto_indent, LineEnding };
100-
101- let text = r # "
102- String Auto Indent
103-
104- 1. Point 1
105- a. Sub point a
106- b. Sub point b
107- 2. Point 2
108- a. Sub point a
109- b. Sub piont b
110- 1b. Sub piont 1b
111- " # ;
112-
113- // Expected output after applying auto indentation
114- let expected = r # "
115- String Auto Indent
116-
117- 1. Point 1
118- a. Sub point a
119- b. Sub point b
120- 2. Point 2
121- a. Sub point a
122- b. Sub piont b
123- 1b. Sub piont 1b
124- " # ;
125-
126- // Verify that `auto_indent` correctly normalizes indentation
127- assert_eq! (
128- auto_indent (text ),
129- expected ,
130- " The auto_indent function should normalize leading whitespace."
131- );
132-
133- // Ensure the original text is not identical to the expected output
134- // This confirms that `auto_indent` actually modifies the string.
135- assert_ne! (
136- text ,
137- expected ,
138- " The original text should *not* be identical to the expected output before normalization."
139- );
14077```
14178
14279## How It Works
0 commit comments