Skip to content

Commit cee3b7f

Browse files
authored
Update indentation logic to support non-whitespace characters (#61)
1 parent 5b30b85 commit cee3b7f

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

internal/marker/marker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func processIndentOption(marker *Marker, match *RawMarker) error {
139139
case "extra":
140140
marker.Indentation = &Indentation{Mode: ExtraIndentation}
141141
case "align":
142-
markerIndentation := len(match.PrecedingIndentation) - len(strings.TrimLeft(match.PrecedingIndentation, " ")) // Naïve count
142+
markerIndentation := len(match.PrecedingIndentation)
143143
marker.Indentation = &Indentation{
144144
Mode: AlignIndentation,
145145
MarkerIndentation: markerIndentation,

internal/marker/marker_regex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var (
1010
ImporterMarkerMarkdown = `<!-- == (imptr|import|importer|i): (?P<importer_name>\S+) \/ (?P<importer_marker>begin|end)(?P<importer_option>.*) == -->`
1111

1212
// ImporterMarkerYAML is the annotation used for importer to find match.
13-
ImporterMarkerYAML = `(?P<importer_marker_indentation>\s*)# == (imptr|import|importer|i): (?P<importer_name>\S+) \/ (?P<importer_marker>begin|end)(?P<importer_option>.*) ==`
13+
ImporterMarkerYAML = `(?P<importer_marker_indentation>.*)# == (imptr|import|importer|i): (?P<importer_name>\S+) \/ (?P<importer_marker>begin|end)(?P<importer_option>.*) ==`
1414

1515
// OptionFilePathIndicator is the pattern used for parsing Importer file options.
1616
OptionFilePathIndicator = `from: (?P<importer_target_path>\S+)\s*\#(?P<importer_target_detail>[0-9a-zA-Z,-_\~]+)\s?`

internal/marker/marker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestNewMarker(t *testing.T) {
159159
IsEndFound: true,
160160
LineToInsertAt: 3,
161161
Options: "from: ./abc.yaml#[from-exporter-marker] indent: align",
162-
PrecedingIndentation: " ",
162+
PrecedingIndentation: " - ", // As if yaml list input is used for indentation
163163
},
164164
want: &marker.Marker{
165165
Name: "simple-marker",

testdata/yaml/align-with-exporter-before.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ data:
77
indentation:
88
for:
99
demo:
10-
# == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
11-
anything: here
12-
would: be
13-
purged: by Importer
14-
# == importer: abc-tree / end ==
10+
- # == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
11+
anything: here
12+
would: be
13+
purged: by Importer
14+
# == importer: abc-tree / end ==
1515

1616
some-data:
1717
description: |

testdata/yaml/align-with-exporter-purged.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ data:
77
indentation:
88
for:
99
demo:
10-
# == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
11-
# == importer: abc-tree / end ==
10+
- # == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
11+
# == importer: abc-tree / end ==
1212

1313
some-data:
1414
description: |

testdata/yaml/align-with-exporter-updated.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ data:
77
indentation:
88
for:
99
demo:
10-
# == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
11-
a:
12-
b:
13-
c:
14-
d:
15-
e:
16-
f:
17-
g:
18-
h:
19-
i:
20-
j:
21-
k: {}
22-
# == importer: abc-tree / end ==
10+
- # == importer: abc-tree / begin from: ./snippet-with-exporter.yaml#[long-tree] indent: align ==
11+
a:
12+
b:
13+
c:
14+
d:
15+
e:
16+
f:
17+
g:
18+
h:
19+
i:
20+
j:
21+
k: {}
22+
# == importer: abc-tree / end ==
2323

2424
some-data:
2525
description: |

0 commit comments

Comments
 (0)