Class: BlueDoc::SML::Rules::SpanWithMark

Inherits:
Base
  • Object
show all
Defined in:
lib/bluedoc/sml/rules/span_with_mark.rb

Constant Summary collapse

MARKS =
{
  cd: ["<code>", "</code>"],
  b: ["<strong>", "</strong>"],
  i: ["<i>", "</i>"],
  s: ["<del>", "</del>"],
  u: ["<u>", "</u>"],
  m: ["<mark>", "</mark>"],
  sup: ["<sup>", "</sup>"],
  sub: ["<sub>", "</sub>"],
}

Constants inherited from Base

Base::INDENT_PX

Class Method Summary collapse

Methods inherited from Base

to_text

Class Method Details

.match?(node) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/bluedoc/sml/rules/span_with_mark.rb', line 17

def self.match?(node)
  return false unless tag_name(node) == "span"
  attrs = attributes(node)
  attrs[:t] == 0
end

.to_html(node, opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bluedoc/sml/rules/span_with_mark.rb', line 23

def self.to_html(node, opts = {})
  attrs = attributes(node)
  renderer = opts[:renderer]
  if attrs[:cd] == 1
    children = renderer.children_to_text(node)
  else
    children = renderer.children_to_html(node)
  end

  case attrs[:va]
  when "superscript" then attrs[:sup] = 1
  when "subscript" then attrs[:sub] = 1
  end

  MARKS.each_key do |key|
    if attrs[key] == 1
      mark = MARKS[key]
      children = "#{mark.first}#{children}#{mark.last}"
    end
  end

  style_attrs = style_for_attrs(attrs)
  return children if style_attrs.blank?

  "<span#{style_attrs}>#{children}</span>"
end