Skip to content

Commit 7a01efe

Browse files
author
james-ball-qualcomm
authored
Merge pull request #135 from riscv/134-convert-existing-adoc-links-to-html-links
Now handle any <<foo>> or <<foo,link text> anchor in norm rules
2 parents 824bd66 + e0c446b commit 7a01efe

File tree

8 files changed

+76
-24
lines changed

8 files changed

+76
-24
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ It's got 2 lines.
7575
.1+| hyperlink2
7676
| DEF &lt;&lt;norm:superscript,custom text&gt;&gt; GHI a| link:test.html#norm:hyperlink2[norm:hyperlink2]
7777

78+
.1+| hyperlink3
79+
| ABC &lt;&lt;non-norm-anchor&gt;&gt; DEF a| link:test.html#norm:hyperlink3[norm:hyperlink3]
80+
81+
.1+| hyperlink4
82+
| DEF &lt;&lt;non-norm-anchor,custom text&gt;&gt; GHI a| link:test.html#norm:hyperlink4[norm:hyperlink4]
83+
7884
.1+| table1
7985
| ===
8086
WITH anchor

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ <h3>my-chapter_name</h3>
233233
<td>DEF <a href="test.html#norm:superscript">custom text</a> GHI</td>
234234
<td><a href="test.html#norm:hyperlink2">norm:hyperlink2</a></td>
235235
</tr>
236+
<tr>
237+
<td rowspan=1 id="hyperlink3">hyperlink3</td>
238+
<td>ABC <a href="test.html#non-norm-anchor">non-norm-anchor</a> DEF</td>
239+
<td><a href="test.html#norm:hyperlink3">norm:hyperlink3</a></td>
240+
</tr>
241+
<tr>
242+
<td rowspan=1 id="hyperlink4">hyperlink4</td>
243+
<td>DEF <a href="test.html#non-norm-anchor">custom text</a> GHI</td>
244+
<td><a href="test.html#norm:hyperlink4">norm:hyperlink4</a></td>
245+
</tr>
236246
<tr>
237247
<td rowspan=1 id="table1">table1</td>
238248
<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
@@ -274,6 +274,32 @@
274274
}
275275
]
276276
},
277+
{
278+
"name": "hyperlink3",
279+
"def_filename": "tests/norm-rule/test.yaml",
280+
"chapter_name": "my-chapter_name",
281+
"tags": [
282+
{
283+
"name": "norm:hyperlink3",
284+
"text": "ABC &lt;&lt;non-norm-anchor&gt;&gt; DEF",
285+
"tag_filename": "/build/test-norm-tags.json",
286+
"stds_doc_url": "test.html"
287+
}
288+
]
289+
},
290+
{
291+
"name": "hyperlink4",
292+
"def_filename": "tests/norm-rule/test.yaml",
293+
"chapter_name": "my-chapter_name",
294+
"tags": [
295+
{
296+
"name": "norm:hyperlink4",
297+
"text": "DEF &lt;&lt;non-norm-anchor,custom text&gt;&gt; GHI",
298+
"tag_filename": "/build/test-norm-tags.json",
299+
"stds_doc_url": "test.html"
300+
}
301+
]
302+
},
277303
{
278304
"name": "table1",
279305
"def_filename": "tests/norm-rule/test.yaml",
71 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
@@ -20,6 +20,8 @@
2020
"norm:macro_call": "200 {ge} 100",
2121
"norm:hyperlink1": "ABC &lt;&lt;norm:superscript&gt;&gt; DEF",
2222
"norm:hyperlink2": "DEF &lt;&lt;norm:superscript,custom text&gt;&gt; GHI",
23+
"norm:hyperlink3": "ABC &lt;&lt;non-norm-anchor&gt;&gt; DEF",
24+
"norm:hyperlink4": "DEF &lt;&lt;non-norm-anchor,custom text&gt;&gt; GHI",
2325
"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===",
2426
"norm:table:anchors-in-cells:entire-table-tagged:cell": "WITH anchor",
2527
"norm:table:anchors-in-cells:entire-table": "===\nWITH anchor\nWITHOUT anchor\n===",
@@ -92,7 +94,9 @@
9294
"norm:unicode_char",
9395
"norm:macro_call",
9496
"norm:hyperlink1",
95-
"norm:hyperlink2"
97+
"norm:hyperlink2",
98+
"norm:hyperlink3",
99+
"norm:hyperlink4"
96100
]
97101
},
98102
{

tests/norm-rule/test.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ Before hyperlink [#norm:hyperlink1]#ABC <<norm:superscript>> DEF# outside.
9191

9292
Before hyperlink [#norm:hyperlink2]#DEF <<norm:superscript,custom text>> GHI# outside.
9393

94+
Before hyperlink [#norm:hyperlink3]#ABC <<non-norm-anchor>> DEF# outside.
95+
96+
Before hyperlink [#norm:hyperlink4]#DEF <<non-norm-anchor,custom text>> GHI# outside.
97+
98+
[[non-norm-anchor]]
99+
Here's some text that isn't normative but the normatively tagged text has an existing link into it.
100+
94101
=== Chapter 2 - Table Tagging
95102

96103
// FAILS - Want tagged text to be "ENTIRE TABLE"

tests/norm-rule/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ normative_rule_definitions:
6060
tag: "norm:hyperlink1"
6161
- name: hyperlink2
6262
tag: "norm:hyperlink2"
63+
- name: hyperlink3
64+
tag: "norm:hyperlink3"
65+
- name: hyperlink4
66+
tag: "norm:hyperlink4"
6367

6468
# Table
6569
- name: table1

tools/create_normative_rules.rb

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10381038
instances_str = "[" + nr.instances.join(', ') + "]"
10391039
rule_name = "instances"
10401040
end
1041-
instances_str = (nr.instances.size > 1) ? ("[" + nr.instances.join(', ') + "]") : nr.instances[0]
10421041
f.puts(%Q{ <tr>}) unless row_started
10431042
f.puts(%Q{ <td>#{instances_str}</td>})
10441043
f.puts(%Q{ <td>Rule's "#{rule_name}" property</td>})
@@ -1050,24 +1049,29 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10501049
tag = tags.get_tag(tag_ref)
10511050
fatal("Normative rule #{nr.name} defined in file #{nr.def_filename} references non-existent tag #{tag_ref}") if tag.nil?
10521051

1053-
tag_text = tag.text
1052+
html_fname = tag_fname2url[tag.tag_filename]
1053+
fatal("No fname tag to HTML mapping (-tag2url cmd line arg) for tag fname #{tag.tag_filename} for tag name #{tag.name}") if html_fname.nil?
1054+
1055+
tag_text = html_convert_newlines(limit_table_rows(Adoc2HTML::convert(tag.text)))
10541056

1055-
tag_text = html_convert_newlines(limit_table_rows(Adoc2HTML::convert(tag_text)))
10561057

10571058
# Convert adoc links to normative text in tag text to html links.
10581059
#
10591060
# Supported formats:
1060-
# <<#{NORM_PREFIX}foo>>
1061-
# <<#{NORM_PREFIX}foo,custom text>>
1062-
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}#{NORM_PREFIX}([^,]+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
1063-
tag2html_link("#{NORM_PREFIX}#{$1}", nr, tags, tag_fname2url)
1061+
# <<link>>
1062+
# <<link,custom text>>
1063+
#
1064+
# Can assume that the link is to the same HTML standards document as the
1065+
# 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)
10641068
end
10651069

1066-
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}#{NORM_PREFIX}([^,]+),(.+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
1067-
tag2html_link("#{NORM_PREFIX}#{$1}", nr, tags, tag_fname2url, $2)
1070+
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}([^,]+),(.+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
1071+
tag2html_link($1, $2, html_fname)
10681072
end
10691073

1070-
tag_link = tag2html_link(tag_ref, nr, tags, tag_fname2url)
1074+
tag_link = tag2html_link(tag_ref, tag_ref, html_fname)
10711075

10721076
f.puts(%Q{ <tr>}) unless row_started
10731077
f.puts(%Q{ <td>#{tag_text}</td>})
@@ -1082,21 +1086,12 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10821086
f.puts(%Q{ </section>})
10831087
end
10841088

1085-
def tag2html_link(tag_ref, nr, tags, tag_fname2url, custom_text = nil)
1089+
def tag2html_link(tag_ref, link_text, html_fname)
10861090
fatal("Expected String for tag_ref but was passed a #{tag_ref}.class") unless tag_ref.is_a?(String)
1087-
fatal("Need NormativeRule for nr but passed a #{nr.class}") unless nr.is_a?(NormativeRuleDef)
1088-
fatal("Need NormativeTags for tags but passed a #{tags.class}") unless tags.is_a?(NormativeTags)
1089-
fatal("Need Hash for tag_fname2url but passed a #{tag_fname2url.class}") unless tag_fname2url.is_a?(Hash)
1090-
1091-
tag = tags.get_tag(tag_ref)
1092-
fatal("Normative rule #{nr.name} defined in file #{nr.def_filename} references non-existent tag #{tag_ref}") if tag.nil?
1093-
1094-
html_fname = tag_fname2url[tag.tag_filename]
1095-
fatal("No fname tag to HTML mapping (-tag2url cmd line arg) for tag fname #{tag.tag_filename} for tag name #{tag.name}") if html_fname.nil?
1096-
1097-
text = custom_text.nil? ? tag_ref : custom_text
1091+
fatal("Expected String for link_text but was passed a #{link_text}.class") unless link_text.is_a?(String)
1092+
fatal("Expected String for html_fname but was passed a #{html_fname}.class") unless html_fname.is_a?(String)
10981093

1099-
return %Q{<a href="#{html_fname}##{tag_ref}">#{text}</a>}
1094+
return %Q{<a href="#{html_fname}##{tag_ref}">#{link_text}</a>}
11001095
end
11011096

11021097
def html_script(f)

0 commit comments

Comments
 (0)