class BlueDoc::SML::Renderer
Attributes
config[RW]
in_block[RW]
For table, list for temp mark in block
list[RW]
sml[RW]
value[RW]
Public Class Methods
new(sml, options)
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 14 def initialize(sml, options) @sml = sml @config = Config.new @config.plantuml_service_host = options[:plantuml_service_host] @config.mathjax_service_host = options[:mathjax_service_host] @value = YAML.load(sml) @list = {} end
Public Instance Methods
children_to_html(node)
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 38 def children_to_html(node) return node if node.is_a?(String) children = self.class.get_children(node) parent_is_list = self.class.tag_name(node) == "list" parent_attrs = self.class.attributes(node) children.each_with_index.map do |child, idx| prev_node = idx > 0 ? children[idx - 1] : nil next_node = idx < children.length ? children[idx + 1] : nil list = self.list is_list = self.class.tag_name(child) == "list" child_attrs = self.class.attributes(child) if is_list nid = child_attrs[:nid] # BUG: ignore invlid nested list if parent_is_list return "" end if list[nid] list[nid] << child else list[nid] = [child] end end pre_node_attrs = self.class.attributes(prev_node) if (!is_list && self.class.tag_name(prev_node) == "list") || (is_list && self.class.tag_name(prev_node) == "list" && child_attrs[:nid] != pre_node_attrs[:nid]) nid = pre_node_attrs[:nid] list.delete(nid) end node_to_html(child, prev: prev_node, next: next_node) end.join("") end
children_to_text(node)
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 92 def children_to_text(node) return node if node.is_a?(String) children = self.class.get_children(node) text = children.each_with_index.map do |child, idx| text = node_to_text(child, {}) text.blank? ? nil : text end.compact.join(" ") end
node_to_html(node, opts = {})
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 31 def node_to_html(node, opts = {}) opts[:renderer] = self rule = BlueDoc::SML::Rules::find_by_node(node) rule.to_html(node, opts) end
node_to_text(node, opts = {})
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 86 def node_to_text(node, opts = {}) opts[:renderer] = self rule = BlueDoc::SML::Rules::find_by_node(node) ERB::Util.html_escape(rule.to_text(node, opts)&.strip) end
to_html()
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 23 def to_html node_to_html(self.value) end
to_s()
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 27 def to_s to_html end
to_text()
click to toggle source
# File lib/bluedoc/sml/renderer.rb, line 82 def to_text node_to_text(self.value) end