Module: IsoDoc::Function::Inline
- Included in:
- Common
- Defined in:
- lib/isodoc/function/inline.rb,
lib/isodoc/function/inline_simple.rb
Instance Method Summary collapse
- #anchor_linkend(node, linkend) ⇒ Object
- #bookmark_parse(node, out) ⇒ Object
- #br_parse(node, out) ⇒ Object
- #callout_parse(node, out) ⇒ Object
- #capitalise_xref(node, linkend) ⇒ Object
- #concept_parse(node, out) ⇒ Object
- #em_parse(node, out) ⇒ Object
- #eref_localities(refs, target) ⇒ Object
- #eref_localities0(r, i, target, delim) ⇒ Object
- #eref_parse(node, out) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #found_matching_variant_sibling(node) ⇒ 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
- #keyword_parse(node, out) ⇒ Object
- #link_parse(node, out) ⇒ Object
- #nearest_block_parent(node) ⇒ Object
- #origin_parse(node, out) ⇒ Object
- #page_break(out) ⇒ Object
- #pagebreak_parse(_node, out) ⇒ Object
- #prefix_container(container, linkend, _target) ⇒ 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
- #sup_parse(node, out) ⇒ Object
- #termrefelem_parse(node, out) ⇒ Object
- #text_parse(node, out) ⇒ Object
- #tt_parse(node, out) ⇒ Object
- #variant_parse(node, out) ⇒ Object
- #xref_parse(node, out) ⇒ Object
Instance Method Details
#anchor_linkend(node, linkend) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/isodoc/function/inline.rb', line 23 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"]) linkend = capitalise_xref(node, linkend) end linkend || "???" end |
#bookmark_parse(node, out) ⇒ Object
26 27 28 |
# File 'lib/isodoc/function/inline_simple.rb', line 26 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 |
#capitalise_xref(node, linkend) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/isodoc/function/inline.rb', line 37 def capitalise_xref(node, linkend) return linkend unless %w(Latn Cyrl Grek).include? @script return linkend&.capitalize if node["case"] == "capital" return linkend&.downcase if node["case"] == "lowercase" return linkend if linkend[0,1].match(/\p{Upper}/) prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") & node.xpath("./preceding::text()") (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ? linkend&.capitalize : linkend end |
#concept_parse(node, out) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/isodoc/function/inline.rb', line 123 def concept_parse(node, out) content = node.first_element_child.children.select do |c| !%w{locality localityStack}.include? c.name end.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 |
#em_parse(node, out) ⇒ Object
36 37 38 39 40 |
# File 'lib/isodoc/function/inline_simple.rb', line 36 def em_parse(node, out) out.i do |e| node.children.each { |n| parse(n, e) } end end |
#eref_localities(refs, target) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/isodoc/function/inline.rb', line 75 def eref_localities(refs, target) ret = "" refs.each_with_index do |r, i| delim = "," delim = ";" if r.name == "localityStack" && i>0 if r.name == "localityStack" r.elements.each_with_index do |rr, j| ret += eref_localities0(rr, j, target, delim) delim = "," end else ret += eref_localities0(r, i, target, delim) end end ret end |
#eref_localities0(r, i, target, delim) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/isodoc/function/inline.rb', line 92 def eref_localities0(r, i, target, delim) if r["type"] == "whole" then l10n("#{delim} #{@whole_of_text}") else eref_localities1(target, r["type"], r.at(ns("./referenceFrom")), r.at(ns("./referenceTo")), delim, @lang) end end |
#eref_parse(node, out) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/isodoc/function/inline.rb', line 100 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
181 182 183 184 185 186 |
# File 'lib/isodoc/function/inline.rb', line 181 def error_parse(node, out) text = node.to_xml.gsub(/</, "<").gsub(/>/, ">") out.para do |p| p.b(**{ role: "strong" }) { |e| e << text } end end |
#found_matching_variant_sibling(node) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/isodoc/function/inline.rb', line 198 def found_matching_variant_sibling(node) prev = node.xpath("./preceding-sibling::xmlns:variant") foll = node.xpath("./following-sibling::xmlns:variant") found = false (prev + foll).each do |n| found = true if n["lang"] == @lang && n["script"] == @script end found end |
#get_linkend(node) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/isodoc/function/inline.rb', line 56 def get_linkend(node) contents = node.children.select do |c| !%w{locality localityStack}.include? c.name end.select { |c| !c.text? || /\S/.match(c) } !contents.empty? and return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"])) link + eref_localities(node.xpath(ns("./locality | ./localityStack")), link) # so not <origin bibitemid="ISO7301" citeas="ISO 7301"> # <locality type="section"><reference>3.1</reference></locality></origin> 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
157 158 159 160 161 162 163 164 165 |
# File 'lib/isodoc/function/inline.rb', line 157 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
149 150 151 152 153 154 155 |
# File 'lib/isodoc/function/inline.rb', line 149 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 |
#keyword_parse(node, out) ⇒ Object
30 31 32 33 34 |
# File 'lib/isodoc/function/inline_simple.rb', line 30 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 |
#nearest_block_parent(node) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/isodoc/function/inline.rb', line 48 def nearest_block_parent(node) until %w(p title td th name formula li dt dd sourcecode pre).include?(node.name) node = node.parent end node end |
#origin_parse(node, out) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/isodoc/function/inline.rb', line 111 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 |
#prefix_container(container, linkend, _target) ⇒ Object
19 20 21 |
# File 'lib/isodoc/function/inline.rb', line 19 def prefix_container(container, linkend, _target) l10n(anchor(container, :xref) + ", " + linkend) 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
167 168 169 170 171 |
# File 'lib/isodoc/function/inline.rb', line 167 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
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/isodoc/function/inline.rb', line 136 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
66 67 68 69 70 |
# File 'lib/isodoc/function/inline_simple.rb', line 66 def strike_parse(node, out) out.s do |e| node.children.each { |n| parse(n, e) } end end |
#strong_parse(node, out) ⇒ Object
42 43 44 45 46 |
# File 'lib/isodoc/function/inline_simple.rb', line 42 def strong_parse(node, out) out.b do |e| node.children.each { |n| parse(n, e) } end end |
#sub_parse(node, out) ⇒ Object
54 55 56 57 58 |
# File 'lib/isodoc/function/inline_simple.rb', line 54 def sub_parse(node, out) out.sub do |e| node.children.each { |n| parse(n, e) } end end |
#sup_parse(node, out) ⇒ Object
48 49 50 51 52 |
# File 'lib/isodoc/function/inline_simple.rb', line 48 def sup_parse(node, out) out.sup do |e| node.children.each { |n| parse(n, e) } end end |
#termrefelem_parse(node, out) ⇒ Object
119 120 121 |
# File 'lib/isodoc/function/inline.rb', line 119 def termrefelem_parse(node, out) out << "Termbase #{node['base']}, term ID #{node['target']}" end |
#text_parse(node, out) ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/isodoc/function/inline.rb', line 173 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
60 61 62 63 64 |
# File 'lib/isodoc/function/inline_simple.rb', line 60 def tt_parse(node, out) out.tt do |e| node.children.each { |n| parse(n, e) } end end |
#variant_parse(node, out) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/isodoc/function/inline.rb', line 188 def variant_parse(node, out) if node["lang"] == @lang && node["script"] == @script node.children.each { |n| parse(n, out) } else return if found_matching_variant_sibling(node) return unless !node.at("./preceding-sibling::xmlns:variant") node.children.each { |n| parse(n, out) } end end |
#xref_parse(node, out) ⇒ Object
69 70 71 72 73 |
# File 'lib/isodoc/function/inline.rb', line 69 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 |