Module: IsoDoc::Function::Inline
- Included in:
- Common
- Defined in:
- lib/isodoc/function/inline.rb,
lib/isodoc/function/inline_simple.rb
Constant Summary collapse
- SPAN_UNWRAP_CLASSES =
Presentation XML classes which we need not pass on to HTML or DOC
%w[fmt-caption-label fmt-label-delim fmt-caption-delim fmt-autonum-delim fmt-element-name fmt-conn fmt-comma fmt-enum-comma fmt-obligation fmt-xref-container fmt-designation-field].freeze
- MATHML =
{ "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
Instance Method Summary collapse
- #add_parse(node, out) ⇒ Object
- #amend_parse(node, out) ⇒ Object
- #annotation_note_parse(node, out) ⇒ Object
- #asciimath_parse(node) ⇒ Object
- #author_parse(node, out) ⇒ Object
- #bookmark_parse(node, out) ⇒ Object
- #br_parse(_node, out) ⇒ Object
-
#callout_parse(node, out) ⇒ Object
todo PRESENTATION XML.
- #children_parse(node, out) ⇒ Object
- #concept_parse(node, out) ⇒ Object
- #date_parse(node, out) ⇒ Object
- #del_parse(node, out) ⇒ Object
- #em_parse(node, out) ⇒ Object
- #eref_parse(node, out) ⇒ Object
- #erefstack_parse(node, out) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #floating_title_parse(node, out) ⇒ Object
- #fmt_annotation_end_parse(node, out) ⇒ Object
- #fmt_annotation_start_parse(node, out) ⇒ Object
- #fmt_concept_parse(node, out) ⇒ Object
- #fmt_date_parse(node, out) ⇒ Object
- #fmt_fn_label_parse(node, out) ⇒ Object
- #fmt_footnote_container_parse(node, out) ⇒ Object
- #fmt_identifier_parse(node, out) ⇒ Object
- #fmt_name_parse(node, out) ⇒ Object
- #hr_parse(_node, out) ⇒ Object
- #identifier_parse(node, out) ⇒ Object
- #image_body_parse(_node, attrs, out) ⇒ Object
- #image_parse(node, out, caption) ⇒ Object
- #image_title_parse(out, caption) ⇒ Object
- #index_parse(node, out) ⇒ Object
- #index_xref_parse(node, out) ⇒ Object
- #keyword_parse(node, out) ⇒ Object
- #latexmath_parse(node) ⇒ Object
- #link_parse(node, out) ⇒ Object
- #location_parse(node, out) ⇒ Object
- #mathml_parse(node) ⇒ Object
- #name_parse(node, out) ⇒ Object
- #no_locality_parse(node, out) ⇒ Object
- #origin_parse(node, out) ⇒ Object
- #page_break(out) ⇒ Object
- #pagebreak_parse(_node, out) ⇒ Object
- #rb_parse(node, out) ⇒ Object
- #rt_parse(node, out) ⇒ Object
- #ruby_parse(node, out) ⇒ Object
- #section_break(body) ⇒ Object
- #semx_definition_parse(node, out) ⇒ Object
- #semx_eref_parse(node, out) ⇒ Object
- #semx_link_parse(node, out) ⇒ Object
- #semx_origin_parse(node, out) ⇒ Object
- #semx_parse(node, out) ⇒ Object
- #semx_source_parse(node, out) ⇒ Object
- #semx_sourcecode_parse(node, out) ⇒ Object
- #semx_stem_parse(node, out) ⇒ Object
- #semx_xref_parse(node, out) ⇒ Object
- #smallcap_parse(node, xml) ⇒ Object
- #span_parse(node, out) ⇒ Object
- #stem_parse(node, out) ⇒ Object
- #stem_parse1(ret, type) ⇒ Object
- #strike_parse(node, out) ⇒ Object
- #strong_parse(node, out) ⇒ Object
- #sub_parse(node, out) ⇒ Object
- #suffix_url(url) ⇒ Object
- #sup_parse(node, out) ⇒ Object
- #svgmap_parse(node, out) ⇒ Object
-
#termrefelem_parse(node, out) ⇒ Object
todo PRESENTATION XML.
- #text_parse(node, out) ⇒ Object
- #tt_parse(node, out) ⇒ Object
- #underline_parse(node, out) ⇒ Object
- #xref_label_parse(node, out) ⇒ Object
- #xref_parse(node, out) ⇒ Object
Instance Method Details
#add_parse(node, out) ⇒ Object
158 159 160 161 162 |
# File 'lib/isodoc/function/inline.rb', line 158 def add_parse(node, out) out.span class: "addition" do |e| children_parse(node, e) end end |
#amend_parse(node, out) ⇒ Object
97 |
# File 'lib/isodoc/function/inline_simple.rb', line 97 def amend_parse(node, out); end |
#annotation_note_parse(node, out) ⇒ Object
99 |
# File 'lib/isodoc/function/inline_simple.rb', line 99 def annotation_note_parse(node, out); end |
#asciimath_parse(node) ⇒ Object
109 110 111 112 113 |
# File 'lib/isodoc/function/inline.rb', line 109 def asciimath_parse(node) a = node.at(ns("./asciimath"))&.text || node.text ["#{@openmathdelim}#{HTMLEntities.new.encode(a)}" \ "#{@closemathdelim}", /^[[0-9,.+-]]*$/.match?(a)] end |
#author_parse(node, out) ⇒ Object
82 |
# File 'lib/isodoc/function/inline_simple.rb', line 82 def (node, out); 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
todo PRESENTATION XML
36 37 38 |
# File 'lib/isodoc/function/inline.rb', line 36 def callout_parse(node, out) out << " <#{node.text}>" end |
#children_parse(node, out) ⇒ Object
199 200 201 |
# File 'lib/isodoc/function/inline.rb', line 199 def children_parse(node, out) node&.children&.each { |n| parse(n, out) } end |
#concept_parse(node, out) ⇒ Object
94 |
# File 'lib/isodoc/function/inline_simple.rb', line 94 def concept_parse(node, out); end |
#date_parse(node, out) ⇒ Object
90 |
# File 'lib/isodoc/function/inline_simple.rb', line 90 def date_parse(node, out); end |
#del_parse(node, out) ⇒ Object
164 165 166 167 168 |
# File 'lib/isodoc/function/inline.rb', line 164 def del_parse(node, out) out.span class: "deletion" do |e| children_parse(node, 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| children_parse(node, e) end end |
#eref_parse(node, out) ⇒ Object
61 62 63 |
# File 'lib/isodoc/function/inline.rb', line 61 def eref_parse(node, out) no_locality_parse(node, out) end |
#erefstack_parse(node, out) ⇒ Object
95 |
# File 'lib/isodoc/function/inline_simple.rb', line 95 def erefstack_parse(node, out); end |
#error_parse(node, out) ⇒ Object
170 171 172 173 174 175 |
# File 'lib/isodoc/function/inline.rb', line 170 def error_parse(node, out) text = node.to_xml.gsub("<", "<").gsub(">", ">") out.para do |p| p.b(role: "strong") { |e| e << text } end end |
#floating_title_parse(node, out) ⇒ Object
92 |
# File 'lib/isodoc/function/inline_simple.rb', line 92 def floating_title_parse(node, out); end |
#fmt_annotation_end_parse(node, out) ⇒ Object
233 234 235 |
# File 'lib/isodoc/function/inline.rb', line 233 def fmt_annotation_end_parse(node, out) children_parse(node, out) end |
#fmt_annotation_start_parse(node, out) ⇒ Object
229 230 231 |
# File 'lib/isodoc/function/inline.rb', line 229 def fmt_annotation_start_parse(node, out) children_parse(node, out) end |
#fmt_concept_parse(node, out) ⇒ Object
213 214 215 |
# File 'lib/isodoc/function/inline.rb', line 213 def fmt_concept_parse(node, out) children_parse(node, out) end |
#fmt_date_parse(node, out) ⇒ Object
217 218 219 |
# File 'lib/isodoc/function/inline.rb', line 217 def fmt_date_parse(node, out) children_parse(node, out) end |
#fmt_fn_label_parse(node, out) ⇒ Object
221 222 223 |
# File 'lib/isodoc/function/inline.rb', line 221 def fmt_fn_label_parse(node, out) children_parse(node, out) end |
#fmt_footnote_container_parse(node, out) ⇒ Object
225 226 227 |
# File 'lib/isodoc/function/inline.rb', line 225 def fmt_footnote_container_parse(node, out) children_parse(node, out) end |
#fmt_identifier_parse(node, out) ⇒ Object
207 208 209 210 211 |
# File 'lib/isodoc/function/inline.rb', line 207 def fmt_identifier_parse(node, out) out.span style: "white-space: nowrap;" do |s| children_parse(node, s) end end |
#fmt_name_parse(node, out) ⇒ Object
203 204 205 |
# File 'lib/isodoc/function/inline.rb', line 203 def fmt_name_parse(node, out) children_parse(node, out) 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 |
#identifier_parse(node, out) ⇒ Object
93 |
# File 'lib/isodoc/function/inline_simple.rb', line 93 def identifier_parse(node, out); end |
#image_body_parse(_node, attrs, out) ⇒ Object
138 139 140 |
# File 'lib/isodoc/function/inline.rb', line 138 def image_body_parse(_node, attrs, out) out.img **attr_code(attrs) end |
#image_parse(node, out, caption) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/isodoc/function/inline.rb', line 128 def image_parse(node, out, caption) attrs = { src: node["src"], height: node["height"] || "auto", width: node["width"] || "auto", title: node["title"], alt: node["alt"] } image_body_parse(node, attrs, out) image_title_parse(out, caption) end |
#image_title_parse(out, caption) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/isodoc/function/inline.rb', line 120 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| children_parse(node, s) end end |
#latexmath_parse(node) ⇒ Object
115 116 117 118 |
# File 'lib/isodoc/function/inline.rb', line 115 def latexmath_parse(node) a = node.at(ns("./latexmath"))&.text || node.text [HTMLEntities.new.encode(a), /^[[0-9,.+-]]*$/.match?(a)] end |
#link_parse(node, out) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# 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.elements.empty? && node.text.strip.empty? l << @c.encode(node["target"].sub(/^mailto:/, ""), :basic, :hexadecimal) else children_parse(node, l) end end end |
#location_parse(node, out) ⇒ Object
81 |
# File 'lib/isodoc/function/inline_simple.rb', line 81 def location_parse(node, out); end |
#mathml_parse(node) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/isodoc/function/inline.rb', line 102 def mathml_parse(node) # node.xpath("./m:math", MATHML).map(&:to_xml).join node.xpath(ns("./asciimath | ./latexmath")).each(&:remove) node.xpath(ns("./br")).each { |e| e.namespace = nil } [node.children, node.elements.empty?] end |
#name_parse(node, out) ⇒ Object
84 |
# File 'lib/isodoc/function/inline_simple.rb', line 84 def name_parse(node, out); end |
#no_locality_parse(node, out) ⇒ Object
40 41 42 43 44 |
# File 'lib/isodoc/function/inline.rb', line 40 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
65 66 67 68 69 70 71 |
# File 'lib/isodoc/function/inline.rb', line 65 def origin_parse(node, out) if t = node.at(ns("./termref")) termrefelem_parse(t, out) else no_locality_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 |
#rb_parse(node, out) ⇒ Object
189 190 191 192 193 |
# File 'lib/isodoc/function/inline.rb', line 189 def rb_parse(node, out) out.rb do |e| children_parse(node, e) end end |
#rt_parse(node, out) ⇒ Object
183 184 185 186 187 |
# File 'lib/isodoc/function/inline.rb', line 183 def rt_parse(node, out) out.rt do |e| children_parse(node, e) end end |
#ruby_parse(node, out) ⇒ Object
177 178 179 180 181 |
# File 'lib/isodoc/function/inline.rb', line 177 def ruby_parse(node, out) out.ruby do |e| children_parse(node, e) end end |
#section_break(body) ⇒ Object
4 5 6 |
# File 'lib/isodoc/function/inline_simple.rb', line 4 def section_break(body) body.br end |
#semx_definition_parse(node, out) ⇒ Object
85 |
# File 'lib/isodoc/function/inline_simple.rb', line 85 def semx_definition_parse(node, out); end |
#semx_eref_parse(node, out) ⇒ Object
87 |
# File 'lib/isodoc/function/inline_simple.rb', line 87 def semx_eref_parse(node, out); end |
#semx_link_parse(node, out) ⇒ Object
88 |
# File 'lib/isodoc/function/inline_simple.rb', line 88 def semx_link_parse(node, out); end |
#semx_origin_parse(node, out) ⇒ Object
89 |
# File 'lib/isodoc/function/inline_simple.rb', line 89 def semx_origin_parse(node, out); end |
#semx_parse(node, out) ⇒ Object
195 196 197 |
# File 'lib/isodoc/function/inline.rb', line 195 def semx_parse(node, out) children_parse(node, out) end |
#semx_source_parse(node, out) ⇒ Object
100 |
# File 'lib/isodoc/function/inline_simple.rb', line 100 def semx_source_parse(node, out); end |
#semx_sourcecode_parse(node, out) ⇒ Object
98 |
# File 'lib/isodoc/function/inline_simple.rb', line 98 def semx_sourcecode_parse(node, out); end |
#semx_stem_parse(node, out) ⇒ Object
91 |
# File 'lib/isodoc/function/inline_simple.rb', line 91 def semx_stem_parse(node, out); end |
#semx_xref_parse(node, out) ⇒ Object
86 |
# File 'lib/isodoc/function/inline_simple.rb', line 86 def semx_xref_parse(node, out); end |
#smallcap_parse(node, xml) ⇒ Object
142 143 144 145 146 |
# File 'lib/isodoc/function/inline.rb', line 142 def smallcap_parse(node, xml) xml.span style: "font-variant:small-caps;" do |s| children_parse(node, s) end end |
#span_parse(node, out) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isodoc/function/inline.rb', line 24 def span_parse(node, out) klass = node["style"] || node["class"] if klass && !SPAN_UNWRAP_CLASSES.include?(klass) out.span **attr_code(style: node["style"], class: node["class"]) do |s| children_parse(node, s) end else children_parse(node, out) end end |
#stem_parse(node, out) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/isodoc/function/inline.rb', line 81 def stem_parse(node, out) ret = node.at(ns("./semx[@element = 'stem']")) || node ooml, text_only = stem_parse1(ret, node["type"]) klass = text_only ? {} : { class: "stem" } out.span **klass do |span| span.parent.add_child ooml end end |
#stem_parse1(ret, type) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/isodoc/function/inline.rb', line 90 def stem_parse1(ret, type) case type when "AsciiMath" then asciimath_parse(ret) when "MathML" then mathml_parse(ret) when "LaTeX" then latexmath_parse(ret) else [HTMLEntities.new.encode(ret.text), /^[[0-9,.+-]]*$/.match?(ret.text)] 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| children_parse(node, 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| children_parse(node, 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| children_parse(node, e) end end |
#suffix_url(url) ⇒ Object
55 56 57 58 59 |
# File 'lib/isodoc/function/inline.rb', line 55 def suffix_url(url) url.nil? || %r{^https?://|^#}.match?(url) and return url File.extname(url).empty? or return url 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| children_parse(node, e) end end |
#svgmap_parse(node, out) ⇒ Object
96 |
# File 'lib/isodoc/function/inline_simple.rb', line 96 def svgmap_parse(node, out); end |
#termrefelem_parse(node, out) ⇒ Object
todo PRESENTATION XML
74 75 76 77 78 79 |
# File 'lib/isodoc/function/inline.rb', line 74 def termrefelem_parse(node, out) if node.text.strip.empty? out << "Termbase #{node['base']}, term ID #{node['target']}" else children_parse(node, out) end end |
#text_parse(node, out) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/isodoc/function/inline.rb', line 148 def text_parse(node, out) node.nil? || node.text.nil? and return text = node.to_s @sourcecode == "pre" and text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/> ") @sourcecode and text = text.gsub(/ (?= )/, " ") 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| children_parse(node, 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| children_parse(node, e) end end |
#xref_label_parse(node, out) ⇒ Object
83 |
# File 'lib/isodoc/function/inline_simple.rb', line 83 def xref_label_parse(node, out); end |
#xref_parse(node, out) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/isodoc/function/inline.rb', line 46 def xref_parse(node, out) target = if node["target"].include?("#") node["target"].sub("#", ".html#") else "##{node['target']}" end out.a(href: target) { |l| no_locality_parse(node, l) } end |