Skip to content

Commit 2433c7e

Browse files
committed
fix up table rule
1 parent 4b870b7 commit 2433c7e

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

styles/circleci-docs/TableTitles.yml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@ script: |
99
matches := []
1010
1111
lines := text.split(scope, "\n")
12-
in_table := false
1312
1413
for i, line in lines {
1514
trimmed := text.trim_space(line)
1615
1716
// Check for table delimiter
1817
if trimmed == "|===" {
19-
// Toggle table state
20-
if !in_table {
21-
// This is an opening delimiter
18+
// Count how many |=== delimiters appear before this one
19+
preceding_count := 0
20+
for k := 0; k < i; k++ {
21+
if text.trim_space(lines[k]) == "|===" {
22+
preceding_count = preceding_count + 1
23+
}
24+
}
25+
26+
// If preceding count is even, this is an opening delimiter
27+
is_opening := preceding_count % 2 == 0
28+
29+
if is_opening {
30+
// This is an opening delimiter - check for title
2231
has_title := false
32+
lookback_limit := 10 // Only look back max 10 lines
2333
2434
// Look back for a title, skipping empty lines, attributes, and block delimiters
25-
for j := i - 1; j >= 0; j-- {
35+
for j := i - 1; j >= 0 && (i - j) <= lookback_limit; j-- {
2636
prev_trimmed := text.trim_space(lines[j])
2737
2838
// Skip empty lines
@@ -35,9 +45,8 @@ script: |
3545
continue
3646
}
3747
38-
// Skip block delimiters (lines with only dashes or equals signs)
39-
is_delimiter := text.re_match("^-+$", prev_trimmed) || text.re_match("^=+$", prev_trimmed)
40-
if is_delimiter {
48+
// Skip block delimiters (only dashes or equals)
49+
if text.re_match("^-+$", prev_trimmed) || text.re_match("^=+$", prev_trimmed) {
4150
continue
4251
}
4352
@@ -46,25 +55,26 @@ script: |
4655
continue
4756
}
4857
49-
// Check if this line is a title (starts with a dot)
50-
if text.has_prefix(prev_trimmed, ".") {
58+
// Check if this line is a title (starts with a dot but not ..)
59+
if text.has_prefix(prev_trimmed, ".") && !text.has_prefix(prev_trimmed, "..") {
5160
has_title = true
5261
break
5362
}
5463
5564
// Found a non-skippable line that's not a title
65+
// This means there's content between the table and any potential title
5666
break
5767
}
5868
5969
if !has_title {
60-
start := text.index(scope, line)
61-
matches = append(matches, {begin: start, end: start + len(line)})
70+
// Calculate position by counting characters up to this line
71+
pos := 0
72+
for k := 0; k < i; k++ {
73+
pos = pos + len(lines[k]) + 1 // +1 for newline
74+
}
75+
matches = append(matches, {begin: pos, end: pos + len(line)})
6276
}
63-
64-
in_table = true
65-
} else {
66-
// This is a closing delimiter, just toggle state
67-
in_table = false
6877
}
78+
// Closing delimiters don't need any action
6979
}
7080
}

0 commit comments

Comments
 (0)