@@ -79,19 +79,11 @@ def self.line_transforms!(paragraphs)
7979 end
8080 end
8181
82- # We only HTML escape very few things, for simplicity
83- HTMLESCAPE_RULES = { "&" => "&" , "<" => "<" , ">" => ">" } . freeze
84-
85- # Insert <{mark, strong, em, a, br}> into the paragraph after escaping HTML
82+ # Perform the transforms in Clayoven::Claytext::Transforms::INLINE on
83+ # Paragraph entries in-place
8684 def self . inline_transforms! ( paragraphs )
87- paragraphs . each do |p |
88- p . replace p
89- . gsub ( /[<>&]/ , HTMLESCAPE_RULES )
90- . gsub ( /`([^`]+)`/ , '<mark>\1</mark>' )
91- . gsub ( /!\{ ([^\} ]+)\} / , '<strong>\1</strong>' )
92- . gsub ( /!_\{ ([^\} ]+)\} / , '<em>\1</em>' )
93- . gsub ( /\[ ([^\[ \] ]+)\] \( ([^)]+)\) / , '<a href="\2">\1</a>' )
94- . gsub ( "\u{23CE} " , "<br>" )
85+ Transforms ::INLINE . each do |regex , replacement |
86+ paragraphs . each { |p | p . gsub! regex , replacement }
9587 end
9688 end
9789
@@ -110,11 +102,11 @@ def self.process(body)
110102 line_transforms! ( paragraphs . filter { |p | p . type == :plain } )
111103
112104 # Finally, do inline transforms on paragraphs untouched by the fenced transforms
113- inline_transforms! (
114- paragraphs . reject { |p |
115- %i[ codeblock images mathjax ] . count ( p . type ) . positive?
116- }
117- )
105+ filtered_paragraphs =
106+ paragraphs . reject do |p |
107+ %i[ codeblock images mathjax ] . count ( p . type ) . positive?
108+ end
109+ inline_transforms! filtered_paragraphs
118110
119111 # Result: paragraphs
120112 paragraphs
0 commit comments