11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/pages/raindown/raindown.rb', line 11
def render(markdown:)
template = markdown.gsub('<{', '<!-- ANTLERS').gsub('}>', 'ANTLERS -->')
doc = Commonmarker.parse(template)
doc.walk do |node|
if node.type == :code || node.type == :code_block
node.string_content = node.string_content.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
end
end
template = doc.to_html(options: { render: { unsafe: true } })
template = template.gsub('<!-- ANTLERS', '<{').gsub('ANTLERS -->', '}>')
return template unless template.include?('<{') || template.include?('{')
ast = Antlers.ast(template:, elements: Antlers::Elements[:html, :prop] + Rain::Elements[:toc])
Antlers.render(ast:, current_binding: binding)
end
|