Module: IsoDoc::Function::Inline

Included in:
Common
Defined in:
lib/isodoc/function/inline.rb,
lib/isodoc/function/inline_simple.rb

Constant Summary collapse

MATHML =
{ "m" => "http://www.w3.org/1998/Math/MathML" }.freeze

Instance Method Summary collapse

Instance Method Details

#add_parse(node, out) ⇒ Object



170
171
172
173
174
# File 'lib/isodoc/function/inline.rb', line 170

def add_parse(node, out)
  out.span class: "addition" do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#asciimath_parse(node) ⇒ Object



123
124
125
126
127
128
# File 'lib/isodoc/function/inline.rb', line 123

def asciimath_parse(node)
  a = node.at(ns("./asciimath"))&.text || node.text

  "#{@openmathdelim}#{HTMLEntities.new.encode(a)}" \
    "#{@closemathdelim}"
end

#bookmark_parse(node, out) ⇒ Object



28
29
30
# File 'lib/isodoc/function/inline_simple.rb', line 28

def bookmark_parse(node, out)
  out.a **attr_code(id: node["id"])
end

#br_parse(_node, out) ⇒ Object



20
21
22
# File 'lib/isodoc/function/inline_simple.rb', line 20

def br_parse(_node, out)
  out.br
end

#callout_parse(node, out) ⇒ Object



29
30
31
# File 'lib/isodoc/function/inline.rb', line 29

def callout_parse(node, out)
  out << " &lt;#{node.text}&gt;"
end

#del_parse(node, out) ⇒ Object



176
177
178
179
180
# File 'lib/isodoc/function/inline.rb', line 176

def del_parse(node, out)
  out.span class: "deletion" do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#em_parse(node, out) ⇒ Object



38
39
40
41
42
# File 'lib/isodoc/function/inline_simple.rb', line 38

def em_parse(node, out)
  out.i do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#eref_parse(node, out) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/isodoc/function/inline.rb', line 76

def eref_parse(node, out)
  if href = eref_target(node)
    if node["type"] == "footnote"
      out.sup do |s|
        s.a(href: href) { |l| no_locality_parse(node, l) }
      end
    else
      out.a(href: href) { |l| no_locality_parse(node, l) }
    end
  else no_locality_parse(node, out)
  end
end

#eref_target(node) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/isodoc/function/inline.rb', line 55

def eref_target(node)
  url = suffix_url(eref_url(node["bibitemid"]))
  anchor = node&.at(ns(".//locality[@type = 'anchor']"))
  return url if url.nil? || /^#/.match?(url) || !anchor

  "#{url}##{anchor.text.strip}"
end

#eref_url(id) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/isodoc/function/inline.rb', line 63

def eref_url(id)
  @bibitems.nil? and return nil

  b = @bibitems[id]
  b.nil? and return nil

  url = b.at(ns("./uri[@type = 'citation'][@language = '#{@lang}']")) and
    return url.text
  url = b.at(ns("./uri[@type = 'citation']")) and return url.text
  b["hidden"] == "true" and return b.at(ns("./uri"))&.text
  "##{id}"
end

#error_parse(node, out) ⇒ Object



182
183
184
185
186
187
# File 'lib/isodoc/function/inline.rb', line 182

def error_parse(node, out)
  text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
  out.para do |p|
    p.b(role: "strong") { |e| e << text }
  end
end

#hr_parse(_node, out) ⇒ Object



16
17
18
# File 'lib/isodoc/function/inline_simple.rb', line 16

def hr_parse(_node, out)
  out.hr
end

#image_parse(node, out, caption) ⇒ Object



143
144
145
146
147
148
149
150
151
# File 'lib/isodoc/function/inline.rb', line 143

def image_parse(node, out, caption)
  attrs = { src: node["src"],
            height: node["height"] || "auto",
            width: node["width"] || "auto",
            title: node["title"],
            alt: node["alt"] }
  out.img **attr_code(attrs)
  image_title_parse(out, caption)
end

#image_title_parse(out, caption) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/isodoc/function/inline.rb', line 135

def image_title_parse(out, caption)
  unless caption.nil?
    out.p class: "FigureTitle", style: "text-align:center;" do |p|
      p.b { |b| b << caption.to_s }
    end
  end
end

#index_parse(node, out) ⇒ Object



24
# File 'lib/isodoc/function/inline_simple.rb', line 24

def index_parse(node, out); end

#index_xref_parse(node, out) ⇒ Object



26
# File 'lib/isodoc/function/inline_simple.rb', line 26

def index_xref_parse(node, out); end

#keyword_parse(node, out) ⇒ Object



32
33
34
35
36
# File 'lib/isodoc/function/inline_simple.rb', line 32

def keyword_parse(node, out)
  out.span class: "keyword" do |s|
    node.children.each { |n| parse(n, s) }
  end
end

#latexmath_parse(node) ⇒ Object



130
131
132
133
# File 'lib/isodoc/function/inline.rb', line 130

def latexmath_parse(node)
  a = node.at(ns("./latexmath"))&.text || node.text
  HTMLEntities.new.encode(a)
end


6
7
8
9
10
11
12
13
14
15
# File 'lib/isodoc/function/inline.rb', line 6

def link_parse(node, out)
  url = node["target"]
  node["update-type"] == "true" and url = suffix_url(url)
  out.a **attr_code(href: url, title: node["alt"]) do |l|
    if node.text.empty?
      l << node["target"].sub(/^mailto:/, "")
    else node.children.each { |n| parse(n, l) }
    end
  end
end

#location_parse(node, out) ⇒ Object



17
# File 'lib/isodoc/function/inline.rb', line 17

def location_parse(node, out); end

#mathml_parse(node) ⇒ Object



119
120
121
# File 'lib/isodoc/function/inline.rb', line 119

def mathml_parse(node)
  node.at("./m:math", MATHML)&.to_xml
end

#no_locality_parse(node, out) ⇒ Object



33
34
35
36
37
# File 'lib/isodoc/function/inline.rb', line 33

def no_locality_parse(node, out)
  node.children.each do |n|
    parse(n, out) unless %w{locality localityStack}.include? n.name
  end
end

#origin_parse(node, out) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/isodoc/function/inline.rb', line 89

def origin_parse(node, out)
  if t = node.at(ns("./termref"))
    termrefelem_parse(t, out)
  else
    eref_parse(node, out)
  end
end

#page_break(out) ⇒ Object



8
9
10
# File 'lib/isodoc/function/inline_simple.rb', line 8

def page_break(out)
  out.br
end

#pagebreak_parse(_node, out) ⇒ Object



12
13
14
# File 'lib/isodoc/function/inline_simple.rb', line 12

def pagebreak_parse(_node, out)
  out.br
end

#section_break(body) ⇒ Object



4
5
6
# File 'lib/isodoc/function/inline_simple.rb', line 4

def section_break(body)
  body.br
end

#smallcap_parse(node, xml) ⇒ Object



153
154
155
156
157
# File 'lib/isodoc/function/inline.rb', line 153

def smallcap_parse(node, xml)
  xml.span style: "font-variant:small-caps;" do |s|
    node.children.each { |n| parse(n, s) }
  end
end

#span_parse(node, out) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/isodoc/function/inline.rb', line 19

def span_parse(node, out)
  if node["style"] || node["class"]
    out.span **attr_code(style: node["style"],
                         class: node["class"]) do |s|
      node.children.each { |n| parse(n, s) }
    end
  else node.children.each { |n| parse(n, out) }
  end
end

#stem_parse(node, out) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/isodoc/function/inline.rb', line 105

def stem_parse(node, out)
  ooml = case node["type"]
         when "AsciiMath" then asciimath_parse(node)
         when "MathML" then mathml_parse(node)
         when "LaTeX" then latexmath_parse(node)
         else HTMLEntities.new.encode(node.text)
         end
  out.span class: "stem" do |span|
    span.parent.add_child ooml
  end
end

#strike_parse(node, out) ⇒ Object



68
69
70
71
72
# File 'lib/isodoc/function/inline_simple.rb', line 68

def strike_parse(node, out)
  out.s do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#strong_parse(node, out) ⇒ Object



44
45
46
47
48
# File 'lib/isodoc/function/inline_simple.rb', line 44

def strong_parse(node, out)
  out.b do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#sub_parse(node, out) ⇒ Object



56
57
58
59
60
# File 'lib/isodoc/function/inline_simple.rb', line 56

def sub_parse(node, out)
  out.sub do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#suffix_url(url) ⇒ Object



48
49
50
51
52
53
# File 'lib/isodoc/function/inline.rb', line 48

def suffix_url(url)
  return url if url.nil? || %r{^https?://|^#}.match?(url)
  return url unless File.extname(url).empty?

  url.sub(/#{File.extname(url)}$/, ".html")
end

#sup_parse(node, out) ⇒ Object



50
51
52
53
54
# File 'lib/isodoc/function/inline_simple.rb', line 50

def sup_parse(node, out)
  out.sup do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#termrefelem_parse(node, out) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/isodoc/function/inline.rb', line 97

def termrefelem_parse(node, out)
  if node.text.strip.empty?
    out << "Termbase #{node['base']}, term ID #{node['target']}"
  else
    node.children.each { |n| parse(n, out) }
  end
end

#text_parse(node, out) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/isodoc/function/inline.rb', line 159

def text_parse(node, out)
  return if node.nil? || node.text.nil?

  text = node.to_s
  @sourcecode == "pre" and
    text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&#xa0;")
  @sourcecode and
    text = text.gsub(/ (?= )/, "&#xa0;")
  out << text
end

#tt_parse(node, out) ⇒ Object



62
63
64
65
66
# File 'lib/isodoc/function/inline_simple.rb', line 62

def tt_parse(node, out)
  out.tt do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#underline_parse(node, out) ⇒ Object



74
75
76
77
78
79
# File 'lib/isodoc/function/inline_simple.rb', line 74

def underline_parse(node, out)
  node["style"] and style = "text-decoration: #{node['style']}"
  out.u **attr_code(style: style) do |e|
    node.children.each { |n| parse(n, e) }
  end
end

#xref_parse(node, out) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/isodoc/function/inline.rb', line 39

def xref_parse(node, out)
  target = if /#/.match?(node["target"])
             node["target"].sub(/#/, ".html#")
           else
             "##{node['target']}"
           end
  out.a(href: target) { |l| no_locality_parse(node, l) }
end