Commit 67cf5917 authored by Brett Walker's avatar Brett Walker

'code_block' closer to original implementation

- utilize the 'out' method to output the 'fence_info',
  which converts to utf8
- output 'sourcepos' again
parent e91dc8f4
...@@ -4,15 +4,11 @@ module Banzai ...@@ -4,15 +4,11 @@ module Banzai
class HTML < CommonMarker::HtmlRenderer class HTML < CommonMarker::HtmlRenderer
def code_block(node) def code_block(node)
block do block do
code = node.string_content out("<pre#{sourcepos(node)}><code")
lang = node.fence_info out(' lang="', node.fence_info, '"') if node.fence_info.present?
lang_attr = lang.present? ? %Q{ lang="#{lang}"} : '' out('>')
result = out(escape_html(node.string_content))
"<pre>" \ out('</code></pre>')
"<code#{lang_attr}>#{ERB::Util.html_escape(code)}</code>" \
"</pre>"
out(result)
end end
end end
end end
......
...@@ -40,6 +40,12 @@ describe Banzai::Filter::MarkdownFilter do ...@@ -40,6 +40,12 @@ describe Banzai::Filter::MarkdownFilter do
expect(result).to start_with("<pre><code>") expect(result).to start_with("<pre><code>")
end end
it 'works with utf8 chars in language' do
result = filter("```日\nsome code\n```")
expect(result).to start_with("<pre><code lang=\"\">")
end
end end
context 'using Redcarpet' do context 'using Redcarpet' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment