Module: IsoDoc::Function::Inline
- Included in:
- Common
- Defined in:
- lib/isodoc/function/inline.rb
Instance Method Summary collapse
- #anchor_linkend(node, linkend) ⇒ Object
- #br_parse(node, out) ⇒ Object
- #callout_parse(node, out) ⇒ Object
- #concept_parse(node, out) ⇒ Object
- #eref_localities(refs, target) ⇒ Object
- #eref_parse(node, out) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #get_linkend(node) ⇒ Object
- #hr_parse(node, out) ⇒ Object
- #image_parse(node, out, caption) ⇒ Object
- #image_title_parse(out, caption) ⇒ Object
- #index_parse(node, out) ⇒ Object
- #link_parse(node, out) ⇒ Object
- #page_break(out) ⇒ Object
- #prefix_container(container, linkend, _target) ⇒ Object
- #section_break(body) ⇒ Object
- #stem_parse(node, out) ⇒ Object
- #termrefelem_parse(node, out) ⇒ Object
- #xref_parse(node, out) ⇒ Object
Instance Method Details
#anchor_linkend(node, linkend) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/isodoc/function/inline.rb', line 40 def anchor_linkend(node, linkend) if node["citeas"].nil? && node["bibitemid"] return anchor(node["bibitemid"] ,:xref) || "???" elsif node["target"] && !/.#./.match(node["target"]) linkend = anchor(node["target"], :xref) container = anchor(node["target"], :container, false) (container && get_note_container_id(node) != container && @anchors[node["target"]]) && linkend = prefix_container(container, linkend, node["target"]) end linkend || "???" end |
#br_parse(node, out) ⇒ Object
15 16 17 |
# File 'lib/isodoc/function/inline.rb', line 15 def br_parse(node, out) out.br end |
#callout_parse(node, out) ⇒ Object
32 33 34 |
# File 'lib/isodoc/function/inline.rb', line 32 def callout_parse(node, out) out << " <#{node.text}>" end |
#concept_parse(node, out) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/isodoc/function/inline.rb', line 97 def concept_parse(node, out) content = node.first_element_child.children.select { |c| c.name != "locality" }. select { |c| !c.text? || /\S/.match(c) } if content.empty? out << "[Term defined in " parse(node.first_element_child, out) out << "]" else content.each { |n| parse(n, out) } end end |
#eref_localities(refs, target) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/isodoc/function/inline.rb', line 70 def eref_localities(refs, target) ret = "" refs.each do |r| ret += if r["type"] == "whole" then l10n(", #{@whole_of_text}") else eref_localities1(target, r["type"], r.at(ns("./referenceFrom")), r.at(ns("./referenceTo")), @lang) end end ret end |
#eref_parse(node, out) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/isodoc/function/inline.rb', line 82 def eref_parse(node, out) linkend = get_linkend(node) if node["type"] == "footnote" out.sup do |s| s.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend } end else out.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend } end end |
#error_parse(node, out) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/isodoc/function/inline.rb', line 139 def error_parse(node, out) text = node.to_xml.gsub(/</, "<").gsub(/>/, ">") out.para do |p| p.b(**{ role: "strong" }) { |e| e << text } end end |
#get_linkend(node) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/isodoc/function/inline.rb', line 53 def get_linkend(node) link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"])) link += eref_localities(node.xpath(ns("./locality")), link) contents = node.children.select { |c| c.name != "locality" }. select { |c| !c.text? || /\S/.match(c) } return link if contents.nil? || contents.empty? Nokogiri::XML::NodeSet.new(node.document, contents).to_xml # so not <origin bibitemid="ISO7301" citeas="ISO 7301"> # <locality type="section"><reference>3.1</reference></locality></origin> end |
#hr_parse(node, out) ⇒ Object
11 12 13 |
# File 'lib/isodoc/function/inline.rb', line 11 def hr_parse(node, out) out.hr end |
#image_parse(node, out, caption) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/isodoc/function/inline.rb', line 129 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
121 122 123 124 125 126 127 |
# File 'lib/isodoc/function/inline.rb', line 121 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
19 20 |
# File 'lib/isodoc/function/inline.rb', line 19 def index_parse(node, out) end |
#link_parse(node, out) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/isodoc/function/inline.rb', line 22 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 |
#page_break(out) ⇒ Object
7 8 9 |
# File 'lib/isodoc/function/inline.rb', line 7 def page_break(out) out.br end |
#prefix_container(container, linkend, _target) ⇒ Object
36 37 38 |
# File 'lib/isodoc/function/inline.rb', line 36 def prefix_container(container, linkend, _target) l10n(anchor(container, :xref) + ", " + linkend) end |
#section_break(body) ⇒ Object
3 4 5 |
# File 'lib/isodoc/function/inline.rb', line 3 def section_break(body) body.br end |
#stem_parse(node, out) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/isodoc/function/inline.rb', line 109 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 |
#termrefelem_parse(node, out) ⇒ Object
93 94 95 |
# File 'lib/isodoc/function/inline.rb', line 93 def termrefelem_parse(node, out) out << "Termbase #{node['base']}, term ID #{node['target']}" end |
#xref_parse(node, out) ⇒ Object
64 65 66 67 68 |
# File 'lib/isodoc/function/inline.rb', line 64 def xref_parse(node, out) target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".html#") : "##{node["target"]}" out.a(**{ "href": target }) { |l| l << get_linkend(node) } end |