module TextTube::Baby::InsideBlock
This finds html tags with “markdown='1'” as an attribute, runs markdown over the contents, then removes the markdown attribute, allowing markdown within html blocks
Public Class Methods
run( content, options={})
click to toggle source
@param [String] content @param [Hash] options @option options [Constant] The markdown parser to use. I'm not sure this bit really works for other parsers than RDiscount.
# File lib/texttube/baby/inside_block.rb, line 19 def self.run( content, options={}) options ||= {} if options[:markdown_parser].nil? require 'rdiscount' markdown_parser=RDiscount end doc = Oga.parse_html(content) doc.xpath("*[@markdown='1']").each do |ele| inner_text = ele.children.inject(""){|mem,child| mem << child.to_xml } html_fragment = markdown_parser.new(inner_text).to_html ele.children= Oga.parse_html( html_fragment ).children ele.unset "markdown" end doc.to_xml end