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 @@ -75,6 +75,12 @@ It's got 2 lines.
.1+| hyperlink2
| DEF <<norm:superscript,custom text>> GHI a| link:test.html#norm:hyperlink2[norm:hyperlink2]

.1+| hyperlink3
| ABC <<non-norm-anchor>> DEF a| link:test.html#norm:hyperlink3[norm:hyperlink3]

.1+| hyperlink4
| DEF <<non-norm-anchor,custom text>> GHI a| link:test.html#norm:hyperlink4[norm:hyperlink4]

.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 @@ -233,6 +233,16 @@ <h3>my-chapter_name</h3>
<td>DEF <a href="test.html#norm:superscript">custom text</a> GHI</td>
<td><a href="test.html#norm:hyperlink2">norm:hyperlink2</a></td>
</tr>
<tr>
<td rowspan=1 id="hyperlink3">hyperlink3</td>
<td>ABC <a href="test.html#non-norm-anchor">non-norm-anchor</a> DEF</td>
<td><a href="test.html#norm:hyperlink3">norm:hyperlink3</a></td>
</tr>
<tr>
<td rowspan=1 id="hyperlink4">hyperlink4</td>
<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="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 @@ -274,6 +274,32 @@
}
]
},
{
"name": "hyperlink3",
"def_filename": "tests/norm-rule/test.yaml",
"chapter_name": "my-chapter_name",
"tags": [
{
"name": "norm:hyperlink3",
"text": "ABC &lt;&lt;non-norm-anchor&gt;&gt; DEF",
"tag_filename": "/build/test-norm-tags.json",
"stds_doc_url": "test.html"
}
]
},
{
"name": "hyperlink4",
"def_filename": "tests/norm-rule/test.yaml",
"chapter_name": "my-chapter_name",
"tags": [
{
"name": "norm:hyperlink4",
"text": "DEF &lt;&lt;non-norm-anchor,custom text&gt;&gt; GHI",
"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 @@ -20,6 +20,8 @@
"norm:macro_call": "200 {ge} 100",
"norm:hyperlink1": "ABC &lt;&lt;norm:superscript&gt;&gt; DEF",
"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: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 @@ -92,7 +94,9 @@
"norm:unicode_char",
"norm:macro_call",
"norm:hyperlink1",
"norm:hyperlink2"
"norm:hyperlink2",
"norm:hyperlink3",
"norm:hyperlink4"
]
},
{
Expand Down
7 changes: 7 additions & 0 deletions tests/norm-rule/test.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ Before hyperlink [#norm:hyperlink1]#ABC <<norm:superscript>> DEF# outside.

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

Before hyperlink [#norm:hyperlink3]#ABC <<non-norm-anchor>> DEF# outside.

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

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

=== Chapter 2 - Table Tagging

// FAILS - Want tagged text to be "ENTIRE TABLE"
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 @@ -60,6 +60,10 @@ normative_rule_definitions:
tag: "norm:hyperlink1"
- name: hyperlink2
tag: "norm:hyperlink2"
- name: hyperlink3
tag: "norm:hyperlink3"
- name: hyperlink4
tag: "norm:hyperlink4"

# Table
- name: table1
Expand Down
41 changes: 18 additions & 23 deletions tools/create_normative_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
instances_str = "[" + nr.instances.join(', ') + "]"
rule_name = "instances"
end
instances_str = (nr.instances.size > 1) ? ("[" + nr.instances.join(', ') + "]") : nr.instances[0]
f.puts(%Q{ <tr>}) unless row_started
f.puts(%Q{ <td>#{instances_str}</td>})
f.puts(%Q{ <td>Rule's "#{rule_name}" property</td>})
Expand All @@ -1050,24 +1049,29 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
tag = tags.get_tag(tag_ref)
fatal("Normative rule #{nr.name} defined in file #{nr.def_filename} references non-existent tag #{tag_ref}") if tag.nil?

tag_text = tag.text
html_fname = tag_fname2url[tag.tag_filename]
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?

tag_text = html_convert_newlines(limit_table_rows(Adoc2HTML::convert(tag.text)))

tag_text = html_convert_newlines(limit_table_rows(Adoc2HTML::convert(tag_text)))

# Convert adoc links to normative text in tag text to html links.
#
# Supported formats:
# <<#{NORM_PREFIX}foo>>
# <<#{NORM_PREFIX}foo,custom text>>
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}#{NORM_PREFIX}([^,]+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
tag2html_link("#{NORM_PREFIX}#{$1}", nr, tags, tag_fname2url)
# <<link>>
# <<link,custom text>>
#
# 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}#{NORM_PREFIX}([^,]+),(.+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
tag2html_link("#{NORM_PREFIX}#{$1}", nr, tags, tag_fname2url, $2)
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}([^,]+),(.+)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
tag2html_link($1, $2, html_fname)
end

tag_link = tag2html_link(tag_ref, nr, tags, tag_fname2url)
tag_link = tag2html_link(tag_ref, tag_ref, html_fname)

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

def tag2html_link(tag_ref, nr, tags, tag_fname2url, custom_text = nil)
def tag2html_link(tag_ref, link_text, html_fname)
fatal("Expected String for tag_ref but was passed a #{tag_ref}.class") unless tag_ref.is_a?(String)
fatal("Need NormativeRule for nr but passed a #{nr.class}") unless nr.is_a?(NormativeRuleDef)
fatal("Need NormativeTags for tags but passed a #{tags.class}") unless tags.is_a?(NormativeTags)
fatal("Need Hash for tag_fname2url but passed a #{tag_fname2url.class}") unless tag_fname2url.is_a?(Hash)

tag = tags.get_tag(tag_ref)
fatal("Normative rule #{nr.name} defined in file #{nr.def_filename} references non-existent tag #{tag_ref}") if tag.nil?

html_fname = tag_fname2url[tag.tag_filename]
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?

text = custom_text.nil? ? tag_ref : custom_text
fatal("Expected String for link_text but was passed a #{link_text}.class") unless link_text.is_a?(String)
fatal("Expected String for html_fname but was passed a #{html_fname}.class") unless html_fname.is_a?(String)

return %Q{<a href="#{html_fname}##{tag_ref}">#{text}</a>}
return %Q{<a href="#{html_fname}##{tag_ref}">#{link_text}</a>}
end

def html_script(f)
Expand Down