Module: IsoDoc::Function::Inline
- Included in:
- Common
- Defined in:
- lib/isodoc/function/inline.rb,
lib/isodoc/function/inline_simple.rb
Instance Method Summary collapse
- #bookmark_parse(node, out) ⇒ Object
- #br_parse(node, out) ⇒ Object
- #callout_parse(node, out) ⇒ Object
- #em_parse(node, out) ⇒ Object
- #eref_parse(node, out) ⇒ Object
- #eref_target(node) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #hr_parse(node, 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
- #link_parse(node, out) ⇒ Object
- #no_locality_parse(node, out) ⇒ Object
- #origin_parse(node, out) ⇒ Object
- #page_break(out) ⇒ Object
- #pagebreak_parse(_node, out) ⇒ Object
- #section_break(body) ⇒ Object
- #smallcap_parse(node, xml) ⇒ Object
- #stem_parse(node, out) ⇒ 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
- #termrefelem_parse(node, out) ⇒ Object
- #text_parse(node, out) ⇒ Object
- #tt_parse(node, out) ⇒ Object
- #underline_parse(node, out) ⇒ Object
- #xref_parse(node, out) ⇒ Object
Instance Method Details
#bookmark_parse(node, out) ⇒ Object
29 30 31 |
# File 'lib/isodoc/function/inline_simple.rb', line 29 def bookmark_parse(node, out) out.a **attr_code(id: node["id"]) end |
#br_parse(node, out) ⇒ Object
19 20 21 |
# File 'lib/isodoc/function/inline_simple.rb', line 19 def br_parse(node, out) out.br end |
#callout_parse(node, out) ⇒ Object
15 16 17 |
# File 'lib/isodoc/function/inline.rb', line 15 def callout_parse(node, out) out << " <#{node.text}>" end |
#em_parse(node, out) ⇒ Object
39 40 41 42 43 |
# File 'lib/isodoc/function/inline_simple.rb', line 39 def em_parse(node, out) out.i do |e| node.children.each { |n| parse(n, e) } end end |
#eref_parse(node, out) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/isodoc/function/inline.rb', line 47 def eref_parse(node, out) 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 end |
#eref_target(node) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/isodoc/function/inline.rb', line 36 def eref_target(node) href = "#" + node["bibitemid"] url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\ "uri[@type = 'citation']")) return href unless url href = suffix_url(url.text) anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip anchor and href += "##{anchor}" href end |
#error_parse(node, out) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/isodoc/function/inline.rb', line 115 def error_parse(node, out) text = node.to_xml.gsub(/</, "<").gsub(/>/, ">") out.para do |p| p.b(**{ role: "strong" }) { |e| e << text } end end |
#hr_parse(node, out) ⇒ Object
15 16 17 |
# File 'lib/isodoc/function/inline_simple.rb', line 15 def hr_parse(node, out) out.hr end |
#image_parse(node, out, caption) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/isodoc/function/inline.rb', line 91 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
83 84 85 86 87 88 89 |
# File 'lib/isodoc/function/inline.rb', line 83 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
23 24 |
# File 'lib/isodoc/function/inline_simple.rb', line 23 def index_parse(node, out) end |
#index_xref_parse(node, out) ⇒ Object
26 27 |
# File 'lib/isodoc/function/inline_simple.rb', line 26 def index_xref_parse(node, out) end |
#keyword_parse(node, out) ⇒ Object
33 34 35 36 37 |
# File 'lib/isodoc/function/inline_simple.rb', line 33 def keyword_parse(node, out) out.span **{ class: "keyword" } do |s| node.children.each { |n| parse(n, s) } end end |
#link_parse(node, out) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/isodoc/function/inline.rb', line 5 def link_parse(node, out) out.a **attr_code(href: node["target"], 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 |
#no_locality_parse(node, out) ⇒ Object
19 20 21 22 23 |
# File 'lib/isodoc/function/inline.rb', line 19 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
58 59 60 61 62 63 64 |
# File 'lib/isodoc/function/inline.rb', line 58 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
7 8 9 |
# File 'lib/isodoc/function/inline_simple.rb', line 7 def page_break(out) out.br end |
#pagebreak_parse(_node, out) ⇒ Object
11 12 13 |
# File 'lib/isodoc/function/inline_simple.rb', line 11 def pagebreak_parse(_node, out) out.br end |
#section_break(body) ⇒ Object
3 4 5 |
# File 'lib/isodoc/function/inline_simple.rb', line 3 def section_break(body) body.br end |
#smallcap_parse(node, xml) ⇒ Object
101 102 103 104 105 |
# File 'lib/isodoc/function/inline.rb', line 101 def smallcap_parse(node, xml) xml.span **{ style: "font-variant:small-caps;" } do |s| node.children.each { |n| parse(n, s) } end end |
#stem_parse(node, out) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/isodoc/function/inline.rb', line 70 def stem_parse(node, out) ooml = if node["type"] == "AsciiMath" "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\ "#{@closemathdelim}" elsif node["type"] == "MathML" then node.first_element_child.to_s 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
69 70 71 72 73 |
# File 'lib/isodoc/function/inline_simple.rb', line 69 def strike_parse(node, out) out.s do |e| node.children.each { |n| parse(n, e) } end end |
#strong_parse(node, out) ⇒ Object
45 46 47 48 49 |
# File 'lib/isodoc/function/inline_simple.rb', line 45 def strong_parse(node, out) out.b do |e| node.children.each { |n| parse(n, e) } end end |
#sub_parse(node, out) ⇒ Object
57 58 59 60 61 |
# File 'lib/isodoc/function/inline_simple.rb', line 57 def sub_parse(node, out) out.sub do |e| node.children.each { |n| parse(n, e) } end end |
#suffix_url(url) ⇒ Object
31 32 33 34 |
# File 'lib/isodoc/function/inline.rb', line 31 def suffix_url(url) return url if %r{^http[s]?://}.match(url) url.sub(/#{File.extname(url)}$/, ".html") end |
#sup_parse(node, out) ⇒ Object
51 52 53 54 55 |
# File 'lib/isodoc/function/inline_simple.rb', line 51 def sup_parse(node, out) out.sup do |e| node.children.each { |n| parse(n, e) } end end |
#termrefelem_parse(node, out) ⇒ Object
66 67 68 |
# File 'lib/isodoc/function/inline.rb', line 66 def termrefelem_parse(node, out) out << "Termbase #{node['base']}, term ID #{node['target']}" end |
#text_parse(node, out) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/isodoc/function/inline.rb', line 107 def text_parse(node, out) return if node.nil? || node.text.nil? text = node.to_s text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/> "). gsub(/[ ](?=[ ])/, " ") if in_sourcecode out << text end |
#tt_parse(node, out) ⇒ Object
63 64 65 66 67 |
# File 'lib/isodoc/function/inline_simple.rb', line 63 def tt_parse(node, out) out.tt do |e| node.children.each { |n| parse(n, e) } end end |
#underline_parse(node, out) ⇒ Object
75 76 77 78 79 |
# File 'lib/isodoc/function/inline_simple.rb', line 75 def underline_parse(node, out) out.u do |e| node.children.each { |n| parse(n, e) } end end |
#xref_parse(node, out) ⇒ Object
25 26 27 28 29 |
# File 'lib/isodoc/function/inline.rb', line 25 def xref_parse(node, out) target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".html#") : "##{node["target"]}" out.a(**{ "href": target }) { |l| no_locality_parse(node, l) } end |