@@ -21,122 +21,59 @@ When working with multi-line strings inside indented code blocks, unwanted leadi
21
21
22
22
` string-auto-indent ` provides an automated way to normalize multi-line strings without modifying the first line's indentation.
23
23
24
- ## Installation
24
+ ## Install
25
25
26
26
``` sh
27
27
cargo add string-auto-indent
28
28
```
29
29
30
30
## Usage
31
31
32
- ## Example 1: Basic Indentation
33
-
34
- This example removes unnecessary leading spaces while preserving the relative indentation of nested lines.
35
-
36
32
``` rust
37
33
use string_auto_indent :: {auto_indent, LineEnding };
38
34
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.
54
69
" # ;
55
70
56
71
// Verify that `auto_indent` correctly normalizes indentation
57
72
assert_eq! (
58
- auto_indent (text ),
59
- expected ,
73
+ auto_indent (excessively_indented_text ),
74
+ normalized_indentation ,
60
75
" The auto_indent function should normalize leading whitespace."
61
76
);
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
- );
140
77
```
141
78
142
79
## How It Works
0 commit comments