Skip to content

Commit

Permalink
Fix paragraphs not being applied in journal posts
Browse files Browse the repository at this point in the history
Fixes inaturalist/inaturalist#3204

Paragraphs were not being applied when in between 2 sections of tables,
lists or preformatted text.
This was because the regex used was greedy, and would  include
everything between the first and last of one of those tags, rather than
stop matching after the first end tag it finds.

Fix was to apply the non-greedy `?` modifier to the `*`s
  • Loading branch information
seanclifford committed Sep 2, 2021
1 parent 902a8d5 commit 00963b8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Expand Up @@ -361,7 +361,7 @@ def formatted_error_sentence_for( record, attribute )

def simple_format_with_structure( text, options )
new_text = ""
chunks = text.split( /(<table.*table>|<ul.*ul>|<ol.*ol>|<pre.*pre>)/m )
chunks = text.split( /(<table.*?table>|<ul.*?ul>|<ol.*?ol>|<pre.*?pre>)/m )
chunks.each do |chunk|
if chunk =~ /<(table|ul|ol)>/
html = Nokogiri::HTML::DocumentFragment.parse( chunk )
Expand Down

0 comments on commit 00963b8

Please sign in to comment.