Module: Markita::Markdown::Code
- Defined in:
- lib/markita/markdown/code.rb
Overview
Module to isolate from Markdown
Constant Summary collapse
- RGX =
/^[`]{3}\s*(\w+)?$/
Class Method Summary collapse
Class Method Details
.code(file, lang, code = String.new) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/markita/markdown/code.rb', line 12 def self.code(file, lang, code = String.new) # Note that we can ignore the final shifted # line because it will be the closing fence. while (line = file.gets) && !RGX.match?(line) code << line end lang ? ROUGE.format(lang.new.lex(code)) : code end |
.klass_lang(line) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/markita/markdown/code.rb', line 21 def self.klass_lang(line) if (mdt = RGX.match(line)) lang = Rouge::Lexer.find(mdt[1]) klass = lang ? ' class="highlight"' : '' [klass, lang] end end |