16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/synclenote/markdown_to_enml_builder.rb', line 16
def call(markdown_text)
formatter = Redcarpet::Markdown.new(
Redcarpet::Render::HTML.new(
filter_html: true,
hard_wrap: true,
),
underline: true,
lax_spacing: true,
footnotes: true,
no_intra_emphasis: true,
superscript: true,
strikethrough: true,
tables: true,
space_after_headers: true,
fenced_code_blocks: true,
)
html = formatter.render(markdown_text)
root = Nokogiri::HTML::DocumentFragment.parse(html)
root.css("*[class]").each do |node|
node.remove_attribute("class")
end
treated_html = root.to_html
content = [
HEADER,
treated_html.gsub(/<(br|hr|img).*?>/, "\\&</\\1>"),
FOOTER,
].join
return content
end
|