@@ -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