Class: Commonmarker::Node
- Inherits:
-
Object
- Object
- Commonmarker::Node
- Includes:
- Inspect, Enumerable
- Defined in:
- lib/commonmarker/node.rb,
lib/commonmarker/node/ast.rb,
lib/commonmarker/node/inspect.rb
Defined Under Namespace
Constant Summary
Constants included from Inspect
Instance Method Summary collapse
-
#each ⇒ Object
Public: Iterate over the children (if any) of the current pointer.
-
#to_commonmark(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) ⇒ Object
Public: Convert the node to a CommonMark string.
-
#to_html(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) ⇒ Object
Public: Converts a node to an HTML string.
-
#walk {|_self| ... } ⇒ Object
Public: An iterator that “walks the tree,” descending into children recursively.
Methods included from Inspect
Instance Method Details
#each ⇒ Object
Public: Iterate over the children (if any) of the current pointer.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/commonmarker/node.rb', line 24 def each return enum_for(:each) unless block_given? child = first_child while child next_child = child.next_sibling yield child child = next_child end end |
#to_commonmark(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) ⇒ Object
Public: Convert the node to a CommonMark string.
options - A Symbol or of Symbols indicating the render options plugins - A Hash of additional plugins.
Returns a String.
56 57 58 59 60 61 62 63 |
# File 'lib/commonmarker/node.rb', line 56 def to_commonmark(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) raise TypeError, "options must be a Hash; got a #{.class}!" unless .is_a?(Hash) opts = Config.() plugins = Config.process_plugins(plugins) node_to_commonmark(options: opts, plugins: plugins).force_encoding("utf-8") end |
#to_html(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) ⇒ Object
Public: Converts a node to an HTML string.
options - A Hash of render, parse, and extension options to transform the text. plugins - A Hash of additional plugins.
Returns a String of HTML.
41 42 43 44 45 46 47 48 |
# File 'lib/commonmarker/node.rb', line 41 def to_html(options: Commonmarker::Config::OPTIONS, plugins: Commonmarker::Config::PLUGINS) raise TypeError, "options must be a Hash; got a #{.class}!" unless .is_a?(Hash) opts = Config.() plugins = Config.process_plugins(plugins) node_to_html(options: opts, plugins: plugins).force_encoding("utf-8") end |
#walk {|_self| ... } ⇒ Object
Public: An iterator that “walks the tree,” descending into children recursively.
blk - A Proc representing the action to take for each child
14 15 16 17 18 19 20 21 |
# File 'lib/commonmarker/node.rb', line 14 def walk(&block) return enum_for(:walk) unless block yield self each do |child| child.walk(&block) end end |