Skip PatternMatcher filter in code and pre blocks

pull/6015/head
Oliver Günther 7 years ago
parent 503d640b8c
commit 6207eb9ce8
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 6
      lib/open_project/text_formatting/filters/pattern_matcher_filter.rb
  2. 11
      lib/open_project/text_formatting/matchers/resource_links_matcher.rb
  3. 11
      spec/lib/open_project/text_formatting/markdown/markdown_spec.rb

@ -32,6 +32,9 @@ module OpenProject::TextFormatting
module Filters
class PatternMatcherFilter < HTML::Pipeline::Filter
# Skip text nodes that are within preformatted blocks
PREFORMATTED_BLOCKS = %w(pre code).to_set
def self.matchers
[
OpenProject::TextFormatting::Matchers::ResourceLinksMatcher,
@ -39,8 +42,11 @@ module OpenProject::TextFormatting
]
end
def call
doc.search('.//text()').each do |node|
next if has_ancestor?(node, PREFORMATTED_BLOCKS)
self.class.matchers.each do |matcher|
matcher.call(node, doc: doc, context: context)
end

@ -89,7 +89,16 @@ module OpenProject::TextFormatting
(:) # or colon separator
([^"\s<>][^\s<>]*?|"[^"]+?") # and its identifier
)
(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)
(?=
(?=
[[:punct:]]\W
)
|,
|\s
|\]
|<
|$
)
}x
end

@ -119,9 +119,9 @@ describe OpenProject::TextFormatting do
end
context 'Single link with dot' do
subject { format_text("r#{changeset1.revision}.") }
subject { format_text("r#{changeset1.revision}. A word") }
it { is_expected.to be_html_eql("<p>#{changeset_link}.</p>") }
it { is_expected.to be_html_eql("<p>#{changeset_link}. A word</p>") }
end
context 'Two links comma separated' do
@ -618,10 +618,11 @@ describe OpenProject::TextFormatting do
##{issue.id}
<pre>
```
[[CookBook documentation]]
##{issue.id}
```
</pre>
RAW
}
@ -630,11 +631,11 @@ describe OpenProject::TextFormatting do
<<-EXPECTED
<p><a class="wiki-page" href="/projects/#{project.identifier}/wiki/cookbook-documentation">CookBook documentation</a></p>
<p><a class="issue work_package status-3 priority-1 created-by-me" href="/work_packages/#{issue.id}" title="#{issue.subject} (#{issue.status})">##{issue.id}</a></p>
<pre>
<pre><code>
[[CookBook documentation]]
##{issue.id}
</pre>
</code></pre>
EXPECTED
}

Loading…
Cancel
Save