Sha256: 1992fab0df3cf8371d6bf77cf7664ff68bcbe284f35a65324d9e746827432f6c
Contents?: true
Size: 1.18 KB
Versions: 6
Compression:
Stored size: 1.18 KB
Contents
require 'wlang' require 'albino' require 'redcarpet' require 'base64' require_relative 'to_markdown' module Alf module Doc class ToHtml class HTMLwithAlbino < Redcarpet::Render::HTML def block_code(code, language) Albino.colorize(code, language || :ruby) end end def operator(op) to_html(ToMarkdown.new.operator(op)) end def aggregator(op) to_html(ToMarkdown.new.aggregator(op)) end def predicate(op) to_html(ToMarkdown.new.predicate(op)) end def page(md) to_html(md) end def to_html(src) src = src.gsub(/([ ]*)```try\n(.*?)\n([ ]*)```/m){|m| spacing = $1 || "" source = $2.strip.gsub(/^#{spacing}/, "") quoted = Base64.encode64(source) source = "```\n#{source}\n```" source = source.gsub(/^/, spacing) %Q{#{source}\n<div class="try-this"><a href="/?src=#{quoted}" target="_blank">Try it!</a></div>} } options = {:fenced_code_blocks => true} Redcarpet::Markdown.new(HTMLwithAlbino, options).render(src) end end # class ToHtml end # module Doc end # module Alf
Version data entries
6 entries across 6 versions & 1 rubygems