|
| 1 | +# Report unsupported block titles. |
| 2 | +--- |
| 3 | +extends: script |
| 4 | +message: "Block titles can only be assigned to examples, figures, and tables in DITA." |
| 5 | +level: warning |
| 6 | +scope: raw |
| 7 | +script: | |
| 8 | + text := import("text") |
| 9 | + matches := [] |
| 10 | +
|
| 11 | + r_add_resources := text.re_compile("^\\.{1,2}Additional resources[ \\t]*$") |
| 12 | + r_attribute_list := text.re_compile("^\\[(?:|[\\w.#%{,\"'].*)\\][ \\t]*$") |
| 13 | + r_attribute := text.re_compile("^:!?\\S[^:]*:") |
| 14 | + r_block_title := text.re_compile("^\\.{1,2}[^ \\t.].*$") |
| 15 | + r_comment_block := text.re_compile("^/{4,}\\s*$") |
| 16 | + r_comment_line := text.re_compile("^(//|//[^/].*)$") |
| 17 | + r_conditional := text.re_compile("^(?:ifn?def|ifeval|endif)::\\S*\\[.*\\][ \\t]*$") |
| 18 | + r_content_type := text.re_compile("^:_(?:mod-docs-content|content|module)-type:[ \\t](?i:procedure)") |
| 19 | + r_empty_line := text.re_compile("^[ \\t]*$") |
| 20 | + r_example_block := text.re_compile("^\\[example\\][ \\t]*$") |
| 21 | + r_example_delim := text.re_compile("^={4,}[ \\t]*$") |
| 22 | + r_image := text.re_compile("^image::(?:\\S|\\S.*\\S)\\[.*\\][ \\t]*$") |
| 23 | + r_supported_title := text.re_compile("^\\.{1,2}(?:Prerequisites?|Procedure|Verification|Results?|Troubleshooting|Troubleshooting steps?|Next steps?)[ \\t]*$") |
| 24 | + r_table_cell := text.re_compile("^\\.[^ \\t|]+\\|") |
| 25 | + r_table := text.re_compile("^\\|={3,}[ \\t]*$") |
| 26 | +
|
| 27 | + document := text.split(text.trim_suffix(scope, "\n"), "\n") |
| 28 | +
|
| 29 | + in_comment_block := false |
| 30 | + is_procedure := false |
| 31 | + expect_block := false |
| 32 | + start := 0 |
| 33 | + end := 0 |
| 34 | +
|
| 35 | + for line in document { |
| 36 | + start += end |
| 37 | + end = len(line) + 1 |
| 38 | +
|
| 39 | + if r_comment_block.match(line) { |
| 40 | + delimiter := text.trim_space(line) |
| 41 | + if ! in_comment_block { |
| 42 | + in_comment_block = delimiter |
| 43 | + } else if in_comment_block == delimiter { |
| 44 | + in_comment_block = false |
| 45 | + } |
| 46 | + continue |
| 47 | + } |
| 48 | + if in_comment_block { continue } |
| 49 | + if r_comment_line.match(line) { continue } |
| 50 | +
|
| 51 | + if r_content_type.match(line) { |
| 52 | + is_procedure = true |
| 53 | + continue |
| 54 | + } |
| 55 | +
|
| 56 | + if r_attribute_list.match(line) && ! r_example_block.match(line) { continue } |
| 57 | + if r_attribute.match(line) { continue } |
| 58 | + if r_conditional.match(line) { continue } |
| 59 | + if r_empty_line.match(line) { continue } |
| 60 | +
|
| 61 | + if r_block_title.match(line) { |
| 62 | + if is_procedure && r_supported_title.match(line) { continue } |
| 63 | + if r_add_resources.match(line) { continue } |
| 64 | + if r_table_cell.match(line) { continue } |
| 65 | +
|
| 66 | + expect_block = {begin: start, end: start + end -1} |
| 67 | + continue |
| 68 | + } |
| 69 | +
|
| 70 | + if r_table.match(line) || r_image.match(line) || |
| 71 | + r_example_block.match(line) || r_example_delim.match(line) { |
| 72 | + expect_block = false |
| 73 | + continue |
| 74 | + } |
| 75 | +
|
| 76 | + if expect_block { |
| 77 | + matches = append(matches, expect_block) |
| 78 | + } |
| 79 | +
|
| 80 | + expect_block = false |
| 81 | + } |
0 commit comments