111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/kramdown/converter/html.rb', line 111
def convert_codeblock(el, indent)
attr = el.attr.dup
lang = (attr)
hl_opts = {}
highlighted_code = highlight_code(el.value, el.options[:lang] || lang, :block, hl_opts)
if highlighted_code
add_syntax_highlighter_to_class_attr(attr, lang || hl_opts[:default_lang])
"#{' ' * indent}<div#{html_attributes(attr)}>#{highlighted_code}#{' ' * indent}</div>\n"
else
result = escape_html(el.value)
result.chomp!
if el.attr['class'].to_s =~ /\bshow-whitespaces\b/
result.gsub!(/(?:(^[ \t]+)|([ \t]+$)|([ \t]+))/) do |m|
suffix = ($1 ? '-l' : ($2 ? '-r' : ''))
m.scan(/./).map do |c|
case c
when "\t" then "<span class=\"ws-tab#{suffix}\">\t</span>"
when " " then "<span class=\"ws-space#{suffix}\">⋅</span>"
end
end.join('')
end
end
code_attr = {}
code_attr['class'] = "language-#{lang}" if lang
"#{' ' * indent}<pre#{html_attributes(attr)}>" \
"<code#{html_attributes(code_attr)}>#{result}\n</code></pre>\n"
end
end
|