Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/norm-rule/expected/test-norm-rules.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ It's got 2 lines.
.1+| hyperlink4
| DEF <<non-norm-anchor,custom text>> GHI a| link:test.html#norm:hyperlink4[norm:hyperlink4]

.1+| hyperlink5
| GHI <<norm:superscript>> and <<norm:subscript>> JKL a| link:test.html#norm:hyperlink5[norm:hyperlink5]

.1+| hyperlink6
| JKL <<norm:superscript,hello>> and <<norm:subscript,goodbye>> MNO a| link:test.html#norm:hyperlink6[norm:hyperlink6]

.1+| table1
| ===
WITH anchor
Expand Down
10 changes: 10 additions & 0 deletions tests/norm-rule/expected/test-norm-rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ <h3>my-chapter_name</h3>
<td>DEF <a href="test.html#non-norm-anchor">custom text</a> GHI</td>
<td><a href="test.html#norm:hyperlink4">norm:hyperlink4</a></td>
</tr>
<tr>
<td rowspan=1 id="hyperlink5">hyperlink5</td>
<td>GHI <a href="test.html#norm:superscript">norm:superscript</a> and <a href="test.html#norm:subscript">norm:subscript</a> JKL</td>
<td><a href="test.html#norm:hyperlink5">norm:hyperlink5</a></td>
</tr>
<tr>
<td rowspan=1 id="hyperlink6">hyperlink6</td>
<td>JKL <a href="test.html#norm:superscript">hello</a> and <a href="test.html#norm:subscript">goodbye</a> MNO</td>
<td><a href="test.html#norm:hyperlink6">norm:hyperlink6</a></td>
</tr>
<tr>
<td rowspan=1 id="table1">table1</td>
<td>===<br>WITH anchor<br>WITHOUT anchor<br>===</td>
Expand Down
26 changes: 26 additions & 0 deletions tests/norm-rule/expected/test-norm-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,32 @@
}
]
},
{
"name": "hyperlink5",
"def_filename": "tests/norm-rule/test.yaml",
"chapter_name": "my-chapter_name",
"tags": [
{
"name": "norm:hyperlink5",
"text": "GHI &lt;&lt;norm:superscript&gt;&gt; and &lt;&lt;norm:subscript&gt;&gt; JKL",
"tag_filename": "/build/test-norm-tags.json",
"stds_doc_url": "test.html"
}
]
},
{
"name": "hyperlink6",
"def_filename": "tests/norm-rule/test.yaml",
"chapter_name": "my-chapter_name",
"tags": [
{
"name": "norm:hyperlink6",
"text": "JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO",
"tag_filename": "/build/test-norm-tags.json",
"stds_doc_url": "test.html"
}
]
},
{
"name": "table1",
"def_filename": "tests/norm-rule/test.yaml",
Expand Down
Binary file modified tests/norm-rule/expected/test-norm-rules.xlsx
Binary file not shown.
6 changes: 5 additions & 1 deletion tests/norm-rule/expected/test-norm-tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"norm:hyperlink2": "DEF &lt;&lt;norm:superscript,custom text&gt;&gt; GHI",
"norm:hyperlink3": "ABC &lt;&lt;non-norm-anchor&gt;&gt; DEF",
"norm:hyperlink4": "DEF &lt;&lt;non-norm-anchor,custom text&gt;&gt; GHI",
"norm:hyperlink5": "GHI &lt;&lt;norm:superscript&gt;&gt; and &lt;&lt;norm:subscript&gt;&gt; JKL",
"norm:hyperlink6": "JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO",
"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===",
"norm:table:anchors-in-cells:entire-table-tagged:cell": "WITH anchor",
"norm:table:anchors-in-cells:entire-table": "===\nWITH anchor\nWITHOUT anchor\n===",
Expand Down Expand Up @@ -96,7 +98,9 @@
"norm:hyperlink1",
"norm:hyperlink2",
"norm:hyperlink3",
"norm:hyperlink4"
"norm:hyperlink4",
"norm:hyperlink5",
"norm:hyperlink6"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions tests/norm-rule/test.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Before hyperlink [#norm:hyperlink3]#ABC <<non-norm-anchor>> DEF# outside.

Before hyperlink [#norm:hyperlink4]#DEF <<non-norm-anchor,custom text>> GHI# outside.

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

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

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

Expand Down
4 changes: 4 additions & 0 deletions tests/norm-rule/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ normative_rule_definitions:
tag: "norm:hyperlink3"
- name: hyperlink4
tag: "norm:hyperlink4"
- name: hyperlink5
tag: "norm:hyperlink5"
- name: hyperlink6
tag: "norm:hyperlink6"

# Table
- name: table1
Expand Down
22 changes: 16 additions & 6 deletions tools/create_normative_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,22 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
#
# Can assume that the link is to the same HTML standards document as the
# tag text that it is found in because these kind of links only link within their document.
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}([^,]+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
tag2html_link($1, $1, html_fname)
end

tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}([^,]+),(.+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
tag2html_link($1, $2, html_fname)
#
# Note that I'm using the non-greedy regular expression (? after +) otherwise the regular expression
# will return multiple <<link>> in the same text as one.
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}(.+?)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
# Look to see if custom text has been provided.
split_texts = $1.split(",")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider trimming whitespace from split_texts elements before passing them to tag2html_link. Currently, <<link , custom text>> (with space before comma) would result in "link " being used as the tag reference, which could cause issues. Adding .map(&:strip) after the split would handle this: split_texts = $1.split(",").map(&:strip)

Suggested change
split_texts = $1.split(",")
split_texts = $1.split(",").map(&:strip)

Copilot uses AI. Check for mistakes.

if split_texts.length == 0
fail("Hyperlink '$1' is empty")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message uses single quotes, which prevents Ruby from interpolating $1. The message will literally display "$1" instead of the actual hyperlink content. Change to double quotes: "Hyperlink \"#{$1}\" is empty" or use "Hyperlink '#{$1}' is empty" for proper interpolation.

Suggested change
fail("Hyperlink '$1' is empty")
fail("Hyperlink '#{$1}' is empty")

Copilot uses AI. Check for mistakes.
elsif split_texts.length == 1
Comment on lines +1073 to +1075
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition split_texts.length == 0 is impossible to reach. When splitting a non-empty string (captured by .+?), the result will always have at least one element. Consider removing this dead code or replacing it with a more meaningful check.

Suggested change
if split_texts.length == 0
fail("Hyperlink '$1' is empty")
elsif split_texts.length == 1
if split_texts.length == 1

Copilot uses AI. Check for mistakes.
tag2html_link(split_texts[0], split_texts[0], html_fname)
elsif split_texts.length == 2
tag2html_link(split_texts[0], split_texts[1], html_fname)
else
fail("Hyperlink '$1' contains too many commas")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message uses single quotes, which prevents Ruby from interpolating $1. The message will literally display "$1" instead of the actual hyperlink content. Change to double quotes: "Hyperlink \"#{$1}\" contains too many commas" or use "Hyperlink '#{$1}' contains too many commas" for proper interpolation.

Suggested change
fail("Hyperlink '$1' contains too many commas")
fail("Hyperlink '#{$1}' contains too many commas")

Copilot uses AI. Check for mistakes.
end
end

tag_link = tag2html_link(tag_ref, tag_ref, html_fname)
Expand Down
Loading