Skip to content

Commit 31cb975

Browse files
Reverted tags backend to just joining table cells with "|" (was for a while prefixing each cell with "|"), changed norm rules Ruby to use split() function instead of complicated regular expression that wasn't robust. Added test case for single char table cells (would have failed before).
Signed-off-by: James Ball <[email protected]>
1 parent 22a17b0 commit 31cb975

File tree

9 files changed

+79
-49
lines changed

9 files changed

+79
-49
lines changed

converters/tags.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def node_text_content(node)
144144
cell.content.join("\n")
145145
end
146146
end
147-
# Prefix cells with "|"
148-
end.map { |s| '|' + s }.join
147+
# Separate cells with "|"
148+
end.join("|")
149149
# Separate rows by newlines.
150150
end.join("\n")
151151
# Separate table sections by ===.

tests/norm-rule/expected/test-norm-rules.adoc

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ It's got 2 lines.
8989

9090
.1+| table1
9191
| ===
92-
|WITH anchor
93-
|WITHOUT anchor
92+
WITH anchor
93+
WITHOUT anchor
9494
=== a| link:test.html#norm:table:anchors-in-cells:entire-table[norm:table:anchors-in-cells:entire-table]
9595

9696
.1+| table2
97-
| |Header 1|Header 2
97+
| Header 1|Header 2
9898
===
99-
|Cell in column 1, row 1|Cell in column 2, row 1
100-
|Cell in column 1, row 2|Cell in column 2, row 2
99+
Cell in column 1, row 1|Cell in column 2, row 1
100+
Cell in column 1, row 2|Cell in column 2, row 2
101101
=== a| link:test.html#norm:table:no-anchors-in-cells:entire-table[norm:table:no-anchors-in-cells:entire-table]
102102

103103
.1+| table3
@@ -107,21 +107,28 @@ It's got 2 lines.
107107
| ABC DEF a| link:test.html#norm:table:anchors-in-cells:entire-table-not-tagged:cell[norm:table:anchors-in-cells:entire-table-not-tagged:cell]
108108

109109
.1+| table5
110-
| |Name|Color
110+
| Name|Color
111111
===
112-
|Roses|Red
113-
|Violets|Blue
114-
|Name1|Color1
115-
|Name2|Color2
116-
|Name3|Color3
117-
|Name4|Color4
118-
|Name5|Color5
119-
|Name6|Color6
120-
|Name7|Color7
121-
|Name8|Color8
122-
|Name9|Color9
112+
Roses|Red
113+
Violets|Blue
114+
Name1|Color1
115+
Name2|Color2
116+
Name3|Color3
117+
Name4|Color4
118+
Name5|Color5
119+
Name6|Color6
120+
Name7|Color7
121+
Name8|Color8
122+
Name9|Color9
123123
... a| link:test.html#norm:table:many-rows[norm:table:many-rows]
124124

125+
.1+| table6
126+
| X1|X2
127+
===
128+
A|B
129+
C|D
130+
=== a| link:test.html#norm:table:single-char-cells[norm:table:single-char-cells]
131+
125132
.1+| unordered1
126133
| Item A
127134
Item B

tests/norm-rule/expected/test-norm-rules.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ <h3>my-chapter_name</h3>
278278
<td><table><thead><tr><th>Name</th><th>Color</th></tr></thead><tbody><tr><td>Roses</td><td>Red</td></tr><tr><td>Violets</td><td>Blue</td></tr><tr><td>Name1</td><td>Color1</td></tr><tr><td>Name2</td><td>Color2</td></tr><tr><td>Name3</td><td>Color3</td></tr><tr><td>Name4</td><td>Color4</td></tr><tr><td>Name5</td><td>Color5</td></tr><tr><td>Name6</td><td>Color6</td></tr><tr><td>Name7</td><td>Color7</td></tr><tr><td>Name8</td><td>Color8</td></tr><tr><td>Name9</td><td>Color9</td></tr><tr><td>Name10</td><td>Color10</td></tr><tr><td>...</td><td>...</td></tr></tbody></table></td>
279279
<td><a href="test.html#norm:table:many-rows">norm:table:many-rows</a></td>
280280
</tr>
281+
<tr>
282+
<td rowspan=1 id="table6">table6</td>
283+
<td><table><thead><tr><th>X1</th><th>X2</th></tr></thead><tbody><tr><td>A</td><td>B</td></tr><tr><td>C</td><td>D</td></tr></tbody></table></td>
284+
<td><a href="test.html#norm:table:single-char-cells">norm:table:single-char-cells</a></td>
285+
</tr>
281286
<tr>
282287
<td rowspan=1 id="unordered1">unordered1</td>
283288
<td>Item A<br>Item B<br>Item C</td>

tests/norm-rule/expected/test-norm-rules.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
"tags": [
334334
{
335335
"name": "norm:table:anchors-in-cells:entire-table",
336-
"text": "===\n|WITH anchor\n|WITHOUT anchor\n===",
336+
"text": "===\nWITH anchor\nWITHOUT anchor\n===",
337337
"tag_filename": "/build/test-norm-tags.json",
338338
"stds_doc_url": "test.html"
339339
}
@@ -346,7 +346,7 @@
346346
"tags": [
347347
{
348348
"name": "norm:table:no-anchors-in-cells:entire-table",
349-
"text": "|Header 1|Header 2\n===\n|Cell in column 1, row 1|Cell in column 2, row 1\n|Cell in column 1, row 2|Cell in column 2, row 2\n===",
349+
"text": "Header 1|Header 2\n===\nCell in column 1, row 1|Cell in column 2, row 1\nCell in column 1, row 2|Cell in column 2, row 2\n===",
350350
"tag_filename": "/build/test-norm-tags.json",
351351
"stds_doc_url": "test.html"
352352
}
@@ -385,7 +385,20 @@
385385
"tags": [
386386
{
387387
"name": "norm:table:many-rows",
388-
"text": "|Name|Color\n===\n|Roses|Red\n|Violets|Blue\n|Name1|Color1\n|Name2|Color2\n|Name3|Color3\n|Name4|Color4\n|Name5|Color5\n|Name6|Color6\n|Name7|Color7\n|Name8|Color8\n|Name9|Color9\n|Name10|Color10\n|Name11|Color11\n|Name12|Color12\n|Name13|Color13\n|Name14|Color14\n===",
388+
"text": "Name|Color\n===\nRoses|Red\nViolets|Blue\nName1|Color1\nName2|Color2\nName3|Color3\nName4|Color4\nName5|Color5\nName6|Color6\nName7|Color7\nName8|Color8\nName9|Color9\nName10|Color10\nName11|Color11\nName12|Color12\nName13|Color13\nName14|Color14\n===",
389+
"tag_filename": "/build/test-norm-tags.json",
390+
"stds_doc_url": "test.html"
391+
}
392+
]
393+
},
394+
{
395+
"name": "table6",
396+
"def_filename": "tests/norm-rule/test.yaml",
397+
"chapter_name": "my-chapter_name",
398+
"tags": [
399+
{
400+
"name": "norm:table:single-char-cells",
401+
"text": "X1|X2\n===\nA|B\nC|D\n===",
389402
"tag_filename": "/build/test-norm-tags.json",
390403
"stds_doc_url": "test.html"
391404
}
39 Bytes
Binary file not shown.

tests/norm-rule/expected/test-norm-tags.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
"norm:hyperlink4": "DEF &lt;&lt;non-norm-anchor,custom text&gt;&gt; GHI",
2525
"norm:hyperlink5": "GHI &lt;&lt;norm:superscript&gt;&gt; and &lt;&lt;norm:subscript&gt;&gt; JKL",
2626
"norm:hyperlink6": "JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO",
27-
"norm:table:no-anchors-in-cells:entire-table": "|Header 1|Header 2\n===\n|Cell in column 1, row 1|Cell in column 2, row 1\n|Cell in column 1, row 2|Cell in column 2, row 2\n===",
27+
"norm:table:no-anchors-in-cells:entire-table": "Header 1|Header 2\n===\nCell in column 1, row 1|Cell in column 2, row 1\nCell in column 1, row 2|Cell in column 2, row 2\n===",
2828
"norm:table:anchors-in-cells:entire-table-tagged:cell": "WITH anchor",
29-
"norm:table:anchors-in-cells:entire-table": "===\n|WITH anchor\n|WITHOUT anchor\n===",
29+
"norm:table:anchors-in-cells:entire-table": "===\nWITH anchor\nWITHOUT anchor\n===",
3030
"norm:table:anchors-in-cells:entire-table-not-tagged:cell": "ABC DEF",
31-
"norm:table:many-rows": "|Name|Color\n===\n|Roses|Red\n|Violets|Blue\n|Name1|Color1\n|Name2|Color2\n|Name3|Color3\n|Name4|Color4\n|Name5|Color5\n|Name6|Color6\n|Name7|Color7\n|Name8|Color8\n|Name9|Color9\n|Name10|Color10\n|Name11|Color11\n|Name12|Color12\n|Name13|Color13\n|Name14|Color14\n===",
31+
"norm:table:many-rows": "Name|Color\n===\nRoses|Red\nViolets|Blue\nName1|Color1\nName2|Color2\nName3|Color3\nName4|Color4\nName5|Color5\nName6|Color6\nName7|Color7\nName8|Color8\nName9|Color9\nName10|Color10\nName11|Color11\nName12|Color12\nName13|Color13\nName14|Color14\n===",
32+
"norm:table:single-char-cells": "X1|X2\n===\nA|B\nC|D\n===",
3233
"norm:unordered-list:no-anchors-in-items:entire-list": "Item A\nItem B\nItem C",
3334
"norm:unordered-list:anchors-in-items:item1": "Item 1",
3435
"norm:unordered-list:anchors-in-items:item2": "Item 2",
@@ -112,7 +113,8 @@
112113
"norm:table:anchors-in-cells:entire-table-tagged:cell",
113114
"norm:table:anchors-in-cells:entire-table",
114115
"norm:table:anchors-in-cells:entire-table-not-tagged:cell",
115-
"norm:table:many-rows"
116+
"norm:table:many-rows",
117+
"norm:table:single-char-cells"
116118
]
117119
}
118120
],

tests/norm-rule/test.adoc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Here's some text that isn't normative but the normatively tagged text has an exi
104104

105105
=== Chapter 2 - Table Tagging
106106

107-
// FAILS - Want tagged text to be "ENTIRE TABLE"
107+
// PASSES
108108
[[norm:table:no-anchors-in-cells:entire-table]]
109109
[cols="1,1"]
110110
|===
@@ -114,11 +114,11 @@ Here's some text that isn't normative but the normatively tagged text has an exi
114114
|Cell in column 1, row 2 |Cell in column 2, row 2
115115
|===
116116

117-
// FAILS - Want tagged text to be "ENTIRE TABLE"
117+
// PASSES
118118
[[norm:table:anchors-in-cells:entire-table]]
119119
|===
120120

121-
// FAILS - Want tagged text to be "WITH anchor"
121+
// PASSES
122122
| [#norm:table:anchors-in-cells:entire-table-tagged:cell]#WITH anchor#
123123
| WITHOUT anchor
124124
|===
@@ -127,11 +127,11 @@ Here's some text that isn't normative but the normatively tagged text has an exi
127127

128128
// PASSES - Handles adoc formatted cell
129129
a| Cell is adoc
130-
// FAILS - Want tagged text to be "ABC DEF"
130+
// PASSES
131131
| [#norm:table:anchors-in-cells:entire-table-not-tagged:cell]#ABC DEF#
132132
|===
133133

134-
// PASSES - Want tagged text to be "ENTIRE TABLE"
134+
// PASSES
135135
[[norm:table:many-rows]]
136136
[cols="1,1"]
137137
|===
@@ -155,6 +155,14 @@ a| Cell is adoc
155155
|Name14|Color14
156156
|===
157157

158+
[[norm:table:single-char-cells]]
159+
|===
160+
|X1|X2
161+
162+
| A|B
163+
|C| D
164+
|===
165+
158166
== Chapter 3 - Tagging Unordered Lists
159167

160168
// PASSES - Tag includes all list items

tests/norm-rule/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ normative_rule_definitions:
8080
tag: "norm:table:anchors-in-cells:entire-table-not-tagged:cell"
8181
- name: table5
8282
tag: "norm:table:many-rows"
83+
- name: table6
84+
tag: "norm:table:single-char-cells"
8385

8486
# Unordered lists
8587
- name: unordered1

tools/create_normative_rules.rb

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,26 +1208,19 @@ def convert_tags_tables_to_html(text)
12081208
end
12091209

12101210
# Return array of table columns from one row/header of a table.
1211-
def extract_tags_table_cells(text)
1212-
raise ArgumentError, "Expected String for text but was passed a #{text}.class" unless text.is_a?(String)
1211+
# Returns empty array if row is nil or the empty string.
1212+
def extract_tags_table_cells(row)
1213+
raise ArgumentError, "Expected String for row but was passed a #{row}.class" unless row.is_a?(String)
12131214

1214-
# This pattern matches strings that:
1215-
# - Start with a non-pipe, non-whitespace character
1216-
# - Then contain zero or more non-pipe characters (can include internal spaces)
1217-
# - End with a non-pipe, non-whitespace character
1218-
#
1219-
# All leading/trailing whitespace is removed.
1220-
#
1215+
return [] if row.nil? || row.empty?
1216+
1217+
# Split row fields with pipe symbol.
12211218
# Examples:
1222-
# "| H1 | H2".scan(/[^|\s][^|]*[^|\s]/)
1223-
# => ["H1", "H2"]
1224-
#
1225-
# "| ABC | DEF GHI |".scan(/[^|\s][^|]*[^|\s]/)
1226-
# => ["ABC", "DEF GHI"] # Note: internal space preserved
1227-
#
1228-
# "| Name | Value |".scan(/[^|\s][^|]*[^|\s]/)
1229-
# => ["Name", "Value"] # Leading/trailing spaces removed
1230-
text.scan(/[^|\s][^|]*[^|\s]/)
1219+
# "H1 | H2" => ["H1", "H2"]
1220+
# "|" => ["", ""]
1221+
# "|A|B" => ["", "A", "B"]
1222+
# "||C" => ["", "", "C"]
1223+
row.split('|', -1).map(&:strip)
12311224
end
12321225

12331226
# Cleanup the tag text to be suitably displayed.

0 commit comments

Comments
 (0)