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.
-
#respond_to?(name, include_all = false) ⇒ Boolean
Public: Whether this node responds to the given method.
-
#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.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/commonmarker/node.rb', line 36 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 |
#respond_to?(name, include_all = false) ⇒ Boolean
Public: Whether this node responds to the given method.
name - A Symbol or String naming the method. include_all - A Boolean indicating whether to consider private methods.
Returns a Boolean.
17 18 19 20 21 |
# File 'lib/commonmarker/node.rb', line 17 def respond_to?(name, include_all = false) return false if node_supports?(name.to_sym) == false super 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.
68 69 70 71 72 73 74 75 |
# File 'lib/commonmarker/node.rb', line 68 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(render: opts[:render], parse: opts[:parse], extension: opts[:extension], 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.
53 54 55 56 57 58 59 60 |
# File 'lib/commonmarker/node.rb', line 53 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(render: opts[:render], parse: opts[:parse], extension: opts[:extension], 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
26 27 28 29 30 31 32 33 |
# File 'lib/commonmarker/node.rb', line 26 def walk(&block) return enum_for(:walk) unless block yield self each do |child| child.walk(&block) end end |