File tree 5 files changed +100
-0
lines changed
fixtures/OpenShiftAsciiDoc/AssemblyContainsRequiredMetadata
5 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ ; Vale configuration file to test the `AssemblyContainsRequiredMetadata` rule
2
+ StylesPath = ../../../styles
3
+ MinAlertLevel = suggestion
4
+ [*.adoc]
5
+ OpenShiftAsciiDoc.AssemblyContainsRequiredMetadata = YES
Original file line number Diff line number Diff line change
1
+ //vale-fixture
2
+ :context: <unique-context-for-assembly>
3
+ = title
4
+
Original file line number Diff line number Diff line change
1
+ //vale-fixture
2
+ :_content-type: ASSEMBLY
3
+ [id="<unique-heading-for-assembly >"]
4
+ = Assembly title
5
+ include::_attributes/input-attributes-file
6
+ :context: some-context
7
+
8
+ toc::[]
Original file line number Diff line number Diff line change
1
+ ---
2
+ extends : script
3
+ message : " Assembly is missing required metadata. Ensure you include metadata for attributes, TOC and context."
4
+ level : error
5
+ link : https://github.com/openshift/openshift-docs/blob/main/contributing_to_docs/doc_guidelines.adoc#assembly-file-metadata
6
+ scope : raw
7
+ script : |
8
+ text := import("text")
9
+ matches := []
10
+
11
+ //trim extra whitespace
12
+ scope = text.trim_space(scope)
13
+ //add a newline, it might be missing
14
+ scope += "\n"
15
+
16
+ attribute_regex := "include::_attributes/"
17
+ toc_regex := "toc::\\[\\]"
18
+ context_regex := ":context:"
19
+ matchAttribute := false
20
+ matchToc := false
21
+ matchContext := false
22
+
23
+ //Check if context declaration is on any line
24
+ for line in text.split(scope, "\n") {
25
+ if text.re_match(attribute_regex, line){
26
+ matchAttribute = true
27
+ } else if text.re_match(toc_regex, line){
28
+ matchToc = true
29
+ } else if text.re_match(context_regex, line){
30
+ matchContext = true
31
+ }
32
+ }
33
+
34
+ //Highlight first line if context declaration not found in file
35
+ if !matchAttribute || !matchToc || !matchContext {
36
+ matches = append(matches, {begin: 1, end: 10})
37
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ Tengo Language
3
+ Checks that lines are not hard-wrapped.
4
+ $ tengo HardWrappedLines.tengo <asciidoc_file_to_validate>
5
+ */
6
+
7
+ fmt := import("fmt")
8
+ os := import("os")
9
+ text := import("text")
10
+
11
+ input := os.args()
12
+ scope := os.read_file(input[2])
13
+ matches := []
14
+
15
+ //trim extra whitespace
16
+ scope = text.trim_space(scope)
17
+ //add a newline, it might be missing
18
+ scope += "\n"
19
+
20
+ attribute_regex := "include::_attributes/"
21
+ toc_regex := "toc::\\[\\]"
22
+ context_regex := ":context:"
23
+ matchAttribute := false
24
+ matchToc := false
25
+ matchContext := false
26
+
27
+ //Check if context declaration is on any line
28
+ for line in text.split(scope, "\n") {
29
+ if text.re_match(attribute_regex, line){
30
+ matchAttribute = true
31
+ fmt.println("Found attribute declaration.")
32
+ } else if text.re_match(toc_regex, line){
33
+ matchToc = true
34
+ fmt.println("Found toc declaration")
35
+ } else if text.re_match(context_regex, line){
36
+ matchContext = true
37
+ fmt.println("Found context declaration")
38
+ }
39
+ }
40
+
41
+ //Highlight first line if context declaration not found in file
42
+ if !matchAttribute || !matchToc || !matchContext {
43
+ matches = append(matches, {begin: 1, end: 10})
44
+ fmt.println("Did not find correct metadata")
45
+ fmt.println(matches)
46
+ }
You can’t perform that action at this time.
0 commit comments