Module: Metanorma::Standoc::Section
- Includes:
- Regex
- Defined in:
- lib/metanorma/cleanup/section.rb,
lib/metanorma/converter/terms.rb,
lib/metanorma/converter/section.rb,
lib/metanorma/converter/ref_sect.rb,
lib/metanorma/converter/sectiontype.rb
Constant Summary collapse
- SECTIONTYPE_STREAMLINE =
{ "terms and definitions": ["terms, definitions, symbols and abbreviated terms", "terms, definitions, symbols and abbreviations", "terms, definitions and symbols", "terms, definitions and abbreviations", "terms, definitions and abbreviated terms", "terms and definitions"], "symbols and abbreviated terms": ["symbols and abbreviated terms", "symbols", "abbreviated terms", "abbreviations", "symbols and abbreviations", "symbols and abbreviated terms"], "acknowledgements": ["acknowledgements", "acknowledgments"], "executivesummary": ["executive summary", "executive-summary", "executive_summary"], "metanorma-extension": ["misc-container", "metanorma-extension"] }.freeze
- PREFACE_CLAUSE_NAMES =
%w(abstract foreword introduction metanorma-extension termdocsource metanorma-extension acknowledgements executivesummary) .freeze
- MAIN_CLAUSE_NAMES =
["normative references", "terms and definitions", "scope", "symbols and abbreviated terms", "clause", "bibliography"].freeze
Constants included from Regex
Regex::CONN_REGEX_STR, Regex::ISO_REF, Regex::ISO_REF_ALL_PARTS, Regex::ISO_REF_NO_YEAR, Regex::LOCALITIES, Regex::LOCALITY_REGEX_STR, Regex::LOCALITY_REGEX_STR_TRIPLEDASH, Regex::LOCALITY_REGEX_VALUE_ONLY_STR, Regex::NON_ISO_REF, Regex::NON_ISO_REF1, Regex::NUMERIC_REGEX, Regex::TERM_REFERENCE_RE, Regex::TERM_REFERENCE_RE_STR
Instance Method Summary collapse
- #abstract_parse(attrs, xml, node) ⇒ Object
- #acknowledgements_parse(attrs, xml, node) ⇒ Object
- #add_term_source(node, xml_t, seen_xref, match) ⇒ Object
- #add_term_source_mod(xml_t, match) ⇒ Object
- #annex_attrs_preprocess(attrs, node) ⇒ Object
- #annex_parse(attrs, xml, node) ⇒ Object
- #appendix_parse(attrs, xml, node) ⇒ Object
- #bibabstract_location(xml) ⇒ Object
- #bibitem_parse(attrs, xml, node) ⇒ Object
- #biblio_prep(attrs, xml, node) ⇒ Object
- #bibliography_parse(attrs, xml, node) ⇒ Object
- #clause_attrs_preprocess(attrs, node) ⇒ Object
- #clause_parse(attrs, xml, node) ⇒ Object
- #clausebefore_cleanup(xmldoc) ⇒ Object
- #clean_abstract(dupabstract) ⇒ Object
- #emend_biblio(xml, code, opts) ⇒ Object
- #emend_biblio_fn(xml, fnote) ⇒ Object
- #emend_biblio_id(xml, code) ⇒ Object
-
#emend_biblio_title(xml, code, title) ⇒ Object
supply title if missing; add title with spans in it as formattedref, to emend bibitem with later.
- #emend_biblio_usrlbl(xml, usrlbl) ⇒ Object
-
#endofpreface_clausebefore(xml, ins) ⇒ Object
only move clausebefore notes at the very end of preface.
- #executivesummary_parse(attrs, xml, node) ⇒ Object
- #extract_termsource_refs(text, node) ⇒ Object
- #floating_title(node) ⇒ Object
- #floating_title_attrs(node) ⇒ Object
- #foreword_parse(attrs, xml, node) ⇒ Object
- #in_biblio? ⇒ Boolean
- #in_norm_ref? ⇒ Boolean
- #in_terms? ⇒ Boolean
- #indexsect_parse(attrs, xml, node) ⇒ Object
- #introduction_parse(attrs, xml, node) ⇒ Object
- #make_abstract(xml, sect) ⇒ Object
- #make_annexes(xml) ⇒ Object
- #make_bibliography(xml, sect) ⇒ Object
- #make_colophon(xml) ⇒ Object
- #make_indexsect(xml, sect) ⇒ Object
- #make_preface(xml, sect) ⇒ Object
- #maxlevel(xml) ⇒ Object
- #metanorma_extension_parse(_attrs, xml, node) ⇒ Object
- #misccontainer_cleanup(xml) ⇒ Object
- #move_clauses_into_preface(xml, preface) ⇒ Object
- #nonterm_symbols_parse(attrs, xml, node) ⇒ Object
- #nonterm_term_def_subclause_parse(attrs, xml, node) ⇒ Object
- #norm_ref_parse(attrs, xml, node) ⇒ Object
- #obligations_cleanup(xml) ⇒ Object
- #obligations_cleanup_info(xml) ⇒ Object
- #obligations_cleanup_inherit(xml) ⇒ Object
- #obligations_cleanup_norm(xml) ⇒ Object
- #pop_symbols ⇒ Object
- #pop_term_def ⇒ Object
- #preamble(node) ⇒ Object
- #preface_clausebefore_cleanup(xmldoc) ⇒ Object
- #preface_main_filter(ret, node) ⇒ Object
- #role_style(node, value) ⇒ Object
- #scope_parse(attrs, xml, node) ⇒ Object
- #section(node) ⇒ Object
- #section_attributes(node) ⇒ Object
- #section_attributes_change(node, ret) ⇒ Object
- #section_title(xml, title) ⇒ Object
- #sections_clausebefore_cleanup(xmldoc) ⇒ Object
- #sections_cleanup(xml) ⇒ Object
- #sections_level_cleanup(xml) ⇒ Object
- #sections_order_cleanup(xml) ⇒ Object
- #sectiontype(node, level = true) ⇒ Object
- #sectiontype1(node) ⇒ Object
- #sectiontype_streamline(ret) ⇒ Object
- #set_obligation(attrs, node) ⇒ Object
- #single_clause_annex(xml) ⇒ Object
- #source_include_cleanup(xml) ⇒ Object
- #source_sanitise(code) ⇒ Object
- #start_main_section(ret, node) ⇒ Object
- #stash_symbols ⇒ Object
- #stash_term_def ⇒ Object
- #support_appendix?(_node) ⇒ Boolean
- #symbols_attrs(node, attr) ⇒ Object
- #symbols_parse(attr, xml, node) ⇒ Object
- #term_contains_subclauses(node) ⇒ Object
- #term_def_parse(attrs, xml, node, _toplevel) ⇒ Object
-
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
subclause contains subclauses.
- #term_def_subclause_parse1(attrs, xml, node) ⇒ Object
- #term_designation(xml, _node, tag, text) ⇒ Object
- #termdefinition(node) ⇒ Object
- #terms_boilerplate_parse(attrs, xml, node) ⇒ Object
- #termsource(node) ⇒ Object
- #termsource_attrs(node, matched) ⇒ Object
- #termsource_origin_attrs(_node, seen_xref) ⇒ Object
- #to_preface(preface, clause) ⇒ Object
Methods included from Regex
Instance Method Details
#abstract_parse(attrs, xml, node) ⇒ Object
114 115 116 |
# File 'lib/metanorma/converter/section.rb', line 114 def abstract_parse(attrs, xml, node) add_noko_elem(xml, "abstract", node.content, **attr_code(attrs)) end |
#acknowledgements_parse(attrs, xml, node) ⇒ Object
179 180 181 182 183 184 |
# File 'lib/metanorma/converter/section.rb', line 179 def acknowledgements_parse(attrs, xml, node) xml.acknowledgements **attr_code(attrs) do |xml_section| section_title(xml_section, node.title || @i18n.acknowledgements) xml_section << node.content end end |
#add_term_source(node, xml_t, seen_xref, match) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/metanorma/converter/terms.rb', line 125 def add_term_source(node, xml_t, seen_xref, match) attrs = {} body = seen_xref.children[0] unless body.name == "concept" attrs = termsource_origin_attrs(node, seen_xref) body = body.children end xml_t.origin **attr_code(attrs) do |o| o << body.to_xml end add_term_source_mod(xml_t, match) end |
#add_term_source_mod(xml_t, match) ⇒ Object
138 139 140 141 142 |
# File 'lib/metanorma/converter/terms.rb', line 138 def add_term_source_mod(xml_t, match) match[:text] && xml_t.modification do |mod| mod.p { |p| p << match[:text].sub(/^\s+/, "") } end end |
#annex_attrs_preprocess(attrs, node) ⇒ Object
139 140 141 142 |
# File 'lib/metanorma/converter/section.rb', line 139 def annex_attrs_preprocess(attrs, node) attrs[:"inline-header"] = node.option? "inline-header" set_obligation(attrs, node) end |
#annex_parse(attrs, xml, node) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/metanorma/converter/section.rb', line 144 def annex_parse(attrs, xml, node) annex_attrs_preprocess(attrs, node) xml.annex **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end end |
#appendix_parse(attrs, xml, node) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/metanorma/converter/section.rb', line 156 def appendix_parse(attrs, xml, node) attrs[:"inline-header"] = node.option? "inline-header" set_obligation(attrs, node) xml.appendix **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end end |
#bibabstract_location(xml) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/metanorma/cleanup/section.rb', line 60 def bibabstract_location(xml) xml.at("//bibdata/script") || xml.at("//bibdata/language") || xml.at("//bibdata/contributor[not(following-sibling::contributor)]") || xml.at("//bibdata/date[not(following-sibling::date)]") || xml.at("//docnumber") || xml.at("//bibdata/docidentifier" \ "[not(following-sibling::docidentifier)]") || xml.at("//bibdata/uri[not(following-sibling::uri)]") || xml.at("//bibdata/title[not(following-sibling::title)]") end |
#bibitem_parse(attrs, xml, node) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/metanorma/converter/ref_sect.rb', line 23 def bibitem_parse(attrs, xml, node) norm_ref = @norm_ref biblio = @biblio @biblio = false @norm_ref = false ret = clause_parse(attrs, xml, node) @biblio = biblio @norm_ref = norm_ref ret end |
#biblio_prep(attrs, xml, node) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/metanorma/converter/ref_sect.rb', line 45 def biblio_prep(attrs, xml, node) if node.option? "bibitem" bibitem_parse(attrs, xml, node) else node.attr("style") == "bibliography" or @log.add("STANDOC_16", node) nil end end |
#bibliography_parse(attrs, xml, node) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/metanorma/converter/ref_sect.rb', line 12 def bibliography_parse(attrs, xml, node) x = biblio_prep(attrs, xml, node) and return x @biblio = true attrs = attrs.merge(normative: node.attr("normative") || false) xml.references **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end @biblio = false end |
#clause_attrs_preprocess(attrs, node) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/metanorma/converter/section.rb', line 122 def clause_attrs_preprocess(attrs, node) attrs[:"inline-header"] = node.option? "inline-header" attrs[:bibitem] = true if node.option? "bibitem" attrs[:level] = node.attr("level") set_obligation(attrs, node) end |
#clause_parse(attrs, xml, node) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/metanorma/converter/section.rb', line 129 def clause_parse(attrs, xml, node) clause_attrs_preprocess(attrs, node) node.option?("appendix") && support_appendix?(node) and return appendix_parse(attrs, xml, node) xml.send :clause, **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end end |
#clausebefore_cleanup(xmldoc) ⇒ Object
199 200 201 202 |
# File 'lib/metanorma/cleanup/section.rb', line 199 def clausebefore_cleanup(xmldoc) sections_clausebefore_cleanup(xmldoc) preface_clausebefore_cleanup(xmldoc) end |
#clean_abstract(dupabstract) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/metanorma/cleanup/section.rb', line 48 def clean_abstract(dupabstract) dupabstract.traverse do |n| n.remove_attribute("id") n.remove_attribute("anchor") end %w(language script unnumbered).each do |w| dupabstract.remove_attribute(w) end dupabstract.at("./title")&.remove dupabstract end |
#emend_biblio(xml, code, opts) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/metanorma/converter/ref_sect.rb', line 55 def emend_biblio(xml, code, opts) emend_biblio_id(xml, code) emend_biblio_title(xml, code, opts[:title]) emend_biblio_usrlbl(xml, opts[:usrlbl]) emend_biblio_fn(xml, opts[:fn]) end |
#emend_biblio_fn(xml, fnote) ⇒ Object
88 89 90 91 |
# File 'lib/metanorma/converter/ref_sect.rb', line 88 def emend_biblio_fn(xml, fnote) fnote or return xml.root << "<note type='Unpublished-Status'><p>#{fnote}</p></note>" end |
#emend_biblio_id(xml, code) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/metanorma/converter/ref_sect.rb', line 62 def emend_biblio_id(xml, code) unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]") || /^doi:/.match?(code) @log.add("STANDOC_17", nil, params: [code]) xml.root << "<docidentifier>#{code}</docidentifier>" end end |
#emend_biblio_title(xml, code, title) ⇒ Object
supply title if missing; add title with spans in it as formattedref, to emend bibitem with later
72 73 74 75 76 77 78 79 80 |
# File 'lib/metanorma/converter/ref_sect.rb', line 72 def emend_biblio_title(xml, code, title) fmt = /<span class=|<fn/.match?(title) unless xml.at("/bibitem/title[text()]") @log.add("STANDOC_18", nil, params: [code]) !fmt and xml.root << "<title>#{title || '(MISSING TITLE)'}</title>" end fmt and xml.root << "<formattedref>#{title}</formattedref>" end |
#emend_biblio_usrlbl(xml, usrlbl) ⇒ Object
82 83 84 85 86 |
# File 'lib/metanorma/converter/ref_sect.rb', line 82 def emend_biblio_usrlbl(xml, usrlbl) usrlbl or return xml.at("/bibitem/docidentifier").next = "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>" end |
#endofpreface_clausebefore(xml, ins) ⇒ Object
only move clausebefore notes at the very end of preface
228 229 230 231 232 233 234 235 |
# File 'lib/metanorma/cleanup/section.rb', line 228 def endofpreface_clausebefore(xml, ins) xml.xpath("//preface//*[@beforeclauses = 'true']").reverse_each do |x| textafter = xml.xpath("//preface//*") & x.xpath("./following::*") textafter.text.strip.empty? or break x.delete("beforeclauses") ins.previous = x.remove end end |
#executivesummary_parse(attrs, xml, node) ⇒ Object
186 187 188 189 190 191 |
# File 'lib/metanorma/converter/section.rb', line 186 def executivesummary_parse(attrs, xml, node) xml.executivesummary **attr_code(attrs) do |xml_section| section_title(xml_section, node.title || @i18n.executivesummary) xml_section << node.content end end |
#extract_termsource_refs(text, node) ⇒ Object
144 145 146 147 148 |
# File 'lib/metanorma/converter/terms.rb', line 144 def extract_termsource_refs(text, node) matched = TERM_REFERENCE_RE.match text matched.nil? and @log.add("STANDOC_13", node, params: [text]) matched end |
#floating_title(node) ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/metanorma/converter/section.rb', line 199 def floating_title(node) noko do |xml| xml.floating_title **floating_title_attrs(node) do |xml_t| xml_t << node.title end end end |
#floating_title_attrs(node) ⇒ Object
193 194 195 196 197 |
# File 'lib/metanorma/converter/section.rb', line 193 def floating_title_attrs(node) attr_code(id_attr(node) .merge(align: node.attr("align"), depth: node.level, type: "floating-title")) end |
#foreword_parse(attrs, xml, node) ⇒ Object
172 173 174 175 176 177 |
# File 'lib/metanorma/converter/section.rb', line 172 def foreword_parse(attrs, xml, node) xml.foreword **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end end |
#in_biblio? ⇒ Boolean
4 5 6 |
# File 'lib/metanorma/converter/ref_sect.rb', line 4 def in_biblio? @biblio end |
#in_norm_ref? ⇒ Boolean
8 9 10 |
# File 'lib/metanorma/converter/ref_sect.rb', line 8 def in_norm_ref? @norm_ref end |
#in_terms? ⇒ Boolean
4 5 6 |
# File 'lib/metanorma/converter/terms.rb', line 4 def in_terms? @term_def end |
#indexsect_parse(attrs, xml, node) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/metanorma/converter/section.rb', line 107 def indexsect_parse(attrs, xml, node) xml.indexsect **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end end |
#introduction_parse(attrs, xml, node) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/metanorma/converter/section.rb', line 165 def introduction_parse(attrs, xml, node) xml.introduction **attr_code(attrs) do |xml_section| section_title(xml_section, @i18n.introduction) xml_section << node.content end end |
#make_abstract(xml, sect) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/metanorma/cleanup/section.rb', line 37 def make_abstract(xml, sect) if xml.at("//abstract[not(ancestor::bibitem)]") preface = sect.at("//preface") || sect.add_previous_sibling("<preface/>").first abstract = xml.at("//abstract[not(ancestor::bibitem)]").remove preface.prepend_child abstract.remove bibabstract = bibabstract_location(xml) bibabstract.next = clean_abstract(abstract.dup) end end |
#make_annexes(xml) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/metanorma/cleanup/section.rb', line 97 def make_annexes(xml) xml.xpath("//*[@annex]").each do |y| y.delete("annex") y.name == "annex" || !y.ancestors("annex").empty? and next y.wrap("<annex/>") add_id(y.parent) %w(obligation language script).each { |w| y.parent[w] = y[w] } end end |
#make_bibliography(xml, sect) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/cleanup/section.rb', line 71 def make_bibliography(xml, sect) if xml.at("//sections/references | //xref[@hidden]") biblio = sect.add_next_sibling("<bibliography/>").first xml.xpath("//sections/references").each do |r| biblio.add_child r.remove end end end |
#make_colophon(xml) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/metanorma/cleanup/section.rb', line 28 def make_colophon(xml) xml.at("//clause[@colophon]") or return colophon = xml.root.add_child("<colophon/>").first xml.xpath("//*[@colophon]").each do |c| c.delete("colophon") colophon.add_child c.remove end end |
#make_indexsect(xml, sect) ⇒ Object
80 81 82 83 84 |
# File 'lib/metanorma/cleanup/section.rb', line 80 def make_indexsect(xml, sect) xml.xpath("//sections/indexsect").reverse_each do |r| sect.next = r.remove end end |
#make_preface(xml, sect) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/metanorma/cleanup/section.rb', line 6 def make_preface(xml, sect) if xml.at("//foreword | //introduction | //acknowledgements | " \ "//executivesummary | //*[@preface]") preface = sect.add_previous_sibling("<preface/>").first f = xml.at("//foreword") and to_preface(preface, f) f = xml.at("//introduction") and to_preface(preface, f) move_clauses_into_preface(xml, preface) f = xml.at("//acknowledgements") and to_preface(preface, f) f = xml.at("//executivesummary") and to_preface(preface, f) end make_abstract(xml, sect) end |
#maxlevel(xml) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/metanorma/cleanup/section.rb', line 107 def maxlevel(xml) max = 5 xml.xpath("//clause[@level]").each do |c| max = c["level"].to_i if max < c["level"].to_i end max end |
#metanorma_extension_parse(_attrs, xml, node) ⇒ Object
103 104 105 |
# File 'lib/metanorma/converter/section.rb', line 103 def (_attrs, xml, node) add_noko_elem(xml, "metanorma-extension-clause", node.content) end |
#misccontainer_cleanup(xml) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/metanorma/cleanup/section.rb', line 134 def misccontainer_cleanup(xml) m = xml.xpath("//metanorma-extension-clause") m.empty? and return ins = add_misc_container(xml) m.each do |m1| ins << m1.remove.children end end |
#move_clauses_into_preface(xml, preface) ⇒ Object
19 20 21 |
# File 'lib/metanorma/cleanup/section.rb', line 19 def move_clauses_into_preface(xml, preface) xml.xpath("//*[@preface]").each { |c| to_preface(preface, c) } end |
#nonterm_symbols_parse(attrs, xml, node) ⇒ Object
8 9 10 11 12 |
# File 'lib/metanorma/converter/terms.rb', line 8 def nonterm_symbols_parse(attrs, xml, node) stash_symbols clause_parse(attrs, xml, node) pop_symbols end |
#nonterm_term_def_subclause_parse(attrs, xml, node) ⇒ Object
37 38 39 40 41 |
# File 'lib/metanorma/converter/terms.rb', line 37 def nonterm_term_def_subclause_parse(attrs, xml, node) stash_term_def clause_parse(attrs, xml, node) pop_term_def end |
#norm_ref_parse(attrs, xml, node) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/converter/ref_sect.rb', line 34 def norm_ref_parse(attrs, xml, node) x = biblio_prep(attrs, xml, node) and return x @norm_ref = true attrs = attrs.merge(normative: node.attr("normative") || true) xml.references **attr_code(attrs) do |xml_section| section_title(xml_section, node.title) xml_section << node.content end @norm_ref = false end |
#obligations_cleanup(xml) ⇒ Object
169 170 171 172 173 |
# File 'lib/metanorma/cleanup/section.rb', line 169 def obligations_cleanup(xml) obligations_cleanup_info(xml) obligations_cleanup_norm(xml) obligations_cleanup_inherit(xml) end |
#obligations_cleanup_info(xml) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/metanorma/cleanup/section.rb', line 175 def obligations_cleanup_info(xml) xml.xpath("//foreword | //introduction | //acknowledgements | " \ "//executivesummary | //references | //preface//clause") .each do |r| r["obligation"] = "informative" end end |
#obligations_cleanup_inherit(xml) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/metanorma/cleanup/section.rb', line 190 def obligations_cleanup_inherit(xml) xml.xpath("//annex | //clause[not(ancestor::boilerplate)]").each do |r| r["obligation"] = "normative" unless r["obligation"] end xml.xpath(Utils::SUBCLAUSE_XPATH).each do |r| o = r.at("./ancestor::*/@obligation")&.text and r["obligation"] = o end end |
#obligations_cleanup_norm(xml) ⇒ Object
183 184 185 186 187 188 |
# File 'lib/metanorma/cleanup/section.rb', line 183 def obligations_cleanup_norm(xml) s = xml.at("//clause[@type = 'scope']") and s["obligation"] = "normative" xml.xpath("//terms").each { |r| r["obligation"] = "normative" } xml.xpath("//definitions").each { |r| r["obligation"] = "normative" } end |
#pop_symbols ⇒ Object
65 66 67 |
# File 'lib/metanorma/converter/terms.rb', line 65 def pop_symbols @definitions = @stashed_definitions.pop end |
#pop_term_def ⇒ Object
55 56 57 |
# File 'lib/metanorma/converter/terms.rb', line 55 def pop_term_def @term_def = @stashed_term_def.pop end |
#preamble(node) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/metanorma/converter/section.rb', line 94 def preamble(node) noko do |xml| xml.foreword **attr_code(section_attributes(node)) do |xml_abstract| section_title(xml_abstract, node.blocks[0].title || @i18n.foreword) xml_abstract << node.content end end end |
#preface_clausebefore_cleanup(xmldoc) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/metanorma/cleanup/section.rb', line 204 def preface_clausebefore_cleanup(xmldoc) xmldoc.at("//preface") or return ins = insert_before(xmldoc, "//preface") xmldoc.xpath("//preface//*[@beforeclauses = 'true']").each do |x| x.delete("beforeclauses") ins.previous = x.remove end xmldoc.xpath("//*[@coverpage = 'true']").each do |x| ins.previous = x.remove end end |
#preface_main_filter(ret, node) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/metanorma/converter/sectiontype.rb', line 75 def preface_main_filter(ret, node) node.level > 1 and return ret start_main_section(ret, node) @preface && self.class::MAIN_CLAUSE_NAMES.include?(ret) and return nil !@preface && self.class::PREFACE_CLAUSE_NAMES.include?(ret) and return nil ret end |
#role_style(node, value) ⇒ Object
64 65 66 |
# File 'lib/metanorma/converter/sectiontype.rb', line 64 def role_style(node, value) node.role == value || node.attr("style") == value end |
#scope_parse(attrs, xml, node) ⇒ Object
118 119 120 |
# File 'lib/metanorma/converter/section.rb', line 118 def scope_parse(attrs, xml, node) clause_parse(attrs.merge(type: "scope"), xml, node) end |
#section(node) ⇒ Object
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/metanorma/converter/section.rb', line 35 def section(node) a = section_attributes(node) noko do |xml| case sectiontype(node) when "metanorma-extension" (a, xml, node) when "introduction" then introduction_parse(a, xml, node) when "foreword" then foreword_parse(a, xml, node) when "scope" then scope_parse(a, xml, node) when "normative references" then norm_ref_parse(a, xml, node) when "terms and definitions" @term_def = true term_def_parse(a, xml, node, true) @term_def = false when "symbols and abbreviated terms" symbols_parse(symbols_attrs(node, a), xml, node) when "acknowledgements" acknowledgements_parse(a, xml, node) when "executivesummary" executivesummary_parse(a, xml, node) when "bibliography" bibliography_parse(a, xml, node) else if @term_def then term_def_subclause_parse(a, xml, node) elsif @definitions then symbols_parse(a, xml, node) elsif @norm_ref || (node.attr("style") == "bibliography" && sectiontype(node, false) == "normative references") norm_ref_parse(a, xml, node) elsif @biblio || node.attr("style") == "bibliography" bibliography_parse(a, xml, node) elsif node.attr("style") == "abstract" abstract_parse(a, xml, node) elsif node.attr("style") == "index" indexsect_parse(a, xml, node) elsif node.attr("style") == "appendix" && node.level == 1 annex_parse(a, xml, node) else clause_parse(a, xml, node) end end end end |
#section_attributes(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/metanorma/converter/section.rb', line 13 def section_attributes(node) ret = id_unnum_attrs(node).merge( { annex: role_style(node, "appendix") && node.level == 1 ? true : nil, colophon: role_style(node, "colophon") ? true : nil, preface: role_style(node, "preface") ? true : nil }, ) %w(language script branch-number type tag keeptitle multilingual-rendering).each do |k| a = node.attr(k) and ret[k.to_sym] = a end section_attributes_change(node, ret).compact end |
#section_attributes_change(node, ret) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/metanorma/converter/section.rb', line 26 def section_attributes_change(node, ret) node.attributes["change"] or return ret ret.merge(change: node.attributes["change"], path: node.attributes["path"], path_end: node.attributes["path_end"], position: node.attributes["position"], title: node.attributes["title"]) end |
#section_title(xml, title) ⇒ Object
89 90 91 92 |
# File 'lib/metanorma/converter/section.rb', line 89 def section_title(xml, title) title.nil? and return add_noko_elem(xml, "title", title, id_attr(nil)) end |
#sections_clausebefore_cleanup(xmldoc) ⇒ Object
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/metanorma/cleanup/section.rb', line 216 def sections_clausebefore_cleanup(xmldoc) xmldoc.at("//sections") or return ins = insert_before(xmldoc, "//sections") xmldoc.xpath("//sections//*[@beforeclauses = 'true']") .reverse_each do |x| x.delete("beforeclauses") ins.previous = x.remove end endofpreface_clausebefore(xmldoc, ins) end |
#sections_cleanup(xml) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/metanorma/cleanup/section.rb', line 126 def sections_cleanup(xml) sections_order_cleanup(xml) sections_level_cleanup(xml) sections_names_cleanup(xml) sections_variant_title_cleanup(xml) change_clauses(xml) end |
#sections_level_cleanup(xml) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/metanorma/cleanup/section.rb', line 115 def sections_level_cleanup(xml) m = maxlevel(xml) m < 6 and return m.downto(6).each do |l| xml.xpath("//clause[@level = '#{l}']").each do |c| c.delete("level") c.previous_element << c.remove end end end |
#sections_order_cleanup(xml) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/metanorma/cleanup/section.rb', line 86 def sections_order_cleanup(xml) s = xml.at("//sections") pop_floating_title(xml) make_preface(xml, s) make_annexes(xml) make_indexsect(xml, s) make_bibliography(xml, s) make_colophon(xml) xml.xpath("//sections/annex").reverse_each { |r| s.next = r.remove } end |
#sectiontype(node, level = true) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/metanorma/converter/sectiontype.rb', line 14 def sectiontype(node, level = true) ret = sectiontype1(node) ret1 = preface_main_filter(sectiontype_streamline(ret), node) # permit multiple instances ["symbols and abbreviated terms", "metanorma-extension"].include?(ret1) and return ret1 !level || node.level == 1 || node.attr("heading") or return nil !node.attr("heading") && @seen_headers.include?(ret) and return nil @seen_headers << ret unless ret1.nil? @seen_headers_canonical << ret1 unless ret1.nil? ret1 end |
#sectiontype1(node) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/metanorma/converter/sectiontype.rb', line 4 def sectiontype1(node) node.attr("style") == "abstract" and return "abstract" node.attr("heading")&.downcase || node.title .gsub(%r{<index>.*?</index>}m, "") .gsub(%r{<fn[^<>]*>.*?</fn>}m, "") .gsub(/<[^<>]+>/, "") .strip.downcase.sub(/\.$/, "") end |
#sectiontype_streamline(ret) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/metanorma/converter/sectiontype.rb', line 48 def sectiontype_streamline(ret) SECTIONTYPE_STREAMLINE.each do |k, v| v.include?(ret) and return k.to_s end ret end |
#set_obligation(attrs, node) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/metanorma/converter/section.rb', line 79 def set_obligation(attrs, node) attrs[:obligation] = if node.attributes.has_key?("obligation") node.attr("obligation") elsif node.parent.attributes.has_key?("obligation") node.parent.attr("obligation") else "normative" end end |
#single_clause_annex(xml) ⇒ Object
163 164 165 166 167 |
# File 'lib/metanorma/cleanup/section.rb', line 163 def single_clause_annex(xml) xml.xpath("//annex").each do |a| single_clause_annex1(a) end end |
#source_include_cleanup(xml) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/metanorma/cleanup/section.rb', line 143 def source_include_cleanup(xml) xml.xpath("//source-include").each do |s| f = File.join(@localdir, s["path"]) s.remove r = source_sanitise(File.read(f)) xml.root << <<~XML <metanorma-extension-clause> <clause> <title #{add_id_text}>#{s['path']}</title> <source>#{r} </source> </clause> </metanorma-extension-clause> XML end end |
#source_sanitise(code) ⇒ Object
159 160 161 |
# File 'lib/metanorma/cleanup/section.rb', line 159 def source_sanitise(code) code end |
#start_main_section(ret, node) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/metanorma/converter/sectiontype.rb', line 68 def start_main_section(ret, node) role_style(node, "preface") and return @preface = false if self.class::MAIN_CLAUSE_NAMES.include?(ret) @preface = false if self.class::PREFACE_CLAUSE_NAMES .intersection(@seen_headers_canonical + [ret]).empty? end |
#stash_symbols ⇒ Object
59 60 61 62 63 |
# File 'lib/metanorma/converter/terms.rb', line 59 def stash_symbols @stashed_definitions ||= [] @stashed_definitions.push(@definitions) @definitions = false end |
#stash_term_def ⇒ Object
49 50 51 52 53 |
# File 'lib/metanorma/converter/terms.rb', line 49 def stash_term_def @stashed_term_def ||= [] @stashed_term_def.push(@term_def) @term_def = false end |
#support_appendix?(_node) ⇒ Boolean
152 153 154 |
# File 'lib/metanorma/converter/section.rb', line 152 def support_appendix?(_node) false end |
#symbols_attrs(node, attr) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/metanorma/converter/terms.rb', line 14 def symbols_attrs(node, attr) case sectiontype1(node) when "symbols" then attr.merge(type: "symbols") when "abbreviated terms", "abbreviations" attr.merge(type: "abbreviated_terms") else attr end end |
#symbols_parse(attr, xml, node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/metanorma/converter/terms.rb', line 24 def symbols_parse(attr, xml, node) node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node) xml.definitions **attr_code(attr) do |xml_section| section_title(xml_section, node.title) stash_symbols @definitions = true stash_term_def xml_section << node.content pop_symbols pop_term_def end end |
#term_contains_subclauses(node) ⇒ Object
87 88 89 90 |
# File 'lib/metanorma/converter/terms.rb', line 87 def term_contains_subclauses(node) sub = node.find_by(context: :section) { |s| s.level == node.level + 1 } !sub.empty? end |
#term_def_parse(attrs, xml, node, _toplevel) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/metanorma/converter/terms.rb', line 99 def term_def_parse(attrs, xml, node, _toplevel) xml.terms **attr_code(attrs) do |section| section_title(section, node.title) (s = node.attr("source")) && s.split(",").each do |s1| section.termdocsource(nil, **attr_code(bibitemid: s1)) end section << node.content end end |
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
subclause contains subclauses
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/metanorma/converter/terms.rb', line 70 def term_def_subclause_parse(attrs, xml, node) node.role == "nonterm" and return nonterm_term_def_subclause_parse(attrs, xml, node) node.role == "boilerplate" and return terms_boilerplate_parse(attrs, xml, node) @definitions and return symbols_parse(attrs, xml, node) term_contains_subclauses(node) and return term_def_parse(attrs, xml, node, false) case sectiontype(node, false) when "symbols and abbreviated terms" return symbols_parse(attrs, xml, node) when "terms and definitions" return clause_parse(attrs, xml, node) end term_def_subclause_parse1(attrs, xml, node) end |
#term_def_subclause_parse1(attrs, xml, node) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/metanorma/converter/terms.rb', line 92 def term_def_subclause_parse1(attrs, xml, node) xml.term **attr_code(attrs) do |xml_section| term_designation(xml_section, node, "preferred", node.title) xml_section << node.content end end |
#term_designation(xml, _node, tag, text) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/metanorma/converter/terms.rb', line 109 def term_designation(xml, _node, tag, text) xml.send tag do |p| p.expression do |e| add_noko_elem(e, "name", text) end end end |
#termdefinition(node) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/metanorma/converter/terms.rb', line 166 def termdefinition(node) noko do |xml| xml.definition **attr_code(id_attr(nil) .merge(type: node.attr("type"))) do |d| d << node.content end end end |
#terms_boilerplate_parse(attrs, xml, node) ⇒ Object
43 44 45 46 47 |
# File 'lib/metanorma/converter/terms.rb', line 43 def terms_boilerplate_parse(attrs, xml, node) stash_term_def clause_parse(attrs.merge(type: "boilerplate"), xml, node) pop_term_def end |
#termsource(node) ⇒ Object
156 157 158 159 160 161 162 163 164 |
# File 'lib/metanorma/converter/terms.rb', line 156 def termsource(node) matched = extract_termsource_refs(node.content, node) or return noko do |xml| xml.source **termsource_attrs(node, matched) do |xml_t| seen_xref = Nokogiri::XML.fragment(matched[:xref]) add_term_source(node, xml_t, seen_xref, matched) end end end |
#termsource_attrs(node, matched) ⇒ Object
150 151 152 153 154 |
# File 'lib/metanorma/converter/terms.rb', line 150 def termsource_attrs(node, matched) status = node.attr("status")&.downcase || (matched[:text] ? "modified" : "identical") { status: status, type: node.attr("type")&.downcase || "authoritative" } end |
#termsource_origin_attrs(_node, seen_xref) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/metanorma/converter/terms.rb', line 117 def termsource_origin_attrs(_node, seen_xref) { case: seen_xref.children[0]["case"], droploc: seen_xref.children[0]["droploc"], bibitemid: seen_xref.children[0]["target"], style: seen_xref.children[0]["style"], format: seen_xref.children[0]["format"], type: "inline" } end |
#to_preface(preface, clause) ⇒ Object
23 24 25 26 |
# File 'lib/metanorma/cleanup/section.rb', line 23 def to_preface(preface, clause) clause.delete("preface") preface.add_child clause.remove end |