diff --git a/lib/banzai/filter/spaced_link_filter.rb b/lib/banzai/filter/spaced_link_filter.rb index d8b4f447583e51616079b6dbf88f2c473bd227f5..64583d0520fa213b16f561fc15dbf695d366aac4 100644 --- a/lib/banzai/filter/spaced_link_filter.rb +++ b/lib/banzai/filter/spaced_link_filter.rb @@ -40,7 +40,7 @@ class SpacedLinkFilter < HTML::Pipeline::Filter ) # Text matching LINK_OR_IMAGE_PATTERN inside these elements will not be linked - IGNORE_PARENTS = %w[a code kbd pre script style].to_set + IGNORE_PARENTS = %w[a code kbd pre script style span[@data-math-style]].to_set # The XPath query to use for finding text nodes to parse. TEXT_QUERY = %(descendant-or-self::text()[ diff --git a/spec/lib/banzai/filter/spaced_link_filter_spec.rb b/spec/lib/banzai/filter/spaced_link_filter_spec.rb index 4f9bf00b29a1b38896fd5f5527043433d0b30e98..29f27190eca6e598958f6706cb2a41bee37cc575 100644 --- a/spec/lib/banzai/filter/spaced_link_filter_spec.rb +++ b/spec/lib/banzai/filter/spaced_link_filter_spec.rb @@ -93,9 +93,10 @@ expect(found_images[0]['alt']).to eq 'example' end - described_class::IGNORE_PARENTS.each do |elem| - it "ignores valid links contained inside '#{elem}' element" do - exp = act = "<#{elem}>See #{link}</#{elem}>" + described_class::IGNORE_PARENTS.each do |xpath| + it "ignores valid links contained inside '#{xpath}' element" do + match = xpath.match(/(?<element>\w+)(?:\[@(?<attribute>.*)\])?/) + exp = act = "<#{match[:element]}#{" #{match[:attribute]}" if match[:attribute]}>See #{link}</#{match[:element]}>" expect(filter(act).to_html).to eq exp end diff --git a/spec/lib/banzai/pipeline/full_pipeline_spec.rb b/spec/lib/banzai/pipeline/full_pipeline_spec.rb index 7def8c9b74ec1cba0c88312179a3ac168bde15bc..73225d8fd261ced89ad97e2aa33fb01019dd6bdd 100644 --- a/spec/lib/banzai/pipeline/full_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/full_pipeline_spec.rb @@ -315,4 +315,17 @@ is_expected.to include '<span class="kc">true</span>' end end + + describe 'math does not get rendered as link' do + [ + "$[(a+b)c](d+e)$", + '$$[(a+b)c](d+e)$$', + '$`[(a+b)c](d+e)`$' + ].each do |input| + it "when using '#{input}' as input" do + result = described_class.call(input, project: nil)[:output] + expect(result.css('a').first).to be_nil + end + end + end end