class TDiary::Style::HTMLwithRouge

Public Instance Methods

code_block(node) click to toggle source
# 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
image(node) click to toggle source
# File lib/tdiary/style/markdown.rb, line 237
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) click to toggle source
# File lib/tdiary/style/markdown.rb, line 248
def rouge_formatter(lexer)
        ::Rouge::Formatters::HTML.new(:css_class => "highlight #{lexer.tag}")
end