Class: MarkupNode
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- MarkupNode
- Defined in:
- lib/assets/lib/markup_node.rb
Overview
MarkupNode is an wrapper introduced to simplify
producing Pandoc markdown output.
It's a delegator to the Node class
Constant Summary collapse
- @@macros =
register available macros
Array.new.tap do |ary| ary << SkipMacro.new ary << ListMacro.new ary << TreeMacro.new ary << EvalMacro.new ary.freeze end
Instance Method Summary collapse
-
#body ⇒ String
Output text for node.body.
-
#link(ref) ⇒ String
Output text for link [[node.id]].
- #markup ⇒ Object
-
#meta ⇒ String
Output text of node.meta.
-
#title ⇒ String
Output text of node.title.
-
#url(id) ⇒ String
Url for node.id.
Instance Method Details
#body ⇒ String
Returns output text for node.body.
46 47 48 49 50 51 52 |
# File 'lib/assets/lib/markup_node.rb', line 46 def body String.new(super).tap do |txt| process_links!(txt) process_macro!(txt) txt.gsub!(/^$\n{2,}/, "\n") end end |
#link(ref) ⇒ String
Returns output text for link [[node.id]].
55 56 57 58 59 |
# File 'lib/assets/lib/markup_node.rb', line 55 def link(ref) node = root.find{|n| n.id == ref} return "[#{ref}](#unknown)" unless node "[#{node.title}](##{url(ref)})" end |
#markup ⇒ Object
18 19 20 |
# File 'lib/assets/lib/markup_node.rb', line 18 def markup [title, , body].select{|part| !part.empty?}.join("\n\n") end |
#meta ⇒ String
Returns output text of node.meta.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/assets/lib/markup_node.rb', line 30 def return '' if nesting_level == 0 return '' if super[:skip_meta] hsh = {id: id}.merge(super) hsh.delete(:order_index) hsh.delete(:filename) hsh.delete(:parent) [].tap{|ary| ary << "Attribute | Value" ary << "--------- | -----" hsh.each{|k,v| ary << "#{k} | #{v}"} }.join("\n") end |
#title ⇒ String
Returns output text of node.title.
23 24 25 26 27 |
# File 'lib/assets/lib/markup_node.rb', line 23 def title s = super s = ".#{id.split(/\./).last}" if s.empty? "#{'#' * nesting_level} #{s} {##{url(id)}}" end |
#url(id) ⇒ String
Returns url for node.id.
62 63 64 65 66 67 68 |
# File 'lib/assets/lib/markup_node.rb', line 62 def url(id) r = id.start_with?(/[[:digit:]]/) ? "p#{id}" : id r.downcase .gsub(/[^A-Za-z0-9]{1,}/, '-') .gsub(/^-/, '') .gsub(/-$/, '') end |