'code_block' closer to original implementation
- utilize the 'out' method to output the 'fence_info', which converts to utf8 - output 'sourcepos' again
This commit is contained in:
parent
e91dc8f4ba
commit
67cf5917e0
2 changed files with 11 additions and 9 deletions
|
@ -4,15 +4,11 @@ module Banzai
|
|||
class HTML < CommonMarker::HtmlRenderer
|
||||
def code_block(node)
|
||||
block do
|
||||
code = node.string_content
|
||||
lang = node.fence_info
|
||||
lang_attr = lang.present? ? %Q{ lang="#{lang}"} : ''
|
||||
result =
|
||||
"<pre>" \
|
||||
"<code#{lang_attr}>#{ERB::Util.html_escape(code)}</code>" \
|
||||
"</pre>"
|
||||
|
||||
out(result)
|
||||
out("<pre#{sourcepos(node)}><code")
|
||||
out(' lang="', node.fence_info, '"') if node.fence_info.present?
|
||||
out('>')
|
||||
out(escape_html(node.string_content))
|
||||
out('</code></pre>')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,6 +40,12 @@ describe Banzai::Filter::MarkdownFilter do
|
|||
|
||||
expect(result).to start_with("<pre><code>")
|
||||
end
|
||||
|
||||
it 'works with utf8 chars in language' do
|
||||
result = filter("```日\nsome code\n```")
|
||||
|
||||
expect(result).to start_with("<pre><code lang=\"日\">")
|
||||
end
|
||||
end
|
||||
|
||||
context 'using Redcarpet' do
|
||||
|
|
Loading…
Reference in a new issue