diff --git a/tests/norm-rule/expected/test-norm-rules.adoc b/tests/norm-rule/expected/test-norm-rules.adoc index 437b65f..5d1fca4 100644 --- a/tests/norm-rule/expected/test-norm-rules.adoc +++ b/tests/norm-rule/expected/test-norm-rules.adoc @@ -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 diff --git a/tests/norm-rule/expected/test-norm-rules.html b/tests/norm-rule/expected/test-norm-rules.html index bb3703c..c196db4 100644 --- a/tests/norm-rule/expected/test-norm-rules.html +++ b/tests/norm-rule/expected/test-norm-rules.html @@ -243,6 +243,16 @@

my-chapter_name

DEF custom text GHI norm:hyperlink4 + + hyperlink5 + GHI norm:superscript and norm:subscript JKL + norm:hyperlink5 + + + hyperlink6 + JKL hello and goodbye MNO + norm:hyperlink6 + table1 ===
WITH anchor
WITHOUT anchor
=== diff --git a/tests/norm-rule/expected/test-norm-rules.json b/tests/norm-rule/expected/test-norm-rules.json index c9992bc..8f51d59 100644 --- a/tests/norm-rule/expected/test-norm-rules.json +++ b/tests/norm-rule/expected/test-norm-rules.json @@ -300,6 +300,32 @@ } ] }, + { + "name": "hyperlink5", + "def_filename": "tests/norm-rule/test.yaml", + "chapter_name": "my-chapter_name", + "tags": [ + { + "name": "norm:hyperlink5", + "text": "GHI <<norm:superscript>> and <<norm:subscript>> 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 <<norm:superscript,hello>> and <<norm:subscript,goodbye>> MNO", + "tag_filename": "/build/test-norm-tags.json", + "stds_doc_url": "test.html" + } + ] + }, { "name": "table1", "def_filename": "tests/norm-rule/test.yaml", diff --git a/tests/norm-rule/expected/test-norm-rules.xlsx b/tests/norm-rule/expected/test-norm-rules.xlsx index 475bcbd..eb78fac 100644 Binary files a/tests/norm-rule/expected/test-norm-rules.xlsx and b/tests/norm-rule/expected/test-norm-rules.xlsx differ diff --git a/tests/norm-rule/expected/test-norm-tags.json b/tests/norm-rule/expected/test-norm-tags.json index d7b7d2a..da22278 100644 --- a/tests/norm-rule/expected/test-norm-tags.json +++ b/tests/norm-rule/expected/test-norm-tags.json @@ -22,6 +22,8 @@ "norm:hyperlink2": "DEF <<norm:superscript,custom text>> GHI", "norm:hyperlink3": "ABC <<non-norm-anchor>> DEF", "norm:hyperlink4": "DEF <<non-norm-anchor,custom text>> GHI", + "norm:hyperlink5": "GHI <<norm:superscript>> and <<norm:subscript>> JKL", + "norm:hyperlink6": "JKL <<norm:superscript,hello>> and <<norm:subscript,goodbye>> 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===", @@ -96,7 +98,9 @@ "norm:hyperlink1", "norm:hyperlink2", "norm:hyperlink3", - "norm:hyperlink4" + "norm:hyperlink4", + "norm:hyperlink5", + "norm:hyperlink6" ] }, { diff --git a/tests/norm-rule/test.adoc b/tests/norm-rule/test.adoc index 2f451a8..8240eb7 100644 --- a/tests/norm-rule/test.adoc +++ b/tests/norm-rule/test.adoc @@ -95,6 +95,10 @@ Before hyperlink [#norm:hyperlink3]#ABC <> DEF# outside. Before hyperlink [#norm:hyperlink4]#DEF <> GHI# outside. +Before hyperlink [#norm:hyperlink5]#GHI <> and <> JKL# outside. + +Before hyperlink [#norm:hyperlink6]#JKL <> and <> MNO# outside. + [[non-norm-anchor]] Here's some text that isn't normative but the normatively tagged text has an existing link into it. diff --git a/tests/norm-rule/test.yaml b/tests/norm-rule/test.yaml index 8cc71d0..2db65df 100644 --- a/tests/norm-rule/test.yaml +++ b/tests/norm-rule/test.yaml @@ -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 diff --git a/tools/create_normative_rules.rb b/tools/create_normative_rules.rb index 83bb13d..2e02014 100644 --- a/tools/create_normative_rules.rb +++ b/tools/create_normative_rules.rb @@ -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 <> 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(",") + + if split_texts.length == 0 + fail("Hyperlink '$1' is empty") + elsif split_texts.length == 1 + 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") + end end tag_link = tag2html_link(tag_ref, tag_ref, html_fname)