Module: TextTube::InsideBlock

Extended by:
Filterable
Defined in:
lib/texttube/filters/inside_block.rb

Overview

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

Class Method Summary collapse

Methods included from Filterable

filter_with, filters

Class Method Details

.run(content, options = {}) ⇒ Object

Parameters:

  • content (String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • The (Constant)

    markdown parser to use. I’m not sure this bit really works for other parsers than RDiscount.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/texttube/filters/inside_block.rb', line 18

def self.run( content, options={})   
  options ||= {} 
  if options[:markdown_parser].nil?
    require 'rdiscount' 
    markdown_parser=RDiscount
  end
  doc = Nokogiri::HTML::fragment(content) 
  
  (doc/"*[@markdown='1']").each do |ele|  
    ele.inner_html = markdown_parser.new(ele.inner_html).to_html
    ele.remove_attribute("markdown")
  end
  
  doc.to_s
end