Module: Metanorma::Standoc::Utils
- Included in:
- Cleanup::SpansToBibitem, Converter
- Defined in:
- lib/metanorma/standoc/utils.rb
Defined Under Namespace
Classes: EmptyAttr
Constant Summary collapse
- SUBCLAUSE_XPATH =
"//clause[not(parent::sections)]" \ "[not(ancestor::boilerplate)]".freeze
Class Method Summary collapse
-
.adoc2xml(text, flavour) ⇒ Object
wrapped in <sections>.
Instance Method Summary collapse
- #attr_code(attributes) ⇒ Object
- #convert(node, transform = nil, opts = {}) ⇒ Object
- #csv_split(text, delim = ";") ⇒ Object
- #dl_to_attrs(elem, dlist, name) ⇒ Object
- #dl_to_elems(ins, elem, dlist, name) ⇒ Object
- #document_ns_attributes(_doc) ⇒ Object
- #isodoc(lang, script, locale, i18nyaml = nil) ⇒ Object
- #link_unwrap(para) ⇒ Object
- #noko(&block) ⇒ Object
- #term_expr(elem) ⇒ Object
- #to_xml(node) ⇒ Object
- #wrap_in_para(node, out) ⇒ Object
- #xml_encode(text) ⇒ Object
Class Method Details
.adoc2xml(text, flavour) ⇒ Object
wrapped in <sections>
80 81 82 83 84 85 86 |
# File 'lib/metanorma/standoc/utils.rb', line 80 def adoc2xml(text, flavour) Nokogiri::XML(text).root and return text c = Asciidoctor.convert("= X\nA\n:semantic-metadata-headless: true\n" \ ":novalid:\n\n#{text}\n", backend: flavour, header_footer: true) Nokogiri::XML(c).at("//xmlns:sections") end |
Instance Method Details
#attr_code(attributes) ⇒ Object
24 25 26 |
# File 'lib/metanorma/standoc/utils.rb', line 24 def attr_code(attributes) Metanorma::Utils::attr_code(attributes) end |
#convert(node, transform = nil, opts = {}) ⇒ Object
11 12 13 14 |
# File 'lib/metanorma/standoc/utils.rb', line 11 def convert(node, transform = nil, opts = {}) transform ||= node.node_name opts.empty? ? (send transform, node) : (send transform, node, opts) end |
#csv_split(text, delim = ";") ⇒ Object
28 29 30 |
# File 'lib/metanorma/standoc/utils.rb', line 28 def csv_split(text, delim = ";") Metanorma::Utils::csv_split(text, delim) end |
#dl_to_attrs(elem, dlist, name) ⇒ Object
51 52 53 |
# File 'lib/metanorma/standoc/utils.rb', line 51 def dl_to_attrs(elem, dlist, name) Metanorma::Utils::dl_to_attrs(elem, dlist, name) end |
#dl_to_elems(ins, elem, dlist, name) ⇒ Object
55 56 57 |
# File 'lib/metanorma/standoc/utils.rb', line 55 def dl_to_elems(ins, elem, dlist, name) Metanorma::Utils::dl_to_elems(ins, elem, dlist, name) end |
#document_ns_attributes(_doc) ⇒ Object
16 17 18 |
# File 'lib/metanorma/standoc/utils.rb', line 16 def document_ns_attributes(_doc) nil end |
#isodoc(lang, script, locale, i18nyaml = nil) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/metanorma/standoc/utils.rb', line 44 def isodoc(lang, script, locale, i18nyaml = nil) conv = presentation_xml_converter(EmptyAttr.new) i18n = conv.i18n_init(lang, script, locale, i18nyaml) conv.(lang, script, locale, i18n) conv end |
#link_unwrap(para) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/metanorma/standoc/utils.rb', line 63 def link_unwrap(para) elems = para.elements if elems.size == 1 && elems[0].name == "link" para.at("./link").replace(elems[0]["target"].strip) end para end |
#noko(&block) ⇒ Object
20 21 22 |
# File 'lib/metanorma/standoc/utils.rb', line 20 def noko(&block) Metanorma::Utils::noko(@script, &block) end |
#term_expr(elem) ⇒ Object
59 60 61 |
# File 'lib/metanorma/standoc/utils.rb', line 59 def term_expr(elem) "<expression><name>#{elem}</name></expression>" end |
#to_xml(node) ⇒ Object
36 37 38 39 |
# File 'lib/metanorma/standoc/utils.rb', line 36 def to_xml(node) node.to_xml(encoding: "UTF-8", indent: 2, save_with: Nokogiri::XML::Node::SaveOptions::AS_XML) end |
#wrap_in_para(node, out) ⇒ Object
32 33 34 |
# File 'lib/metanorma/standoc/utils.rb', line 32 def wrap_in_para(node, out) Metanorma::Utils::wrap_in_para(node, out) end |
#xml_encode(text) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/metanorma/standoc/utils.rb', line 71 def xml_encode(text) @c.encode(text, :basic, :hexadecimal) .gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&") .gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&") .gsub(/"/, '"').gsub(/
/, "\n").gsub(/&#/, "&#") .gsub(/'/, "'") end |