forked from migtools/mta-documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidCodeBlocks.yml
More file actions
30 lines (27 loc) · 836 Bytes
/
ValidCodeBlocks.yml
File metadata and controls
30 lines (27 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
---
extends: script
level: error
message: "Unterminated listing block found in file."
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/listing-blocks/
scope: raw
script: |
text := import("text")
matches := []
// clean out multi-line comments
scope = text.re_replace("(?s) *(\n////.*?////\n)", scope, "")
//add a newline, it might be missing
scope += "\n"
listingblock_delim_regex := "^-{4}$"
count := 0
for line in text.split(scope, "\n") {
// trim trailing whitespace
line = text.trim_space(line)
if text.re_match(listingblock_delim_regex, line) {
count += 1
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
} else if count > 1 {
count = 0 // listing block is closed, reset the count
matches = []
}
}