Class: IsoDoc::Ietf::RfcConvert
- Inherits:
-
Convert
- Object
- Convert
- IsoDoc::Ietf::RfcConvert
- Defined in:
- lib/isodoc/ietf/footnotes.rb,
lib/isodoc/ietf/references.rb,
lib/isodoc/ietf/rfc_convert.rb,
lib/isodoc/ietf/section.rb,
lib/isodoc/ietf/cleanup.rb,
lib/isodoc/ietf/inline.rb,
lib/isodoc/ietf/blocks.rb,
lib/isodoc/ietf/terms.rb,
lib/isodoc/ietf/table.rb,
lib/isodoc/ietf/front.rb,
lib/isodoc/ietf/reqt.rb
Constant Summary collapse
- OL_STYLE =
{ arabic: "1", roman: "i", alphabet: "a", roman_upper: "I", alphabet_upper: "A", }.freeze
Instance Method Summary collapse
- #abstract(isoxml, front) ⇒ Object
- #address(addr, phone, fax, email, uri, out) ⇒ Object
- #admitted_term_parse(node, out) ⇒ Object
- #admonition_name_parse(_node, div, name) ⇒ Object
- #admonition_parse(node, out) ⇒ Object
- #annex(isoxml, out) ⇒ Object
- #annotation_cleanup(docxml) ⇒ Object
- #annotation_parse(node, out) ⇒ Object
- #area(isoxml, front) ⇒ Object
- #aside_cleanup(docxml) ⇒ Object
- #author(isoxml, front) ⇒ Object
- #bcp14_parse(node, out) ⇒ Object
- #biblio_list(f, div, biblio) ⇒ Object
-
#bibliography(isoxml, out) ⇒ Object
TODO displayreference will be implemented as combination of autofetch and user-provided citations.
- #boilerplate(isoxml, front) ⇒ Object
- #bookmark_cleanup(docxml) ⇒ Object
- #bookmark_parse(node, out) ⇒ Object
- #br_parse(node, out) ⇒ Object
- #clause(isoxml, out) ⇒ Object
- #clause1(c, out) ⇒ Object
- #clause_parse(node, out) ⇒ Object
- #clause_parse_title(node, div, c1, out) ⇒ Object
- #cleanup(docxml) ⇒ Object
- #common_rfc_pis(node) ⇒ Object
- #convert1(docxml, filename, dir) ⇒ Object
- #date(isoxml, front) ⇒ Object
- #date_attr(date) ⇒ Object
- #dd_cleanup(docxml) ⇒ Object
- #definition_parse(node, out) ⇒ Object
- #deflist_cleanup(docxml) ⇒ Object
- #deprecated_term_parse(node, out) ⇒ Object
- #dl_attrs(node) ⇒ Object
- #dt_cleanup(docxml) ⇒ Object
- #dt_parse(dt, term) ⇒ Object
- #em_parse(node, out) ⇒ Object
- #email(email, out) ⇒ Object
- #eref_clause(refs, target) ⇒ Object
- #eref_clause1(refs, target) ⇒ Object
- #eref_parse(node, out) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #example_label(node, div, name) ⇒ Object
- #example_parse(node, out) ⇒ Object
- #extract_delims(text) ⇒ Object
- #figure_cleanup(docxml) ⇒ Object
- #figure_footnote_cleanup(docxml) ⇒ Object
- #figure_name_parse(node, div, name) ⇒ Object
- #figure_parse(node, out) ⇒ Object
- #figure_postamble(docxml) ⇒ Object
- #figure_unnest(docxml) ⇒ Object
- #figure_wrap_artwork(docxml) ⇒ Object
- #footnote_cleanup(docxml) ⇒ Object
- #footnote_parse(node, out) ⇒ Object
- #footnote_refs_cleanup(docxml) ⇒ Object
- #formula_parse(node, out) ⇒ Object
- #formula_parse1(node, out) ⇒ Object
- #formula_where(dl, out) ⇒ Object
-
#front_cleanup(xmldoc) ⇒ Object
TODO: insert <u>.
- #get_linkend(node) ⇒ Object
- #get_table_ancestor_id(node) ⇒ Object
- #hr_parse(node, out) ⇒ Object
- #id_seriesinfo(isoxml, front) ⇒ Object
- #ietf_bibitem_entry(div, b, i) ⇒ Object
- #image_cleanup(docxml) ⇒ Object
- #image_parse(node, out, caption) ⇒ Object
- #image_title_parse(out, caption) ⇒ Object
- #index_parse(node, out) ⇒ Object
- #info(isoxml, out) ⇒ Object
- #init_file(filename, debug) ⇒ Object
-
#initialize(options) ⇒ RfcConvert
constructor
A new instance of RfcConvert.
- #inline?(node) ⇒ Boolean
- #is_ietf(b) ⇒ Object
- #keyword(isoxml, front) ⇒ Object
- #keyword_parse(node, out) ⇒ Object
- #link_parse(node, out) ⇒ Object
- #make_back(out, isoxml) ⇒ Object
- #make_endnotes(docxml) ⇒ Object
- #make_front(out, isoxml) ⇒ Object
- #make_generic_footnote_text(node, fnref) ⇒ Object
- #make_link(out, isoxml) ⇒ Object
- #make_local_footnote(node, fn, out) ⇒ Object
- #make_middle(out, isoxml) ⇒ Object
- #make_postamble(docxml) ⇒ Object
- #make_table_footnote_link(out, fnid, fnref) ⇒ Object
- #make_table_footnote_text(node, fnid, fnref) ⇒ Object
- #make_tr_attr(td, row, totalrows, header) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #modification_parse(node, out) ⇒ Object
- #move_postamble(docxml) ⇒ Object
- #move_preamble(docxml) ⇒ Object
- #nonstd_bibitem(list, b, ordinal, bibliography) ⇒ Object
- #note(isoxml, front) ⇒ Object
- #note_label(node) ⇒ Object
- #note_parse(node, out) ⇒ Object
- #ol_attrs(node) ⇒ Object
- #ol_parse(node, out) ⇒ Object
- #ol_style(type) ⇒ Object
- #org_author(c, role, front) ⇒ Object
- #organization(org, out, show) ⇒ Object
- #page_break(_out) ⇒ Object
- #pagebreak_parse(_node, _out) ⇒ Object
- #para_attrs(node) ⇒ Object
- #para_parse(node, out) ⇒ Object
- #permission_parse(node, out) ⇒ Object
- #pers_author_attrs1(ret, full, init, c) ⇒ Object
- #person_author(c, role, front) ⇒ Object
- #person_author_attrs(c, role) ⇒ Object
- #postal(addr, out) ⇒ Object
- #postal_detailed(addr, out) ⇒ Object
- #postprocess(result, filename, dir) ⇒ Object
- #pre_parse(node, out) ⇒ Object
- #pseudocode_parse(node, out) ⇒ Object
- #quote_attribution(node) ⇒ Object
- #quote_parse(node, out) ⇒ Object
- #recommendation_attributes(node, out) ⇒ Object
- #recommendation_name(node, out, type) ⇒ Object
- #recommendation_parse(node, out) ⇒ Object
- #rel2iana(type) ⇒ Object
- #relaton_org_to_author(o, role, f) ⇒ Object
- #relaton_person_to_author(p, role, f) ⇒ Object
- #relaton_to_abstract(b, f) ⇒ Object
- #relaton_to_author(b, f) ⇒ Object
- #relaton_to_date(b, f) ⇒ Object
- #relaton_to_keyword(b, f) ⇒ Object
- #relaton_to_title(b, f) ⇒ Object
- #requirement_component_parse(node, out) ⇒ Object
- #requirement_parse(node, out) ⇒ Object
- #review_note_parse(node, out) ⇒ Object
- #rfc_attributes(docxml) ⇒ Object
- #rfc_seriesinfo(isoxml, front) ⇒ Object
- #series2category(series) ⇒ Object
- #seriesinfo(isoxml, front) ⇒ Object
- #seriesinfo_attr(isoxml) ⇒ Object
- #set_pis(node, doc) ⇒ Object
- #smallcap_parse(node, out) ⇒ Object
-
#sourcecode_cleanup(docxml) ⇒ Object
for markup in pseudocode.
- #sourcecode_parse(node, out) ⇒ Object
- #sourcecode_remove_markup(s) ⇒ 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
- #table_attrs(node) ⇒ Object
- #table_cleanup(docxml) ⇒ Object
- #table_footnote_cleanup(docxml) ⇒ Object
- #table_footnote_parse(node, out) ⇒ Object
- #table_parse(node, out) ⇒ Object
- #table_title_parse(node, out) ⇒ Object
- #term_parse(node, out) ⇒ Object
- #termdef_parse(node, out) ⇒ Object
- #termdocsource_parse(_node, _out) ⇒ Object
- #termnote_anchor_names(docxml) ⇒ Object
- #termnote_parse(node, out) ⇒ Object
- #termref_parse(node, out) ⇒ Object
- #text_parse(node, out) ⇒ Object
- #textcleanup(docxml) ⇒ Object
- #title(isoxml, front) ⇒ Object
- #tr_parse(node, out, ord, totalrows, header) ⇒ Object
- #tt_parse(node, out) ⇒ Object
-
#ul_attrs(node) ⇒ Object
NOTE ignoring “bare” attribute, which is tantamount to “empty”.
- #ul_parse(node, out) ⇒ Object
- #workgroup(isoxml, front) ⇒ Object
- #xpath_comma(xpath) ⇒ Object
- #xref_parse(node, out) ⇒ Object
Constructor Details
#initialize(options) ⇒ RfcConvert
Returns a new instance of RfcConvert.
70 71 72 73 74 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 70 def initialize() super @xinclude = [:use_xinclude] == "true" @format = :rfc end |
Instance Method Details
#abstract(isoxml, front) ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/isodoc/ietf/front.rb', line 206 def abstract(isoxml, front) a = isoxml.at(ns("//preface/abstract | //preface/foreword")) || return front.abstract **attr_code(anchor: a["id"]) do |abs| a.children.reject { |c1| %w(title note).include? c1.name }.each do |c1| parse(c1, abs) end end end |
#address(addr, phone, fax, email, uri, out) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/ietf/front.rb', line 121 def address(addr, phone, fax, email, uri, out) return unless addr || phone || fax || email || uri out.address do |a| addr and postal(addr, a) phone and a.phone phone.text fax and a.facsimile fax.text email and email(email, a) uri and a.uri uri.text end end |
#admitted_term_parse(node, out) ⇒ Object
21 22 23 24 25 |
# File 'lib/isodoc/ietf/terms.rb', line 21 def admitted_term_parse(node, out) out.t do |p| node.children.each { |c| parse(c, p) } end end |
#admonition_name_parse(_node, div, name) ⇒ Object
176 177 178 179 180 |
# File 'lib/isodoc/ietf/blocks.rb', line 176 def admonition_name_parse(_node, div, name) div.t **{keepWithNext: "true" } do |p| name.children.each { |n| parse(n, p) } end end |
#admonition_parse(node, out) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/isodoc/ietf/blocks.rb', line 182 def admonition_parse(node, out) type = node["type"] name = admonition_name(node, type) out.aside **{ anchor: node["id"] } do |t| admonition_name_parse(node, t, name) if name node.children.each { |n| parse(n, t) unless n.name == "name" } end end |
#annex(isoxml, out) ⇒ Object
169 170 171 172 173 |
# File 'lib/isodoc/ietf/section.rb', line 169 def annex(isoxml, out) isoxml.xpath(ns("//annex")).each do |c| clause1(c, out) end end |
#annotation_cleanup(docxml) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/isodoc/ietf/cleanup.rb', line 176 def annotation_cleanup(docxml) docxml.xpath("//reference").each do |r| next unless r&.next_element&.name == "aside" aside = r.next_element aside.name = "annotation" aside.traverse do |n| n.name == "t" and n.replace(n.children) end r << aside end docxml.xpath("//references/aside").each { |r| r.remove } end |
#annotation_parse(node, out) ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/isodoc/ietf/blocks.rb', line 127 def annotation_parse(node, out) @sourcecode = false @annotation = true node.at("./preceding-sibling::*[local-name() = 'annotation']") or out << "\n\n" callout = node.at(ns("//callout[@target='#{node['id']}']")) out << "\n<#{callout.text}> " out << node&.children&.text&.strip @annotation = false end |
#area(isoxml, front) ⇒ Object
188 189 190 191 192 |
# File 'lib/isodoc/ietf/front.rb', line 188 def area(isoxml, front) @meta.get[:areas].each do |w| front.area w end end |
#aside_cleanup(docxml) ⇒ Object
218 219 220 221 222 223 224 225 226 227 |
# File 'lib/isodoc/ietf/cleanup.rb', line 218 def aside_cleanup(docxml) docxml.xpath("//t[descendant::aside] | //table[descendant::aside] | "\ "//figure[descendant::aside]").each do |p| insert = p p.xpath(".//aside").each do |a| insert.next = a.remove insert = insert.next_element end end end |
#author(isoxml, front) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/isodoc/ietf/front.rb', line 63 def (isoxml, front) isoxml.xpath(("//xmlns:bibdata/xmlns:contributor[xmlns:role/@type = "\ "'author' or xmlns:role/@type = 'editor']")).each do |c| role = c.at(ns("./role/@type")).text == "editor" ? "editor" : nil c.at("./organization") and (c, role, front) or (c, role, front) end end |
#bcp14_parse(node, out) ⇒ Object
35 36 37 38 39 |
# File 'lib/isodoc/ietf/inline.rb', line 35 def bcp14_parse(node, out) out.bcp14 do |e| node.children.each { |n| parse(n, e) } end end |
#biblio_list(f, div, biblio) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/isodoc/ietf/references.rb', line 19 def biblio_list(f, div, biblio) i = 0 f.xpath(ns("./bibitem | ./note")).each do |b| next if implicit_reference(b) i += 1 if b.name == "bibitem" if b.name == "note" then note_parse(b, div) elsif(is_ietf(b)) then ietf_bibitem_entry(div, b, i) else nonstd_bibitem(div, b, i, biblio) end end end |
#bibliography(isoxml, out) ⇒ Object
TODO displayreference will be implemented as combination of autofetch and user-provided citations
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/isodoc/ietf/references.rb', line 5 def bibliography(isoxml, out) isoxml.xpath(ns("//references")).each do |f| out.references **attr_code(anchor: f["id"]) do |div| title = f.at(ns("./title")) and div.name do |name| title.children.each { |n| parse(n, name) } end f.elements.reject do |e| %w(reference title bibitem note).include? e.name end.each { |e| parse(e, div) } biblio_list(f, div, true) end end end |
#boilerplate(isoxml, front) ⇒ Object
228 229 |
# File 'lib/isodoc/ietf/front.rb', line 228 def boilerplate(isoxml, front) end |
#bookmark_cleanup(docxml) ⇒ Object
212 213 214 215 216 |
# File 'lib/isodoc/ietf/cleanup.rb', line 212 def bookmark_cleanup(docxml) docxml.xpath("//bookmark").each do |b| b.remove end end |
#bookmark_parse(node, out) ⇒ Object
163 164 165 |
# File 'lib/isodoc/ietf/inline.rb', line 163 def bookmark_parse(node, out) out.bookmark nil, **attr_code(anchor: node["id"]) end |
#br_parse(node, out) ⇒ Object
74 75 76 77 78 |
# File 'lib/isodoc/ietf/inline.rb', line 74 def br_parse(node, out) if @sourcecode out.br end end |
#clause(isoxml, out) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/isodoc/ietf/section.rb', line 152 def clause(isoxml, out) isoxml.xpath("//xmlns:preface/child::*[not(name() = 'abstract' or name() = 'foreword')] "\ "| //xmlns:sections/child::*").each do |c| clause1(c, out) end end |
#clause1(c, out) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/isodoc/ietf/section.rb', line 159 def clause1(c, out) out.section **attr_code( anchor: c["id"], numbered: c["numbered"], removeInRFC: c["removeInRFC"], toc: c["toc"]) do |div| clause_parse_title(c, div, c.at(ns("./title")), out) c.elements.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, div) end end end |
#clause_parse(node, out) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/isodoc/ietf/section.rb', line 142 def clause_parse(node, out) out.section **attr_code( anchor: node["id"], numbered: node["numbered"], removeInRFC: node["removeInRFC"], toc: node["toc"]) do |div| clause_parse_title(node, div, node.at(ns("./title")), out) node.children.reject { |c1| c1.name == "title" }.each do |c1| parse(c1, div) end end end |
#clause_parse_title(node, div, c1, out) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/isodoc/ietf/section.rb', line 135 def clause_parse_title(node, div, c1, out) return unless c1 div.name do |n| c1&.children&.each { |c2| parse(c2, n) } end end |
#cleanup(docxml) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/isodoc/ietf/cleanup.rb', line 3 def cleanup(docxml) image_cleanup(docxml) figure_cleanup(docxml) table_cleanup(docxml) footnote_cleanup(docxml) sourcecode_cleanup(docxml) annotation_cleanup(docxml) deflist_cleanup(docxml) bookmark_cleanup(docxml) aside_cleanup(docxml) front_cleanup(docxml) docxml end |
#common_rfc_pis(node) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/isodoc/ietf/section.rb', line 3 def common_rfc_pis(node) rfc_pis = { artworkdelimiter: node&.at(ns("//pi/artworkdelimiter"))&.text, artworklines: node&.at(ns("//pi/artworklines"))&.text, authorship: node&.at(ns("//pi/authorship"))&.text, autobreaks: node&.at(ns("//pi/autobreaks"))&.text, background: node&.at(ns("//pi/background"))&.text, colonspace: node&.at(ns("//pi/colonspace"))&.text, comments: node&.at(ns("//pi/comments"))&.text, docmapping: node&.at(ns("//pi/docmapping"))&.text, editing: node&.at(ns("//pi/editing"))&.text, emoticonic: node&.at(ns("//pi/emoticonic"))&.text, footer: node&.at(ns("//pi/footer"))&.text, header: node&.at(ns("//pi/header"))&.text, inline: node&.at(ns("//pi/inline"))&.text, iprnotified: node&.at(ns("//pi/iprnotified"))&.text, linkmailto: node&.at(ns("//pi/linkmailto"))&.text, linefile: node&.at(ns("//pi/linefile"))&.text, notedraftinprogress: node&.at(ns("//pi/notedraftinprogress"))&.text, private: node&.at(ns("//pi/private"))&.text, refparent: node&.at(ns("//pi/refparent"))&.text, rfcedstyle: node&.at(ns("//pi/rfcedstyle"))&.text, slides: node&.at(ns("//pi/slides"))&.text, "text-list-symbols": node&.at(ns("//pi/text-list-symbols"))&.text, tocappendix: node&.at(ns("//pi/tocappendix"))&.text, tocindent: node&.at(ns("//pi/tocindent"))&.text, tocnarrow: node&.at(ns("//pi/tocnarrow"))&.text, tocompact: node&.at(ns("//pi/tocompact"))&.text, topblock: node&.at(ns("//pi/topblock"))&.text, useobject: node&.at(ns("//pi/useobject"))&.text, strict: node&.at(ns("//pi/strict"))&.text || "yes", compact: node&.at(ns("//pi/compact"))&.text || "yes", subcompact: node&.at(ns("//pi/subcompact"))&.text || "no", toc: node&.at(ns("//pi/toc-include"))&.text, tocdepth: node&.at(ns("//pi/toc-depth"))&.text || "4", symrefs: node&.at(ns("//pi/sym-refs"))&.text || "yes", sortrefs: node&.at(ns("//pi/sort-refs"))&.text || "yes", } attr_code(rfc_pis) end |
#convert1(docxml, filename, dir) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 15 def convert1(docxml, filename, dir) anchor_names docxml info docxml, nil xml = noko do |xml| xml.rfc **attr_code(rfc_attributes(docxml)) do |html| make_link(html, docxml) make_front(html, docxml) make_middle(html, docxml) make_back(html, docxml) end end.join("\n").sub(/<!DOCTYPE[^>]+>\n/, "") set_pis(docxml, Nokogiri::XML(xml)) end |
#date(isoxml, front) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/isodoc/ietf/front.rb', line 164 def date(isoxml, front) date = @meta.get[:publisheddate] || @meta.get[:circulateddate] || return date.gsub!(/T.*$/, "") attr = date_attr(date) || return front.date **attr_code(attr) end |
#date_attr(date) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/isodoc/ietf/front.rb', line 171 def date_attr(date) return nil if date.nil? if date.length == 4 && date =~ /^\d\d\d\d$/ then { year: date } elsif date =~ /^\d\d\d\d-?\d\d$/ m = /^(?<year>\d\d\d\d)-(?<month>\d\d)$/.match date { month: Date::MONTHNAMES[(m[:month]).to_i], year: m[:year] } else begin d = Date.iso8601 date { day: d.day.to_s.gsub(/^0/, ""), year: d.year, month: Date::MONTHNAMES[d.month] } rescue nil end end end |
#dd_cleanup(docxml) ⇒ Object
205 206 207 208 209 210 |
# File 'lib/isodoc/ietf/cleanup.rb', line 205 def dd_cleanup(docxml) docxml.xpath("//dd").each do |d| d&.first_element_child&.name == "bookmark" and d["anchor"] ||= d.first_element_child["anchor"] end end |
#definition_parse(node, out) ⇒ Object
4 5 6 |
# File 'lib/isodoc/ietf/terms.rb', line 4 def definition_parse(node, out) node.children.each { |n| parse(n, out) } end |
#deflist_cleanup(docxml) ⇒ Object
189 190 191 192 |
# File 'lib/isodoc/ietf/cleanup.rb', line 189 def deflist_cleanup(docxml) dt_cleanup(docxml) dd_cleanup(docxml) end |
#deprecated_term_parse(node, out) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/isodoc/ietf/terms.rb', line 14 def deprecated_term_parse(node, out) out.t do |p| p << l10n("#{@deprecated_lbl}: ") node.children.each { |c| parse(c, p) } end end |
#dl_attrs(node) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/isodoc/ietf/blocks.rb', line 59 def dl_attrs(node) attr_code(anchor: node["id"], newline: node["newline"], indent: node["indent"], spacing: node["spacing"]) end |
#dt_cleanup(docxml) ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/isodoc/ietf/cleanup.rb', line 194 def dt_cleanup(docxml) docxml.xpath("//dt").each do |d| d&.first_element_child&.name == "bookmark" and d["anchor"] ||= d.first_element_child["anchor"] d.xpath(".//t").each do |t| d["anchor"] ||= t["anchor"] t.replace(t.children) end end end |
#dt_parse(dt, term) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/isodoc/ietf/blocks.rb', line 66 def dt_parse(dt, term) if dt.elements.empty? term << dt.text else dt.children.each { |n| parse(n, term) } end end |
#em_parse(node, out) ⇒ Object
5 6 7 8 9 |
# File 'lib/isodoc/ietf/inline.rb', line 5 def em_parse(node, out) out.em do |e| node.children.each { |n| parse(n, e) } end end |
#email(email, out) ⇒ Object
158 159 160 161 162 |
# File 'lib/isodoc/ietf/front.rb', line 158 def email(email, out) ascii = email.text.transliterate out.email email.text, **attr_code(ascii: ascii == email.text ? nil : ascii ) end |
#eref_clause(refs, target) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/isodoc/ietf/inline.rb', line 134 def eref_clause(refs, target) ret = [] ret1 = "" refs.each do |l| if l.name == "localityStack" ret << ret1 ret1 = "" ret << eref_clause1(l.elements, target) else ret1 += eref_clause1([l], target) end end ret << ret1 ret.reject { |c| c.nil? || c.empty? }.join("; ") end |
#eref_clause1(refs, target) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/isodoc/ietf/inline.rb', line 150 def eref_clause1(refs, target) refs.each do |l| next unless %w(clause section).include? l["type"] return l&.at(ns("./referenceFrom"))&.text end return "" end |
#eref_parse(node, out) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/isodoc/ietf/inline.rb', line 121 def eref_parse(node, out) linkend = node.children.reject { |c| %w{locality localityStack}.include? c.name } relative = node["relative"] || node.at(ns(".//locality[@type = 'anchor']/referenceFrom"))&.text || "" section = eref_clause(node.xpath(ns("./locality | ./localityStack")), nil) || "" section = "" if relative.empty? out.relref **attr_code(target: node["bibitemid"], section: section, relative: relative, displayFormat: node["displayFormat"]) do |l| linkend.each { |n| parse(n, l) } end end |
#error_parse(node, out) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 44 def error_parse(node, out) case node.name when "bcp14" then bcp14_parse(node, out) else text = node.to_xml.gsub(/</, "<").gsub(/>/, ">") out.t { |p| p << text } end end |
#example_label(node, div, name) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/isodoc/ietf/blocks.rb', line 96 def example_label(node, div, name) n = get_anchors[node["id"]] div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p| lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl : l10n("#{@example_lbl} #{n[:label]}") p << lbl name and !lbl.nil? and p << ": " name and name.children.each { |n| parse(n, p) } end end |
#example_parse(node, out) ⇒ Object
91 92 93 94 |
# File 'lib/isodoc/ietf/blocks.rb', line 91 def example_parse(node, out) example_label(node, out, node.at(ns("./name"))) node.elements.each { |n| parse(n, out) unless n.name == "name" } end |
#extract_delims(text) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 33 def extract_delims(text) @openmathdelim = "$$" @closemathdelim = "$$" while %r{#{Regexp.escape(@openmathdelim)}}m.match(text) || %r{#{Regexp.escape(@closemathdelim)}}m.match(text) @openmathdelim += "$" @closemathdelim += "$" end [@openmathdelim, @closemathdelim] end |
#figure_cleanup(docxml) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/isodoc/ietf/cleanup.rb', line 47 def figure_cleanup(docxml) figure_postamble(docxml) figure_wrap_artwork(docxml) figure_unnest(docxml) figure_footnote_cleanup(docxml) end |
#figure_footnote_cleanup(docxml) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/isodoc/ietf/cleanup.rb', line 35 def figure_footnote_cleanup(docxml) docxml.xpath("//figure[descendant::fn]").each do |t| t.xpath(".//fn").each do |a| t << "<aside>#{a.remove.children}</aside>" end end end |
#figure_name_parse(node, div, name) ⇒ Object
201 202 203 204 205 206 |
# File 'lib/isodoc/ietf/blocks.rb', line 201 def figure_name_parse(node, div, name) return if name.nil? div.name do |n| name.children.each { |n| parse(n, div) } end end |
#figure_parse(node, out) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/isodoc/ietf/blocks.rb', line 212 def figure_parse(node, out) return pseudocode_parse(node, out) if node["class"] == "pseudocode" || node["type"] == "pseudocode" @in_figure = true out.figure **attr_code(anchor: node["id"]) do |div| figure_name_parse(node, div, node.at(ns("./name"))) node.children.each do |n| parse(n, div) unless n.name == "name" end end @in_figure = false end |
#figure_postamble(docxml) ⇒ Object
71 72 73 74 75 |
# File 'lib/isodoc/ietf/cleanup.rb', line 71 def figure_postamble(docxml) make_postamble(docxml) move_postamble(docxml) move_preamble(docxml) end |
#figure_unnest(docxml) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/isodoc/ietf/cleanup.rb', line 61 def figure_unnest(docxml) docxml.xpath("//figure[descendant::figure]").each do |f| insert = f f.xpath(".//figure").each do |a| insert.next = a.remove insert = insert.next_element end end end |
#figure_wrap_artwork(docxml) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/isodoc/ietf/cleanup.rb', line 54 def figure_wrap_artwork(docxml) docxml.xpath("//artwork[not(parent::figure)] | "\ "//sourcecode[not(parent::figure)]").each do |a| a.wrap("<figure></figure>") end end |
#footnote_cleanup(docxml) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/isodoc/ietf/cleanup.rb', line 110 def footnote_cleanup(docxml) fn = footnote_refs_cleanup(docxml) endnotes = make_endnotes(docxml) docxml.xpath("//section[descendant::fn] | "\ "//abstract[descendant::fn]").each do |s| s.xpath(".//fn").each do |f| ref = f.at(".//ref") and ref.replace("[#{fn[ref.text]}] ") endnotes << f.remove.children end end end |
#footnote_parse(node, out) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/isodoc/ietf/footnotes.rb', line 3 def footnote_parse(node, out) return table_footnote_parse(node, out) if @in_table || @in_figure fn = node["reference"] out.fnref fn make_local_footnote(node, fn, out) end |
#footnote_refs_cleanup(docxml) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/isodoc/ietf/cleanup.rb', line 122 def footnote_refs_cleanup(docxml) i = 0 fn = {} docxml.xpath("//fnref").each do |f| unless fn[f.text] i = i + 1 fn[f.text] = i.to_s end f.replace(" [#{fn[f.text]}]") end fn end |
#formula_parse(node, out) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/isodoc/ietf/blocks.rb', line 153 def formula_parse(node, out) formula_parse1(node, out) formula_where(node.at(ns("./dl")), out) node.children.each do |n| next if %w(stem dl).include? n.name parse(n, out) end end |
#formula_parse1(node, out) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/isodoc/ietf/blocks.rb', line 144 def formula_parse1(node, out) out.t **attr_code(anchor: node["id"]) do |p| parse(node.at(ns("./stem")), p) lbl = anchor(node['id'], :label, false) lbl.nil? or p << " (#{lbl})" end end |
#formula_where(dl, out) ⇒ Object
138 139 140 141 142 |
# File 'lib/isodoc/ietf/blocks.rb', line 138 def formula_where(dl, out) return unless dl out.t { |p| p << @where_lbl } parse(dl, out) end |
#front_cleanup(xmldoc) ⇒ Object
TODO: insert <u>
19 20 21 22 23 24 25 |
# File 'lib/isodoc/ietf/cleanup.rb', line 19 def front_cleanup(xmldoc) xmldoc.xpath("//title").each { |s| s.children = s.text } xmldoc.xpath("//reference/front[not(author)]").each do |f| insert = f.at("./seriesInfo[last()]") || f.at("./title") insert.next = "<author surname='Unknown'/>" end end |
#get_linkend(node) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/isodoc/ietf/inline.rb', line 113 def get_linkend(node) contents = node.children.select { |c| !%w{locality localityStack}.include? c.name }. select { |c| !c.text? || /\S/.match(c) } !contents.empty? and return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml "" end |
#get_table_ancestor_id(node) ⇒ Object
64 65 66 67 68 |
# File 'lib/isodoc/ietf/footnotes.rb', line 64 def get_table_ancestor_id(node) table = node.ancestors("table") || node.ancestors("figure") return UUIDTools::UUID.random_create.to_s if table.empty? table.last["id"] end |
#hr_parse(node, out) ⇒ Object
80 81 |
# File 'lib/isodoc/ietf/inline.rb', line 80 def hr_parse(node, out) end |
#id_seriesinfo(isoxml, front) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/isodoc/ietf/front.rb', line 55 def id_seriesinfo(isoxml, front) front.seriesInfo nil, **seriesinfo_attr(isoxml).merge({name: "Internet-Draft", asciiName: "Internet-Draft"}) i = isoxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text and front.seriesInfo **attr_code(name: "", value: "", status: i) end |
#ietf_bibitem_entry(div, b, i) ⇒ Object
137 138 139 140 |
# File 'lib/isodoc/ietf/references.rb', line 137 def ietf_bibitem_entry(div, b, i) url = b&.at(ns("./uri[@type = 'xml']"))&.text div << "<xi:include href='#{url}'/>" end |
#image_cleanup(docxml) ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/isodoc/ietf/cleanup.rb', line 143 def image_cleanup(docxml) docxml.xpath("//t[descendant::artwork]").each do |t| insert = t t.xpath(".//artwork").each_with_index do |a, i| insert.next = a.dup insert = insert.next a.replace("[IMAGE #{i+1}]") end end end |
#image_parse(node, out, caption) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/ietf/inline.rb', line 89 def image_parse(node, out, ) attrs = { src: node["src"], title: node["title"], align: node["align"], name: node["filename"], anchor: node["id"], type: "svg", alt: node["alt"] } out.artwork **attr_code(attrs) image_title_parse(out, ) end |
#image_title_parse(out, caption) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/isodoc/ietf/inline.rb', line 98 def image_title_parse(out, ) unless .nil? out.t **{ align: "center", keepWithPrevious: "true" } do |p| p << .to_s end end end |
#index_parse(node, out) ⇒ Object
158 159 160 161 |
# File 'lib/isodoc/ietf/inline.rb', line 158 def index_parse(node, out) out.iref nil, **attr_code(item: node["primary"], subitem: node["secondary"]) end |
#info(isoxml, out) ⇒ Object
21 22 23 24 |
# File 'lib/isodoc/ietf/front.rb', line 21 def info(isoxml, out) @meta.areas isoxml, out super end |
#init_file(filename, debug) ⇒ Object
65 66 67 68 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 65 def init_file(filename, debug) filename = filename.sub(/\.rfc\.xml$/, ".rfc") super end |
#inline?(node) ⇒ Boolean
53 54 55 56 57 58 |
# File 'lib/isodoc/ietf/reqt.rb', line 53 def inline?(node) return true if node.first_element_child.nil? %w(em link eref xref strong tt sup sub strike keyword smallcap br hr bookmark pagebreak stem origin term preferred admitted deprecates domain termsource modification).include? node.first_element_child.name end |
#is_ietf(b) ⇒ Object
142 143 144 145 146 |
# File 'lib/isodoc/ietf/references.rb', line 142 def is_ietf(b) return false if !@xinclude url = b.at(ns("./uri[@type = 'xml']")) or return false /xml2rfc\.tools\.ietf\.org/.match(url) end |
#keyword(isoxml, front) ⇒ Object
200 201 202 203 204 |
# File 'lib/isodoc/ietf/front.rb', line 200 def keyword(isoxml, front) @meta.get[:keywords].each do |kw| front.keyword kw end end |
#keyword_parse(node, out) ⇒ Object
49 50 51 |
# File 'lib/isodoc/ietf/inline.rb', line 49 def keyword_parse(node, out) node.children.each { |n| parse(n, out) } end |
#link_parse(node, out) ⇒ Object
83 84 85 86 87 |
# File 'lib/isodoc/ietf/inline.rb', line 83 def link_parse(node, out) out.eref **attr_code(target: node["target"]) do |l| node.children.each { |n| parse(n, l) } end end |
#make_back(out, isoxml) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/isodoc/ietf/section.rb', line 128 def make_back(out, isoxml) out.back do |back| bibliography isoxml, back annex isoxml, back end end |
#make_endnotes(docxml) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/isodoc/ietf/cleanup.rb', line 135 def make_endnotes(docxml) return unless docxml.at("//fn") endnotes = docxml.at("//back") or docxml << "<back/>" and endnotes = docxml.at("//back") endnotes << "<section><name>Endnotes</name></section>" endnotes = docxml.at("//back/section[last()]") end |
#make_front(out, isoxml) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/isodoc/ietf/front.rb', line 5 def make_front(out, isoxml) info(isoxml, out) out.front do |front| title isoxml, front seriesinfo isoxml, front isoxml, front date isoxml, front area isoxml, front workgroup isoxml, front keyword isoxml, front abstract isoxml, front note isoxml, front boilerplate isoxml, front end end |
#make_generic_footnote_text(node, fnref) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/isodoc/ietf/footnotes.rb', line 18 def make_generic_footnote_text(node, fnref) first = node.first_element_child noko do |xml| xml.fn do |div| xml.t **attr_code(anchor: first ? first["id"] : nil) do |div| div.ref fnref first.name == "p" and first.children.each { |n| parse(n, div) } end first.name == "p" and node.elements.drop(1).each { |n| parse(n, xml) } or node.children.each { |n| parse(n, xml) } end end.join end |
#make_link(out, isoxml) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/isodoc/ietf/section.rb', line 101 def make_link(out, isoxml) links = isoxml.xpath(ns( "//bibdata/relation[@type = 'includedIn' or @type = 'describedBy' or "\ "@type = 'derivedFrom' or @type = 'instance']")) || return links.each do |l| out.link **{ href: l&.at(ns("./bibitem/docidentifier"))&.text, rel: rel2iana(l["type"]) } end end |
#make_local_footnote(node, fn, out) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/isodoc/ietf/footnotes.rb', line 10 def make_local_footnote(node, fn, out) return if @seen_footnote.include?(fn) @in_footnote = true out << make_generic_footnote_text(node, fn) @in_footnote = false @seen_footnote << fn end |
#make_middle(out, isoxml) ⇒ Object
122 123 124 125 126 |
# File 'lib/isodoc/ietf/section.rb', line 122 def make_middle(out, isoxml) out.middle do |middle| clause isoxml, middle end end |
#make_postamble(docxml) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/isodoc/ietf/cleanup.rb', line 77 def make_postamble(docxml) docxml.xpath("//figure").each do |f| a = f&.at("./artwork | ./sourcecode") || next name = f&.at("./name")&.remove b = a&.xpath("./preceding-sibling::*")&.remove c = a&.xpath("./following-sibling::*")&.remove a = a.remove name and f << name b.empty? or f << "<preamble>#{b.to_xml}</preamble>" a and f << a c.empty? or f << "<postamble>#{c.to_xml}</postamble>" end end |
#make_table_footnote_link(out, fnid, fnref) ⇒ Object
47 48 49 |
# File 'lib/isodoc/ietf/footnotes.rb', line 47 def make_table_footnote_link(out, fnid, fnref) out << " [#{fnref}]" end |
#make_table_footnote_text(node, fnid, fnref) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/isodoc/ietf/footnotes.rb', line 51 def make_table_footnote_text(node, fnid, fnref) first = node.first_element_child noko do |xml| xml.t **attr_code(anchor: first ? first["id"] : nil) do |div| div << "[#{fnref}] " first.name == "p" and first.children.each { |n| parse(n, div) } end first.name == "p" and node.elements.drop(1).each { |n| parse(n, xml) } or node.children.each { |n| parse(n, xml) } end.join end |
#make_tr_attr(td, row, totalrows, header) ⇒ Object
38 39 40 41 |
# File 'lib/isodoc/ietf/table.rb', line 38 def make_tr_attr(td, row, totalrows, header) attr_code(rowspan: td["rowspan"], colspan: td["colspan"], align: td["align"] ) end |
#metadata_init(lang, script, labels) ⇒ Object
29 30 31 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 29 def (lang, script, labels) @meta = Metadata.new(lang, script, labels) end |
#modification_parse(node, out) ⇒ Object
8 9 10 11 12 |
# File 'lib/isodoc/ietf/terms.rb', line 8 def modification_parse(node, out) para = node.at(ns("./p")) out << " -- " para.children.each { |n| parse(n, out) } end |
#move_postamble(docxml) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/isodoc/ietf/cleanup.rb', line 91 def move_postamble(docxml) docxml.xpath("//postamble").each do |p| insert = p.parent p.remove.elements.each do |e| insert.next = e insert = insert.next_element end end end |
#move_preamble(docxml) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/isodoc/ietf/cleanup.rb', line 101 def move_preamble(docxml) docxml.xpath("//preamble").each do |p| insert = p.parent p.remove.elements.each do |e| insert.previous = e end end end |
#nonstd_bibitem(list, b, ordinal, bibliography) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/isodoc/ietf/references.rb', line 32 def nonstd_bibitem(list, b, ordinal, bibliography) uris = b.xpath(ns("./uri")) target = nil uris&.each do |u| if u["type"] == "src" then target = u.text end end list.reference **attr_code(target: target, anchor: b["id"]) do |r| r.front do |f| relaton_to_title(b, f) (b, f) relaton_to_date(b, f) relaton_to_keyword(b, f) relaton_to_abstract(b, f) end uris&.each do |u| r.format nil, **attr_code(target: u.text, type: u["type"]) end docidentifiers = b.xpath(ns("./docidentifier")) id = render_identifier(bibitem_ref_code(b)) !id[1].nil? and id[1] != "(NO ID)" and r.refcontent id[1] docidentifiers&.each do |u| if %w(DOI IETF).include? u["type"] r.seriesInfo nil, **attr_code(value: u.text, name: u["type"]) end end end end |
#note(isoxml, front) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/isodoc/ietf/front.rb', line 215 def note(isoxml, front) a = isoxml.at(ns("//preface/abstract/note | //preface/foreword/note")) or return front.note **attr_code(removeInRFC: a["removeInRFC"]) do |n| title = a.at(ns("./name")) and n.name do |t| title.children.each { |tt| parse(tt, t) } end a.children.reject { |c1| c1.name == "name" }.each do |c1| parse(c1, n) end end end |
#note_label(node) ⇒ Object
74 75 76 |
# File 'lib/isodoc/ietf/blocks.rb', line 74 def note_label(node) l10n("#{super}: ") end |
#note_parse(node, out) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/isodoc/ietf/blocks.rb', line 78 def note_parse(node, out) first = node.first_element_child out.aside **attr_code(anchor: node["id"] || first["id"]) do |a| a.t do |p| p << note_label(node) first.name == "p" and first.children.each { |n| parse(n, p) } end first.name == "p" and node.elements.drop(1).each { |n| parse(n, out) } or node.children.each { |n| parse(n, out) } end end |
#ol_attrs(node) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/isodoc/ietf/blocks.rb', line 45 def ol_attrs(node) { anchor: node["id"], spacing: node["spacing"], type: ol_style(node["type"]), group: node["group"], start: node["start"] } end |
#ol_parse(node, out) ⇒ Object
53 54 55 56 57 |
# File 'lib/isodoc/ietf/blocks.rb', line 53 def ol_parse(node, out) out.ol **attr_code(ol_attrs(node)) do |ol| node.children.each { |n| parse(n, ol) } end end |
#ol_style(type) ⇒ Object
41 42 43 |
# File 'lib/isodoc/ietf/blocks.rb', line 41 def ol_style(type) OL_STYLE[type&.to_sym] || type end |
#org_author(c, role, front) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/isodoc/ietf/front.rb', line 102 def (c, role, front) front. **attr_code(role: role) do |a| organization(c.at(ns("./organization")), a, c.document.at(ns("//showOnFrontPage"))) address(c.at(ns(".//address")), c.at(ns(".//phone[not(@type = 'fax')]")), c.at(ns(".//phone[@type = 'fax']")), c.at(ns(".//email")), c.at(ns(".//uri")), a) end end |
#organization(org, out, show) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/isodoc/ietf/front.rb', line 113 def organization(org, out, show) name = org.at(ns("./name"))&.text out.organization name, **attr_code( showOnFrontPage: show&.text, ascii: name&.transliterate, asciiAbbrev: org&.at(ns("./abbreviation"))&.transliterate, abbrev: org.at(ns("./abbreviation"))) end |
#page_break(_out) ⇒ Object
68 69 |
# File 'lib/isodoc/ietf/inline.rb', line 68 def page_break(_out) end |
#pagebreak_parse(_node, _out) ⇒ Object
71 72 |
# File 'lib/isodoc/ietf/inline.rb', line 71 def pagebreak_parse(_node, _out) end |
#para_attrs(node) ⇒ Object
3 4 5 6 7 |
# File 'lib/isodoc/ietf/blocks.rb', line 3 def para_attrs(node) { keepWithNext: node["keep-with-next"], keepWithPrevious: node["keep-with-previous"], anchor: node["id"] } end |
#para_parse(node, out) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/ietf/blocks.rb', line 9 def para_parse(node, out) out.t **attr_code(para_attrs(node)) do |p| unless @termdomain.empty? p << "<#{@termdomain}> " @termdomain = "" end node.children.each { |n| parse(n, p) unless n.name == "note" } end node.xpath(ns("./note")).each { |n| parse(n, out) } end |
#permission_parse(node, out) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/isodoc/ietf/reqt.rb', line 45 def (node, out) recommendation_name(node, out, @permission_lbl) recommendation_attributes(node, out) node.children.each do |n| parse(n, out) unless %w(label title).include? n.name end end |
#pers_author_attrs1(ret, full, init, c) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/isodoc/ietf/front.rb', line 83 def (ret, full, init, c) full and ret.merge!(attr_code( asciiFullname: full&.transliterate, asciiInitials: init&.transliterate, asciiSurname: c&.at(ns("./surname"))&.text&.transliterate)) ret end |
#person_author(c, role, front) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/isodoc/ietf/front.rb', line 91 def (c, role, front) front. **(c.at(ns("./person/name")), role) do |a| org = c.at(ns("./person/affiliation/organization")) and organization(org, a, c.document.at(ns("//showOnFrontPage"))) address(c.xpath(ns(".//address")), c.at(ns(".//phone[not(@type = 'fax')]")), c.at(ns(".//phone[@type = 'fax']")), c.xpath(ns(".//email")), c.xpath(ns(".//uri")), a) end end |
#person_author_attrs(c, role) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/isodoc/ietf/front.rb', line 72 def (c, role) return {} if c.nil? full = c&.at(ns("./completename"))&.text init = c&.at(ns("./initial"))&.text || c&.xpath(ns("./forename")).map { |n| n.text[0] }.join(".") init = nil if init.empty? ret = attr_code(role: role, fullname: full, initials: init, surname: c&.at(ns("./surname"))&.text) (ret, full, init, c) end |
#postal(addr, out) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/isodoc/ietf/front.rb', line 132 def postal(addr, out) if line = addr.at(ns("./formattedAddress")) line.text.split(/\n/).each do |l| out.postalLine l, **attr_code(ascii: l.transliterate) end else out.postal do |p| postal_detailed(addr, p) end end end |
#postal_detailed(addr, out) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/isodoc/ietf/front.rb', line 144 def postal_detailed(addr, out) addr.xpath(ns("./street")).each do |s| out.street s.text, **attr_code(ascii: s.text.transliterate) end s = addr.at(ns("./city")) and out.city s.text, **attr_code(ascii: s.text.transliterate) s = addr.at(ns("./state")) and out.region s.text, **attr_code(ascii: s.text.transliterate) s = addr.at(ns("./country")) and out.country s.text, **attr_code(ascii: s.text.transliterate) s = addr.at(ns("./postcode")) and out.code s.text, **attr_code(ascii: s.text.transliterate) end |
#postprocess(result, filename, dir) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 57 def postprocess(result, filename, dir) result = from_xhtml(cleanup(to_xhtml(textcleanup(result)))). sub(/<!DOCTYPE[^>]+>\n/, ""). sub(/(<rfc[^<]+? )lang="[^"]+"/, "\\1") File.open("#{filename}.rfc.xml", "w:UTF-8") { |f| f.write(result) } @files_to_delete.each { |f| FileUtils.rm_rf f } end |
#pre_parse(node, out) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/isodoc/ietf/blocks.rb', line 120 def pre_parse(node, out) out.artwork **attr_code(anchor: node["id"], align: node["align"], alt: node["alt"], type: "ascii-art") do |s| s.cdata node.text.sub(/^\n/, "").gsub(/\t/, " ") end end |
#pseudocode_parse(node, out) ⇒ Object
208 209 210 |
# File 'lib/isodoc/ietf/blocks.rb', line 208 def pseudocode_parse(node, out) sourcecode_parse(node, out) end |
#quote_attribution(node) ⇒ Object
162 163 164 165 166 |
# File 'lib/isodoc/ietf/blocks.rb', line 162 def quote_attribution(node) = node&.at(ns("./author"))&.text source = node&.at(ns("./source/@uri"))&.text attr_code(quotedFrom: , cite: source) end |
#quote_parse(node, out) ⇒ Object
168 169 170 171 172 173 174 |
# File 'lib/isodoc/ietf/blocks.rb', line 168 def quote_parse(node, out) out.blockquote **quote_attribution(node) do |p| node.children.each do |n| parse(n, p) unless ["author", "source"].include? n.name end end end |
#recommendation_attributes(node, out) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/isodoc/ietf/reqt.rb', line 17 def recommendation_attributes(node, out) ret = recommendation_attributes1(node) return if ret.empty? out.ul do |p| ret.each do |l| p.li do |i| i.em { |e| i << l } end end end end |
#recommendation_name(node, out, type) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/isodoc/ietf/reqt.rb', line 3 def recommendation_name(node, out, type) label, title, lbl = recommendation_labels(node) out.t **{ keepWithNext: "true" } do |b| b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:")) end if label || title out.t **{ keepWithNext: "true" } do |b| label and label.children.each { |n| parse(n,b) } b << "#{clausedelim} " if label && title title and title.children.each { |n| parse(n,b) } end end end |
#recommendation_parse(node, out) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/isodoc/ietf/reqt.rb', line 29 def recommendation_parse(node, out) recommendation_name(node, out, @recommendation_lbl) recommendation_attributes(node, out) node.children.each do |n| parse(n, out) unless %w(label title).include? n.name end end |
#rel2iana(type) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/isodoc/ietf/section.rb', line 111 def rel2iana(type) case type when "includedIn" then "item" when "describedBy" then "describedby" when "derivedFrom" then "convertedfrom" when "instance" then "alternate" else "alternate" end end |
#relaton_org_to_author(o, role, f) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/isodoc/ietf/references.rb', line 97 def (o, role, f) name = o&.at(ns("./name"))&.text abbrev = o&.at(ns("./abbreviation"))&.text f. do |a| f.organization name, **attr_code(ascii: name&.transliterate, abbrev: abbrev) end end |
#relaton_person_to_author(p, role, f) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/isodoc/ietf/references.rb', line 84 def (p, role, f) fullname = p&.at(ns("./completename"))&.text surname = p&.at(ns("./surname"))&.text initials = p&.xpath(ns("./initial"))&.map { |i| i.text }&.join(" ") || p&.xpath(ns("./forename"))&.map { |i| i.text[0] }&.join(" ") initials = nil if initials.empty? f. nil, **attr_code(fullname: fullname, asciiFullname: fullname&.transliterate, role: role, surname: surname, initials: initials, asciiSurname: fullname ? surname&.transliterate : nil, asciiInitials: fullname ? initials&.transliterate : nil) end |
#relaton_to_abstract(b, f) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/isodoc/ietf/references.rb', line 123 def relaton_to_abstract(b, f) b.xpath(ns("./abstract")).each do |k| f.abstract do |abstract| if k.at(ns("./p")) k.children.each { |n| parse(n, abstract) } else abstract.t do |t| k.children.each { |n| parse(n, t) } end end end end end |
#relaton_to_author(b, f) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/isodoc/ietf/references.rb', line 71 def (b, f) auths = b.xpath(ns("./contributor[xmlns:role/@type = 'author' or "\ "xmlns:role/@type = 'editor']")) auths.empty? and auths = b.xpath(ns("./contributor[xmlns:role/@type = "\ "'publisher']")) auths.each do |a| role = a.at(ns("./role[@type = 'editor']")) ? "editor" : nil p = a&.at(ns("./person/name")) and (p, role, f) or (a&.at(ns("./organization")), role, f) end end |
#relaton_to_date(b, f) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/isodoc/ietf/references.rb', line 106 def relaton_to_date(b, f) date = b.at(ns("./date[@type = 'published']")) || b.at(ns("./date[@type = 'issued']")) || b.at(ns("./date[@type = 'circulated']")) return unless date attr = date_attr(date&.at(ns("./on | ./from"))&.text) || return f.date **attr_code(attr) end |
#relaton_to_keyword(b, f) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/isodoc/ietf/references.rb', line 115 def relaton_to_keyword(b, f) b.xpath(ns("./keyword")).each do |k| f.keyword do |keyword| k.children.each { |n| parse(n, keyword) } end end end |
#relaton_to_title(b, f) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/isodoc/ietf/references.rb', line 64 def relaton_to_title(b, f) title = b&.at(ns("./title")) || b&.at(ns("./formattedref")) or return f.title do |t| title.children.each { |n| parse(n, t) } end end |
#requirement_component_parse(node, out) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/isodoc/ietf/reqt.rb', line 60 def requirement_component_parse(node, out) return if node["exclude"] == "true" out1 = out if inline?(node) out.t do |p| p << "INHERIT: " if node.name == "inherit" node.children.each { |n| parse(n, p) } end else node.children.each { |n| parse(n, out) } end end |
#requirement_parse(node, out) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/isodoc/ietf/reqt.rb', line 37 def requirement_parse(node, out) recommendation_name(node, out, @requirement_lbl) recommendation_attributes(node, out) node.children.each do |n| parse(n, out) unless %w(label title).include? n.name end end |
#review_note_parse(node, out) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/isodoc/ietf/blocks.rb', line 191 def review_note_parse(node, out) out.cref **attr_code(anchor: node["id"], display: node["display"], source: node["reviewer"]) do |c| name = node.at(ns("./name")) and c.name do |div| name.children.each { |n| parse(n, div) } end node.children.each { |n| parse(n, c) unless n.name == "name" } end end |
#rfc_attributes(docxml) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/isodoc/ietf/section.rb', line 54 def rfc_attributes(docxml) t = Time.now.getutc obs = xpath_comma(docxml.xpath(ns( "//bibdata/relation[@type = 'obsoletes']/bibitem/docidentifier"))) upd = xpath_comma(docxml.xpath(ns( "//bibdata/relation[@type = 'updates']/bibitem/docidentifier"))) { docName: @meta.get[:doctype] == "Internet Draft" ? @meta.get[:docnumber] : nil, number: @meta.get[:doctype].casecmp?("rfc") ? @meta.get[:docnumber] : nil, category: series2category( docxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text), ipr: docxml&.at(ns("//bibdata/ext/ipr"))&.text, obsoletes: obs, updates: upd, indexInclude: docxml&.at(ns("//bibdata/ext/indexInclude"))&.text, iprExtract: docxml&.at(ns("//bibdata/ext/iprExtract"))&.text, sortRefs: docxml&.at(ns("//bibdata/ext/sortRefs"))&.text, symRefs: docxml&.at(ns("//bibdata/ext/symRefs"))&.text, tocInclude: docxml&.at(ns("//bibdata/ext/tocInclude"))&.text, tocDepth: docxml&.at(ns("//bibdata/ext/tocDepth"))&.text, submissionType: docxml&.at(ns( "//bibdata/series[@type = 'stream']/title"))&.text || "IETF", 'xml:lang': docxml&.at(ns("//bibdata/language"))&.text, version: "3", 'xmlns:xi': "http://www.w3.org/2001/XInclude", } end |
#rfc_seriesinfo(isoxml, front) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/isodoc/ietf/front.rb', line 46 def rfc_seriesinfo(isoxml, front) front.seriesInfo **seriesinfo_attr(isoxml).merge({name: "RFC", asciiName: "RFC"}) i = isoxml&.at(ns("//bibdata/series[@type = 'intended']")) and front.seriesInfo nil, **attr_code(name: "", status: i&.at(ns("./title"))&.text, value: i&.at(ns("./number"))&.text || "") end |
#series2category(series) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/isodoc/ietf/section.rb', line 82 def series2category(series) case series&.downcase when "standard" then "std" when "informational" then "info" when "experimental" then "exp" when "bcp" then "bcp" when "fyi" then "info" when "full-standard" then "std" when "historic" then "historic" else "std" end end |
#seriesinfo(isoxml, front) ⇒ Object
33 34 35 36 |
# File 'lib/isodoc/ietf/front.rb', line 33 def seriesinfo(isoxml, front) rfc_seriesinfo(isoxml, front) if @meta.get[:doctype] == "Rfc" id_seriesinfo(isoxml, front) if @meta.get[:doctype] == "Internet Draft" end |
#seriesinfo_attr(isoxml) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/isodoc/ietf/front.rb', line 38 def seriesinfo_attr(isoxml) attr_code(value: @meta.get[:docnumber] || "", asciiValue: @meta.get[:docnumber]&.transliterate, status: @meta.get[:stage], stream: isoxml&.at(ns("//bibdata/series[@type = 'stream']/"\ "title"))&.text) end |
#set_pis(node, doc) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/isodoc/ietf/section.rb', line 44 def set_pis(node, doc) rfc_pis = common_rfc_pis(node) rfc_pis.each_pair do |k, v| pi = Nokogiri::XML::ProcessingInstruction.new(doc, "rfc", "#{k}=\"#{v}\"") doc.root.add_previous_sibling(pi) end doc.to_xml end |
#smallcap_parse(node, out) ⇒ Object
45 46 47 |
# File 'lib/isodoc/ietf/inline.rb', line 45 def smallcap_parse(node, out) node.children.each { |n| parse(n, out) } end |
#sourcecode_cleanup(docxml) ⇒ Object
for markup in pseudocode
155 156 157 158 159 160 161 162 |
# File 'lib/isodoc/ietf/cleanup.rb', line 155 def sourcecode_cleanup(docxml) docxml.xpath("//sourcecode").each do |s| s.children = s.children.to_xml.gsub(%r{<br/>\n}, "\n"). gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>") sourcecode_remove_markup(s) s.children = "<![CDATA[#{s.children.to_xml.sub(/\A\n+/, "")}]]>" end end |
#sourcecode_parse(node, out) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/isodoc/ietf/blocks.rb', line 107 def sourcecode_parse(node, out) out.figure **attr_code(anchor: node["id"]) do |div| name = node&.at(ns("./name"))&.remove and div.name do |n| name.children.each { |nn| parse(nn, n) } end div.sourcecode **attr_code(type: node["lang"], name: node["filename"], markers: node["markers"], src: node["src"]) do |s| node.children.each { |x| parse(x, s) unless x.name == "name" } end end end |
#sourcecode_remove_markup(s) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/isodoc/ietf/cleanup.rb', line 164 def sourcecode_remove_markup(s) s.traverse do |n| next if n.text? next if %w(name callout annotation note sourcecode).include? n.name if n.name == "br" then n.replace("\n") elsif n.name == "t" then n.replace("\n\n#{n.children}") else n.replace(n.children) end end end |
#stem_parse(node, out) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/isodoc/ietf/inline.rb', line 59 def stem_parse(node, out) stem = case node["type"] when "MathML" then MathML2AsciiMath.m2a(node.children.to_xml) else HTMLEntities.new.encode(node.text) end out << "#{@openmathdelim} #{stem} #{@closemathdelim}" end |
#strike_parse(node, out) ⇒ Object
41 42 43 |
# File 'lib/isodoc/ietf/inline.rb', line 41 def strike_parse(node, out) node.children.each { |n| parse(n, out) } end |
#strong_parse(node, out) ⇒ Object
29 30 31 32 33 |
# File 'lib/isodoc/ietf/inline.rb', line 29 def strong_parse(node, out) out.strong do |e| node.children.each { |n| parse(n, e) } end end |
#sub_parse(node, out) ⇒ Object
17 18 19 20 21 |
# File 'lib/isodoc/ietf/inline.rb', line 17 def sub_parse(node, out) out.sub do |e| node.children.each { |n| parse(n, e) } end end |
#sup_parse(node, out) ⇒ Object
11 12 13 14 15 |
# File 'lib/isodoc/ietf/inline.rb', line 11 def sup_parse(node, out) out.sup do |e| node.children.each { |n| parse(n, e) } end end |
#table_attrs(node) ⇒ Object
3 4 5 |
# File 'lib/isodoc/ietf/table.rb', line 3 def table_attrs(node) attr_code(anchor: node["id"], align: node["align"]) end |
#table_cleanup(docxml) ⇒ Object
43 44 45 |
# File 'lib/isodoc/ietf/cleanup.rb', line 43 def table_cleanup(docxml) table_footnote_cleanup(docxml) end |
#table_footnote_cleanup(docxml) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/isodoc/ietf/cleanup.rb', line 27 def table_footnote_cleanup(docxml) docxml.xpath("//table[descendant::fn]").each do |t| t.xpath(".//fn").each do |a| t << "<aside>#{a.remove.children}</aside>" end end end |
#table_footnote_parse(node, out) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/isodoc/ietf/footnotes.rb', line 33 def table_footnote_parse(node, out) fn = node["reference"] tid = get_table_ancestor_id(node) make_table_footnote_link(out, tid + fn, fn) # do not output footnote text if we have already seen it for this table return if @seen_footnote.include?(tid + fn) @in_footnote = true out.fn do |a| a << make_table_footnote_text(node, tid + fn, fn) end @in_footnote = false @seen_footnote << (tid + fn) end |
#table_parse(node, out) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/isodoc/ietf/table.rb', line 7 def table_parse(node, out) @in_table = true out.table **table_attrs(node) do |t| table_title_parse(node, out) thead_parse(node, t) tbody_parse(node, t) tfoot_parse(node, t) end (dl = node.at(ns("./dl"))) && parse(dl, out) node.xpath(ns("./note")).each { |n| parse(n, out) } @in_table = false end |
#table_title_parse(node, out) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/isodoc/ietf/table.rb', line 20 def table_title_parse(node, out) name = node.at(ns("./name")) || return out.name do |p| name.children.each { |n| parse(n, p) } end end |
#term_parse(node, out) ⇒ Object
27 28 29 30 31 |
# File 'lib/isodoc/ietf/terms.rb', line 27 def term_parse(node, out) out.name do |p| node.children.each { |n| parse(n, p) } end end |
#termdef_parse(node, out) ⇒ Object
44 45 46 47 |
# File 'lib/isodoc/ietf/terms.rb', line 44 def termdef_parse(node, out) set_termdomain("") clause_parse(node, out) end |
#termdocsource_parse(_node, _out) ⇒ Object
49 50 |
# File 'lib/isodoc/ietf/terms.rb', line 49 def termdocsource_parse(_node, _out) end |
#termnote_anchor_names(docxml) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/isodoc/ietf/terms.rb', line 52 def termnote_anchor_names(docxml) docxml.xpath(ns("//term[descendant::termnote]")).each do |t| c = Counter.new notes = t.xpath(ns(".//termnote")) notes.each do |n| next if n["id"].nil? || n["id"].empty? idx = notes.size == 1 ? "" : " #{c.increment(n).print}" @anchors[n["id"]] = anchor_struct(idx, n, @note_xref_lbl, "note", false) end end end |
#termnote_parse(node, out) ⇒ Object
33 34 35 |
# File 'lib/isodoc/ietf/terms.rb', line 33 def termnote_parse(node, out) note_parse(node, out) end |
#termref_parse(node, out) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/isodoc/ietf/terms.rb', line 37 def termref_parse(node, out) out.t do |p| p << "SOURCE: " node.children.each { |n| parse(n, p) } end end |
#text_parse(node, out) ⇒ Object
53 54 55 56 57 |
# File 'lib/isodoc/ietf/inline.rb', line 53 def text_parse(node, out) return if node.nil? || node.text.nil? text = node.to_s out << text end |
#textcleanup(docxml) ⇒ Object
53 54 55 |
# File 'lib/isodoc/ietf/rfc_convert.rb', line 53 def textcleanup(docxml) passthrough_cleanup(docxml) end |
#title(isoxml, front) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/isodoc/ietf/front.rb', line 26 def title(isoxml, front) title = @meta.get[:doctitle] or return front.title title, **attr_code(abbrev: @meta.get[:docabbrev], ascii: @meta.get[:docascii] || title.transliterate) end |
#tr_parse(node, out, ord, totalrows, header) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/isodoc/ietf/table.rb', line 27 def tr_parse(node, out, ord, totalrows, header) out.tr do |r| node.elements.each do |td| attrs = make_tr_attr(td, ord, totalrows - 1, header) r.send td.name, **attrs do |entry| td.children.each { |n| parse(n, entry) } end end end end |
#tt_parse(node, out) ⇒ Object
23 24 25 26 27 |
# File 'lib/isodoc/ietf/inline.rb', line 23 def tt_parse(node, out) out.tt do |e| node.children.each { |n| parse(n, e) } end end |
#ul_attrs(node) ⇒ Object
NOTE ignoring “bare” attribute, which is tantamount to “empty”
21 22 23 24 25 |
# File 'lib/isodoc/ietf/blocks.rb', line 21 def ul_attrs(node) { anchor: node["id"], empty: node["nobullet"], spacing: node["spacing"] } end |
#ul_parse(node, out) ⇒ Object
27 28 29 30 31 |
# File 'lib/isodoc/ietf/blocks.rb', line 27 def ul_parse(node, out) out.ul **attr_code(ul_attrs(node)) do |ul| node.children.each { |n| parse(n, ul) } end end |
#workgroup(isoxml, front) ⇒ Object
194 195 196 197 198 |
# File 'lib/isodoc/ietf/front.rb', line 194 def workgroup(isoxml, front) @meta.get[:wg].each do |w| front.workgroup w end end |
#xpath_comma(xpath) ⇒ Object
96 97 98 99 |
# File 'lib/isodoc/ietf/section.rb', line 96 def xpath_comma(xpath) return nil if xpath.empty? xpath.map { |x| x.text }.join(", ") end |
#xref_parse(node, out) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/isodoc/ietf/inline.rb', line 106 def xref_parse(node, out) out.xref **attr_code(target: node["target"], format: node["format"], relative: node["relative"]) do |l| l << get_linkend(node) end end |