Skip to content

Commit 19d71fa

Browse files
author
james-ball-qualcomm
authored
Merge pull request #137 from riscv/136-adoc-link-replacement-to-html-bug
Fix for having two or more links in normative text
2 parents 7a01efe + 91ab024 commit 19d71fa

File tree

8 files changed

+71
-7
lines changed

8 files changed

+71
-7
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ It's got 2 lines.
8181
.1+| hyperlink4
8282
| DEF <<non-norm-anchor,custom text>> GHI a| link:test.html#norm:hyperlink4[norm:hyperlink4]
8383

84+
.1+| hyperlink5
85+
| GHI <<norm:superscript>> and <<norm:subscript>> JKL a| link:test.html#norm:hyperlink5[norm:hyperlink5]
86+
87+
.1+| hyperlink6
88+
| JKL <<norm:superscript,hello>> and <<norm:subscript,goodbye>> MNO a| link:test.html#norm:hyperlink6[norm:hyperlink6]
89+
8490
.1+| table1
8591
| ===
8692
WITH anchor

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ <h3>my-chapter_name</h3>
243243
<td>DEF <a href="test.html#non-norm-anchor">custom text</a> GHI</td>
244244
<td><a href="test.html#norm:hyperlink4">norm:hyperlink4</a></td>
245245
</tr>
246+
<tr>
247+
<td rowspan=1 id="hyperlink5">hyperlink5</td>
248+
<td>GHI <a href="test.html#norm:superscript">norm:superscript</a> and <a href="test.html#norm:subscript">norm:subscript</a> JKL</td>
249+
<td><a href="test.html#norm:hyperlink5">norm:hyperlink5</a></td>
250+
</tr>
251+
<tr>
252+
<td rowspan=1 id="hyperlink6">hyperlink6</td>
253+
<td>JKL <a href="test.html#norm:superscript">hello</a> and <a href="test.html#norm:subscript">goodbye</a> MNO</td>
254+
<td><a href="test.html#norm:hyperlink6">norm:hyperlink6</a></td>
255+
</tr>
246256
<tr>
247257
<td rowspan=1 id="table1">table1</td>
248258
<td>===<br>WITH anchor<br>WITHOUT anchor<br>===</td>

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,32 @@
300300
}
301301
]
302302
},
303+
{
304+
"name": "hyperlink5",
305+
"def_filename": "tests/norm-rule/test.yaml",
306+
"chapter_name": "my-chapter_name",
307+
"tags": [
308+
{
309+
"name": "norm:hyperlink5",
310+
"text": "GHI &lt;&lt;norm:superscript&gt;&gt; and &lt;&lt;norm:subscript&gt;&gt; JKL",
311+
"tag_filename": "/build/test-norm-tags.json",
312+
"stds_doc_url": "test.html"
313+
}
314+
]
315+
},
316+
{
317+
"name": "hyperlink6",
318+
"def_filename": "tests/norm-rule/test.yaml",
319+
"chapter_name": "my-chapter_name",
320+
"tags": [
321+
{
322+
"name": "norm:hyperlink6",
323+
"text": "JKL &lt;&lt;norm:superscript,hello&gt;&gt; and &lt;&lt;norm:subscript,goodbye&gt;&gt; MNO",
324+
"tag_filename": "/build/test-norm-tags.json",
325+
"stds_doc_url": "test.html"
326+
}
327+
]
328+
},
303329
{
304330
"name": "table1",
305331
"def_filename": "tests/norm-rule/test.yaml",
80 Bytes
Binary file not shown.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"norm:hyperlink2": "DEF &lt;&lt;norm:superscript,custom text&gt;&gt; GHI",
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",
25+
"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",
2527
"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===",
2628
"norm:table:anchors-in-cells:entire-table-tagged:cell": "WITH anchor",
2729
"norm:table:anchors-in-cells:entire-table": "===\nWITH anchor\nWITHOUT anchor\n===",
@@ -96,7 +98,9 @@
9698
"norm:hyperlink1",
9799
"norm:hyperlink2",
98100
"norm:hyperlink3",
99-
"norm:hyperlink4"
101+
"norm:hyperlink4",
102+
"norm:hyperlink5",
103+
"norm:hyperlink6"
100104
]
101105
},
102106
{

tests/norm-rule/test.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ Before hyperlink [#norm:hyperlink3]#ABC <<non-norm-anchor>> DEF# outside.
9595

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

98+
Before hyperlink [#norm:hyperlink5]#GHI <<norm:superscript>> and <<norm:subscript>> JKL# outside.
99+
100+
Before hyperlink [#norm:hyperlink6]#JKL <<norm:superscript,hello>> and <<norm:subscript,goodbye>> MNO# outside.
101+
98102
[[non-norm-anchor]]
99103
Here's some text that isn't normative but the normatively tagged text has an existing link into it.
100104

tests/norm-rule/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ normative_rule_definitions:
6464
tag: "norm:hyperlink3"
6565
- name: hyperlink4
6666
tag: "norm:hyperlink4"
67+
- name: hyperlink5
68+
tag: "norm:hyperlink5"
69+
- name: hyperlink6
70+
tag: "norm:hyperlink6"
6771

6872
# Table
6973
- name: table1

tools/create_normative_rules.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,22 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10631063
#
10641064
# Can assume that the link is to the same HTML standards document as the
10651065
# tag text that it is found in because these kind of links only link within their document.
1066-
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}([^,]+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
1067-
tag2html_link($1, $1, html_fname)
1068-
end
1069-
1070-
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}([^,]+),(.+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
1071-
tag2html_link($1, $2, html_fname)
1066+
#
1067+
# Note that I'm using the non-greedy regular expression (? after +) otherwise the regular expression
1068+
# will return multiple <<link>> in the same text as one.
1069+
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}(.+?)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
1070+
# Look to see if custom text has been provided.
1071+
split_texts = $1.split(",")
1072+
1073+
if split_texts.length == 0
1074+
fail("Hyperlink '$1' is empty")
1075+
elsif split_texts.length == 1
1076+
tag2html_link(split_texts[0], split_texts[0], html_fname)
1077+
elsif split_texts.length == 2
1078+
tag2html_link(split_texts[0], split_texts[1], html_fname)
1079+
else
1080+
fail("Hyperlink '$1' contains too many commas")
1081+
end
10721082
end
10731083

10741084
tag_link = tag2html_link(tag_ref, tag_ref, html_fname)

0 commit comments

Comments
 (0)