Class: TDiary::Style::HTMLwithRouge

Inherits:
CommonMarker::HtmlRenderer
  • Object
show all
Defined in:
lib/tdiary/style/markdown.rb

Instance Method Summary collapse

Instance Method Details

#code_block(node) ⇒ Object



195
196
197
198
199
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
# File 'lib/tdiary/style/markdown.rb', line 195

def code_block(node)
	language = if node.fence_info && !node.fence_info.empty?
					  node.fence_info.split(/\s+/)[0]
				  else
					  nil
				  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('><code>')
		else
			out("<pre#{sourcepos(node)}")
			if language
				out(' class="highlight ', language, '">')
			else
				out(' class="highlight plaintext">')
			end
		end
		out('<code>')
		out(highlighted)
		out('</code></pre>')
	end
end

#image(node) ⇒ Object



226
227
228
229
230
231
232
233
234
235
# File 'lib/tdiary/style/markdown.rb', line 226

def image(node)
	out('<img src="', escape_href(node.url), '"')
	plain do
		out(' alt="', :children, '"')
	end
	if node.title && !node.title.empty?
		out(' title="', escape_html(node.title), '"')
	end
	out('>')
end

#rouge_formatter(lexer) ⇒ Object



237
238
239
# File 'lib/tdiary/style/markdown.rb', line 237

def rouge_formatter(lexer)
	::Rouge::Formatters::HTML.new(:css_class => "highlight #{lexer.tag}")
end