diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2023-04-25 00:34:30 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2023-04-25 01:44:32 -0600 |
| commit | c58ad5ab87a281c42c59dd097f24378dfca0e0d1 (patch) | |
| tree | 952cc2f1320039ca00dd69cda7e95b5953da7eaa | |
| parent | 32cd2d1c77c978704c2384d735b4e3d5cb53033b (diff) | |
slightly simplify implicit link processing by separating implicit and explicit match
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/rx.rb | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 12 | ||||
| -rw-r--r-- | test/links_test.rb | 5 |
4 files changed, 10 insertions, 12 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 299a66e6..fd0667de 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -22,6 +22,7 @@ Improvements:: * Return empty string instead of nil if raw or verbatim block has no lines * Don't uppercase monospace span in section title in manpage output (#4402) + * Simplify processing of implicit link (i.e., autolink) by separating implicit and explicit match Compliance:: diff --git a/lib/asciidoctor/rx.rb b/lib/asciidoctor/rx.rb index 88bfac45..ba284fab 100644 --- a/lib/asciidoctor/rx.rb +++ b/lib/asciidoctor/rx.rb @@ -516,9 +516,9 @@ module Asciidoctor # <https://github.com> # link:https://github.com[] # "https://github.com[]" + # (https://github.com) <= parenthesis not included in autolink # - # FIXME revisit! the main issue is we need different rules for implicit vs explicit - InlineLinkRx = %r((^|link:|#{CG_BLANK}|<|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://[^\s\[\]<]*([^\s.,\[\]<]))(?:\[(|#{CC_ALL}*?[^\\])\])?)m + InlineLinkRx = %r((^|link:|#{CG_BLANK}|<|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m # Match a link or e-mail inline macro. # diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index 8cd57e63..6582a250 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -526,7 +526,7 @@ module Substitutors if found_colon && (text.include? '://') # inline urls, target[text] (optionally prefixed with link: and optionally surrounded by <>) text = text.gsub InlineLinkRx do - if (target = $2).start_with? RS + if (target = $2 + ($3 || $5)).start_with? RS # honor the escape next ($&.slice 0, (rs_idx = $1.length)) + ($&.slice rs_idx + 1, $&.length) end @@ -543,15 +543,7 @@ module Substitutors when 'link:', ?", ?' next $& end - case $3 - when ')', '?', '!' - target = target.chop - if (suffix = $3) == ')' && (target.end_with? '.', '?', '!') - suffix = target[-1] + suffix - target = target.chop - end - # NOTE handle case when modified target is a URI scheme (e.g., http://) - next $& if target.end_with? '://' + case $6 when ';' if (prefix.start_with? '<') && (target.end_with? '>') # move surrounding <> out of URL diff --git a/test/links_test.rb b/test/links_test.rb index 9b2f687b..c98feed3 100644 --- a/test/links_test.rb +++ b/test/links_test.rb @@ -209,6 +209,11 @@ context 'Links' do assert_include '"<a href="https://asciidoctor.org" class="bare">https://asciidoctor.org</a>"', output end + test 'should convert qualified url as macro with trailing period' do + result = convert_string_to_embedded 'Information about the https://symbols.example.org/.[.] character.' + assert_xpath '//a[@href="https://symbols.example.org/."][text()="."]', result, 1 + end + test 'should convert qualified url as macro enclosed in single quotes' do output = convert_string_to_embedded('\'https://asciidoctor.org[]\'') assert_include '\'<a href="https://asciidoctor.org" class="bare">https://asciidoctor.org</a>\'', output |
