200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/tdiary/style/markdown.rb', line 200
def code_block(node)
language = if node.fence_info && !node.fence_info.empty?
node.fence_info.split(/\s+/)[0]
else
nil
end
caption_part = ""
language, caption = language.split(":", 2) if language
if caption
caption_part = "<span class=\"caption\">#{escape_html(caption)}</span>\n"
end
code = node.string_content
lexer = Rouge::Lexer.find_fancy(language, code) || Rouge::Lexers::PlainText
formatter = rouge_formatter(lexer)
highlighted = formatter.format(lexer.lex(code))
block do
if option_enabled?(:GITHUB_PRE_LANG)
out("<pre#{sourcepos(node)}")
if language
out(' lang="', language, '"')
end
out(">")
else
out("<pre#{sourcepos(node)}")
if language
out(' class="highlight ', language, '">')
else
out(' class="highlight plaintext">')
end
end
out(caption_part)
out('<code>')
out(highlighted)
out('</code></pre>')
end
end
|