module Paru::PandocFilter::InnerMarkdown
A mixin to add inner_markdown
properties to Nodes for which it makes sense to have an inner_markdown. Only those nodes that have a clear identifiable Inline
level content, have the {#inner_markdown} method. This are almost all Inline
nodes (except Cite
) and Block
level nodes with Inline
contents like {Para} or {Header}.
Public Instance Methods
inner_markdown()
click to toggle source
Get the markdown representation of this Node’s children.
@return [String] the inner markdown representation of this Node
@example Replace all occurrences of “hello” by “world” in all paragraphs
Paru::Filter.run do with "Para" do |p| p.inner_markdown = p.inner_markdown.gsub "hello", "world" end end
# File lib/paru/filter/inner_markdown.rb, line 40 def inner_markdown() if has_children? temp_doc = PandocFilter::Document.fragment @children AST2MARKDOWN << temp_doc.to_JSON elsif has_string? @string end end
inner_markdown=(markdown)
click to toggle source
Replace this Node’s children with the Nodes represented by the markdown string
@param markdown [String] the markdown string to replace this
Node's children
@example Replace all occurrences of “hello” by “world” in all paragraphs
Paru::Filter.run do with "Para" do |p| p.inner_markdown = p.inner_markdown.gsub "hello", "world" end end
# File lib/paru/filter/inner_markdown.rb, line 62 def inner_markdown=(markdown) if has_string? @string = markdown else if markdown.nil? or markdown.empty? @children = [] else json = MARKDOWN2JSON << markdown temp_doc = PandocFilter::Document.from_JSON json temp_doc.children.each {|c| c.parent = @parent} if has_inline? @children = temp_doc.children.first.children elsif has_block? @children = temp_doc.children else # Unknown; what to do here? end end end end