diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2014-08-10 18:18:15 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2014-08-10 18:19:25 -0600 |
| commit | 87aa6d70af0c033d9ab2d709f167e66c0caa0c8e (patch) | |
| tree | 0e1e2f7776fa2db3dd6b27f36b837c43463da265 | |
| parent | 2640a9938bd76dd5f577910117776f847962b41b (diff) | |
don't parse link attributes if text doesn't contain = sign
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | README.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/substitutors.rb | 6 | ||||
| -rw-r--r-- | test/links_test.rb | 6 |
4 files changed, 10 insertions, 4 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f8b912e0..b1ae485a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -61,6 +61,7 @@ Improvements:: * {star} use glyphs for checkboxes when not using font icons (#878) * {star} prefer source-language attribute over language attribute for defining default source language (#888) * {star} pass document as first argument to process method on Preprocessor + * don't parse link attributes when linkattrs is set unless text contains equal sign * allow Treeprocessor#process method to replace tree (#1035) * add AbstractNode#find_by method to locate nodes in tree (#862) * add API for parsing title and subtitle (#1000) diff --git a/README.adoc b/README.adoc index 652fd5f2..c3424f09 100644 --- a/README.adoc +++ b/README.adoc @@ -376,6 +376,7 @@ Improvements:: * use glyphs for checkboxes when not using font icons (#878) * prefer source-language attribute over language attribute for defining default source language (#888) * pass document as first argument to process method on Preprocessor + * don't parse link attributes when linkattrs is set unless text contains equal sign * allow Treeprocessor#process method to replace tree (#1035) * add AbstractNode#find_by method to locate nodes in tree (#862) * add API for parsing title and subtitle (#1000) diff --git a/lib/asciidoctor/substitutors.rb b/lib/asciidoctor/substitutors.rb index 2b31a0eb..08548bf1 100644 --- a/lib/asciidoctor/substitutors.rb +++ b/lib/asciidoctor/substitutors.rb @@ -799,12 +799,12 @@ module Substitutors if m[3].nil_or_empty? text = '' else - text = if use_link_attrs && (m[3].start_with?('"') || m[3].include?(',')) + if use_link_attrs && (m[3].start_with?('"') || (m[3].include?(',') && m[3].include?('='))) attrs = parse_attributes(sub_attributes(m[3].gsub('\]', ']')), []) link_opts[:id] = (attrs.delete 'id') if attrs.has_key? 'id' - attrs[1] || '' + text = attrs[1] || '' else - sub_attributes(m[3].gsub('\]', ']')) + text = sub_attributes(m[3].gsub('\]', ']')) end # TODO enable in Asciidoctor 1.5.1 diff --git a/test/links_test.rb b/test/links_test.rb index 29ea6b36..4a73abc4 100644 --- a/test/links_test.rb +++ b/test/links_test.rb @@ -120,7 +120,11 @@ context 'Links' do end test 'link with quoted text should not be separated into attributes when linkattrs is set' do - assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing"]', render_embedded_string('http://search.example.com["Google, Yahoo, Bing"]', :attributes => {'linkattrs' => ''}), 1 + assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing = Search Engines"]', render_embedded_string('http://search.example.com["Google, Yahoo, Bing = Search Engines"]', :attributes => {'linkattrs' => ''}), 1 + end + + test 'link with comma in text but no equal sign should not be separated into attributes when linkattrs is set' do + assert_xpath '//a[@href="http://search.example.com"][text()="Google, Yahoo, Bing"]', render_embedded_string('http://search.example.com[Google, Yahoo, Bing]', :attributes => {'linkattrs' => ''}), 1 end test 'role and window attributes on link are processed when linkattrs is set' do |
