Skip to content

Commit 116d24e

Browse files
Fixed a bunch of small corner case bugs and added them to my test.
Signed-off-by: James Ball <jameball@qti.qualcomm.com>
1 parent 31cb975 commit 116d24e

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ It's got 2 lines.
8585
| GHI &lt;&lt;norm:superscript&gt;&gt; and &lt;&lt;norm:subscript&gt;&gt; JKL a| link:test.html#norm:hyperlink5[norm:hyperlink5]
8686

8787
.1+| hyperlink6
88-
| JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO a| link:test.html#norm:hyperlink6[norm:hyperlink6]
88+
| JKL &lt;&lt;norm:superscript ,hello&gt;&gt; and &lt;&lt;norm:subscript, goodbye&gt;&gt; MNO a| link:test.html#norm:hyperlink6[norm:hyperlink6]
8989

9090
.1+| table1
9191
| ===

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
"tags": [
321321
{
322322
"name": "norm:hyperlink6",
323-
"text": "JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO",
323+
"text": "JKL &lt;&lt;norm:superscript ,hello&gt;&gt; and &lt;&lt;norm:subscript, goodbye&gt;&gt; MNO",
324324
"tag_filename": "/build/test-norm-tags.json",
325325
"stds_doc_url": "test.html"
326326
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"norm:hyperlink3": "ABC &lt;&lt;non-norm-anchor&gt;&gt; DEF",
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",
26-
"norm:hyperlink6": "JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO",
26+
"norm:hyperlink6": "JKL &lt;&lt;norm:superscript ,hello&gt;&gt; and &lt;&lt;norm:subscript, goodbye&gt;&gt; MNO",
2727
"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",
2929
"norm:table:anchors-in-cells:entire-table": "===\nWITH anchor\nWITHOUT anchor\n===",

tests/norm-rule/test.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Before hyperlink [#norm:hyperlink4]#DEF <<non-norm-anchor,custom text>> GHI# out
9797

9898
Before hyperlink [#norm:hyperlink5]#GHI <<norm:superscript>> and <<norm:subscript>> JKL# outside.
9999

100-
Before hyperlink [#norm:hyperlink6]#JKL <<norm:superscript,hello>> and <<norm:subscript,goodbye>> MNO# outside.
100+
Before hyperlink [#norm:hyperlink6]#JKL <<norm:superscript ,hello>> and <<norm:subscript, goodbye>> MNO# outside.
101101

102102
[[non-norm-anchor]]
103103
Here's some text that isn't normative but the normatively tagged text has an existing link into it.

tools/create_normative_rules.rb

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
PN = "create_normative_rules.rb"
88

99
# Global constants
10-
LT_UNICODE_DECIMAL = 60 # "<" Unicode devimal value
10+
LT_UNICODE_DECIMAL = 60 # "<" Unicode decimal value
1111
GT_UNICODE_DECIMAL = 62 # ">"" Unicode decimal value
1212

1313
LT_UNICODE_STR = "&##{LT_UNICODE_DECIMAL};" # "<" Unicode string
@@ -589,12 +589,12 @@ def convert_extra_amp(text)
589589
"&" + $1 + ";"
590590
end
591591

592-
# Sometimes the tags backend converts "&#8800;" to "&amp;#8800;". Convert it to "&#8800".
592+
# Sometimes the tags backend converts "&#8800;" to "&amp;#8800;". Convert it to "&#8800;".
593593
text = text.gsub(/&amp;#([0-9]+);/) do
594594
"&#" + $1 + ";"
595595
end
596596

597-
# And now handle the the hexadecimal variant.
597+
# And now handle the hexadecimal variant.
598598
text.gsub(/&amp;#x([0-9a-fA-F]+);/) do
599599
"&#x" + $1 + ";"
600600
end
@@ -1069,16 +1069,16 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10691069
# will return multiple <<link>> in the same text as one.
10701070
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}(.+?)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
10711071
# Look to see if custom text has been provided.
1072-
split_texts = $1.split(",")
1072+
split_texts = $1.split(",").map(&:strip)
10731073

10741074
if split_texts.length == 0
1075-
fail("Hyperlink '$1' is empty")
1075+
fail("Hyperlink '#{$1}' is empty")
10761076
elsif split_texts.length == 1
10771077
tag2html_link(split_texts[0], split_texts[0], html_fname)
10781078
elsif split_texts.length == 2
10791079
tag2html_link(split_texts[0], split_texts[1], html_fname)
10801080
else
1081-
fail("Hyperlink '$1' contains too many commas")
1081+
fail("Hyperlink '#{$1}' contains too many commas")
10821082
end
10831083
end
10841084

@@ -1098,9 +1098,9 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10981098
end
10991099

11001100
def tag2html_link(tag_ref, link_text, html_fname)
1101-
fatal("Expected String for tag_ref but was passed a #{tag_ref}.class") unless tag_ref.is_a?(String)
1102-
fatal("Expected String for link_text but was passed a #{link_text}.class") unless link_text.is_a?(String)
1103-
fatal("Expected String for html_fname but was passed a #{html_fname}.class") unless html_fname.is_a?(String)
1101+
fatal("Expected String for tag_ref but was passed a #{tag_ref.class}") unless tag_ref.is_a?(String)
1102+
fatal("Expected String for link_text but was passed a #{link_text.class}") unless link_text.is_a?(String)
1103+
fatal("Expected String for html_fname but was passed a #{html_fname.class}") unless html_fname.is_a?(String)
11041104

11051105
return %Q{<a href="#{html_fname}##{tag_ref}">#{link_text}</a>}
11061106
end
@@ -1147,25 +1147,23 @@ def html_script(f)
11471147
# Without heading:
11481148
#
11491149
# ===
1150-
# | ABC | DEF
1151-
# |GHI |JKL
1150+
# ABC | DEF
1151+
# GHI |JKL
11521152
# ===
11531153
#
1154-
# Actual string from tags: "===\n| ABC | DEF\n|GHI |JKL\n==="
1154+
# Actual string from tags: "===\nABC | DEF\nGHI |JKL\n==="
11551155
#
11561156
# With heading:
11571157
#
1158-
# | H1 | H2
1158+
# H1 | H2
11591159
# ===
1160-
# | GHI | JKL
1160+
# GHI | JKL
11611161
# ===
11621162
#
1163-
# Actual string from tags: "| H1 | H2\n===\n| GHI | JKL\n==="
1163+
# Actual string from tags: "H1 | H2\n===\nGHI | JKL\n==="
11641164

11651165
def convert_tags_tables_to_html(text)
1166-
raise ArgumentError, "Expected String for text but was passed a #{text}.class" unless text.is_a?(String)
1167-
1168-
ret = text # Default to input
1166+
raise ArgumentError, "Expected String for text but was passed a #{text.class}" unless text.is_a?(String)
11691167

11701168
text.gsub(/(.*?)===\n(.+)\n===/m) do
11711169
# Found a "tags" formatted table
@@ -1203,18 +1201,17 @@ def convert_tags_tables_to_html(text)
12031201
ret << "</tbody>"
12041202
ret << "</table>" # End html table
12051203
end
1206-
1207-
return ret
12081204
end
12091205

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

12151211
return [] if row.nil? || row.empty?
12161212

1217-
# Split row fields with pipe symbol.
1213+
# Split row fields with pipe symbol. The -1 passed to split ensures trailing null fields are not suppressed.
1214+
#
12181215
# Examples:
12191216
# "H1 | H2" => ["H1", "H2"]
12201217
# "|" => ["", ""]
@@ -1225,7 +1222,7 @@ def extract_tags_table_cells(row)
12251222

12261223
# Cleanup the tag text to be suitably displayed.
12271224
def limit_table_rows(text)
1228-
raise ArgumentError, "Expected String for text but was passed a #{text}.class" unless text.is_a?(String)
1225+
raise ArgumentError, "Expected String for text but was passed a #{text.class}" unless text.is_a?(String)
12291226

12301227
# This is the detection pattern for an entire table being tagged from the "tags.rb" AsciiDoctor backend.
12311228
if text.end_with?("\n===")
@@ -1266,7 +1263,7 @@ def count_parameters(defs)
12661263

12671264
# Convert newlines to <br>.
12681265
def convert_newlines_to_html(text)
1269-
raise ArgumentError, "Expected String for text but was passed a #{text}.class" unless text.is_a?(String)
1266+
raise ArgumentError, "Expected String for text but was passed a #{text.class}" unless text.is_a?(String)
12701267

12711268
text.gsub(/\n/, '<br>')
12721269
end

0 commit comments

Comments
 (0)