Class: NwodkramParser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- NwodkramParser
- Defined in:
- lib/nwodkram_parser.rb
Constant Summary collapse
- MARKDOWN =
{ 'p' => ["" , "\n"], 'a' => ["[" , lambda { "](#{@attr['href']})" }], 'img' => [ lambda {"![#{@attr['title'] || @attr['alt']}](#{@attr['src']})"}, ""], 'li' => [ lambda { @parent == "ul" ? "* " : "1. " } , "\n"], 'code' => ["" , ""], 'h1' => ["# " , " #\n" ], 'h2' => ["## " , " ##\n" ], 'h3' => ["### " , " ###\n"], 'em' => ["*" , "*"], 'blockquote' => ["> " , ""], 'strong' => ["**" , "**"] }
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #cdata_block(string) ⇒ Object
-
#characters(string) ⇒ Object
content of the markup.
- #end_element(name) ⇒ Object
- #start_element(name, attributes = []) ⇒ Object
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
3 4 5 |
# File 'lib/nwodkram_parser.rb', line 3 def attr @attr end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/nwodkram_parser.rb', line 3 def name @name end |
Instance Method Details
#cdata_block(string) ⇒ Object
44 45 46 |
# File 'lib/nwodkram_parser.rb', line 44 def cdata_block(string) print string end |
#characters(string) ⇒ Object
content of the markup
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nwodkram_parser.rb', line 29 def characters(string) case @name when "code" string.split("\n").each {|line| print " #{line}\n" # 4 spaces to indicate code } when "img" print "" # image doesn't contain any children, normally when 'p','h1','h2','h3', 'li', 'ul','ol','blockquote' print string.chomp else print string end end |