@@ -79,19 +79,11 @@ def self.line_transforms!(paragraphs)
79
79
end
80
80
end
81
81
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
86
84
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 }
95
87
end
96
88
end
97
89
@@ -110,11 +102,11 @@ def self.process(body)
110
102
line_transforms! ( paragraphs . filter { |p | p . type == :plain } )
111
103
112
104
# 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
118
110
119
111
# Result: paragraphs
120
112
paragraphs
0 commit comments