metanorma-standoc 2.9.0 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/metanorma/standoc/anchor.rb +3 -3
 - data/lib/metanorma/standoc/base.rb +1 -1
 - data/lib/metanorma/standoc/blocks.rb +5 -5
 - data/lib/metanorma/standoc/blocks_image.rb +1 -1
 - data/lib/metanorma/standoc/blocks_notes.rb +6 -6
 - data/lib/metanorma/standoc/cleanup.rb +15 -0
 - data/lib/metanorma/standoc/cleanup_bibitem.rb +14 -10
 - data/lib/metanorma/standoc/cleanup_block.rb +1 -1
 - data/lib/metanorma/standoc/cleanup_ref.rb +1 -2
 - data/lib/metanorma/standoc/cleanup_section.rb +5 -9
 - data/lib/metanorma/standoc/cleanup_text.rb +1 -1
 - data/lib/metanorma/standoc/cleanup_xref.rb +6 -10
 - data/lib/metanorma/standoc/init.rb +10 -0
 - data/lib/metanorma/standoc/inline.rb +5 -5
 - data/lib/metanorma/standoc/isodoc.rng +5 -5
 - data/lib/metanorma/standoc/lists.rb +4 -4
 - data/lib/metanorma/standoc/macros.rb +15 -44
 - data/lib/metanorma/standoc/macros_embed.rb +14 -12
 - data/lib/metanorma/standoc/ref.rb +9 -12
 - data/lib/metanorma/standoc/ref_queue.rb +6 -8
 - data/lib/metanorma/standoc/ref_utility.rb +2 -2
 - data/lib/metanorma/standoc/section.rb +3 -3
 - data/lib/metanorma/standoc/terms.rb +2 -2
 - data/lib/metanorma/standoc/validate.rb +14 -2
 - data/lib/metanorma/standoc/version.rb +1 -1
 - data/metanorma-standoc.gemspec +3 -1
 - metadata +32 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: afbcf21ea1b8e99868178616c755a4dcef811f631326c65f6835ad491d1f2835
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9d3499adf6025521d2683f4456e64b1cd27dd63722c231de8fab7aa47fe79973
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 46a8beb31cb6230dccdcdb36352dd05e705a3114d0b1b6e04b46b1a445aa1fe30249426c81be8a441f615c95fe633cc078bd70c030616cdc25ff4c50eb45ab76
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 300aeca29fa514e88535c4f60577f9a6e83446f195b76e7e15029ae912d0beb06c0f6f028b098e4662ab53fbf83fc8e675a920ef7c3269f1e501afa835ba127f
         
     | 
| 
         @@ -34,7 +34,7 @@ module Metanorma 
     | 
|
| 
       34 
34 
     | 
    
         
             
                    t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
         
     | 
| 
       35 
35 
     | 
    
         
             
                    attrs, text = inline_anchor_xref_match(text)
         
     | 
| 
       36 
36 
     | 
    
         
             
                    attrs.empty? and
         
     | 
| 
       37 
     | 
    
         
            -
                      return { target: t, type: "inline", text 
     | 
| 
      
 37 
     | 
    
         
            +
                      return { target: t, type: "inline", text:, style: @xrefstyle }
         
     | 
| 
       38 
38 
     | 
    
         
             
                    inline_anchor_xref_attrs1(attrs, t, text)
         
     | 
| 
       39 
39 
     | 
    
         
             
                  end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
         @@ -46,13 +46,13 @@ module Metanorma 
     | 
|
| 
       46 
46 
     | 
    
         
             
                  end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
                  def inline_anchor_xref_attrs1(attrs, target, text)
         
     | 
| 
       49 
     | 
    
         
            -
                    { target 
     | 
| 
      
 49 
     | 
    
         
            +
                    { target:, hidden: attrs["hidden"],
         
     | 
| 
       50 
50 
     | 
    
         
             
                      type: attrs.key?("fn") ? "footnote" : "inline",
         
     | 
| 
       51 
51 
     | 
    
         
             
                      case: %w(capital lowercase).detect { |x| attrs.key?(x) },
         
     | 
| 
       52 
52 
     | 
    
         
             
                      label: attrs["label"],
         
     | 
| 
       53 
53 
     | 
    
         
             
                      style: attrs["style"] || @xrefstyle,
         
     | 
| 
       54 
54 
     | 
    
         
             
                      droploc: attrs.key?("droploc") ? true : nil,
         
     | 
| 
       55 
     | 
    
         
            -
                      text:  
     | 
| 
      
 55 
     | 
    
         
            +
                      text: }.compact
         
     | 
| 
       56 
56 
     | 
    
         
             
                  end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
                  XREF_ATTRS = "hidden|style|droploc|capital|lowercase|label".freeze
         
     | 
| 
         @@ -130,7 +130,7 @@ module Metanorma 
     | 
|
| 
       130 
130 
     | 
    
         
             
                      %w(presentation semantic).each do |t|
         
     | 
| 
       131 
131 
     | 
    
         
             
                        /^#{t}-metadata-/.match?(k) or next
         
     | 
| 
       132 
132 
     | 
    
         
             
                        k = k.sub(/^#{t}-metadata-/, "")
         
     | 
| 
       133 
     | 
    
         
            -
                         
     | 
| 
      
 133 
     | 
    
         
            +
                        quoted_csv_split(v)&.each do |c|
         
     | 
| 
       134 
134 
     | 
    
         
             
                          ret << "<#{t}-metadata><#{k}>#{c}</#{k}></#{t}-metadata>"
         
     | 
| 
       135 
135 
     | 
    
         
             
                        end
         
     | 
| 
       136 
136 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -90,7 +90,7 @@ module Metanorma 
     | 
|
| 
       90 
90 
     | 
    
         
             
                        )) do |ex|
         
     | 
| 
       91 
91 
     | 
    
         
             
                        wrap_in_para(node, ex)
         
     | 
| 
       92 
92 
     | 
    
         
             
                      end
         
     | 
| 
       93 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 93 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       94 
94 
     | 
    
         
             
                  end
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
96 
     | 
    
         
             
                  def example(node)
         
     | 
| 
         @@ -128,7 +128,7 @@ module Metanorma 
     | 
|
| 
       128 
128 
     | 
    
         
             
                        figure_title(node, ex)
         
     | 
| 
       129 
129 
     | 
    
         
             
                        wrap_in_para(node, ex)
         
     | 
| 
       130 
130 
     | 
    
         
             
                      end
         
     | 
| 
       131 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 131 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       132 
132 
     | 
    
         
             
                  end
         
     | 
| 
       133 
133 
     | 
    
         | 
| 
       134 
134 
     | 
    
         
             
                  def example_attrs(node)
         
     | 
| 
         @@ -141,7 +141,7 @@ module Metanorma 
     | 
|
| 
       141 
141 
     | 
    
         
             
                        node.title.nil? or ex.name { |name| name << node.title }
         
     | 
| 
       142 
142 
     | 
    
         
             
                        wrap_in_para(node, ex)
         
     | 
| 
       143 
143 
     | 
    
         
             
                      end
         
     | 
| 
       144 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 144 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       145 
145 
     | 
    
         
             
                  end
         
     | 
| 
       146 
146 
     | 
    
         | 
| 
       147 
147 
     | 
    
         
             
                  def para_attrs(node)
         
     | 
| 
         @@ -158,7 +158,7 @@ module Metanorma 
     | 
|
| 
       158 
158 
     | 
    
         
             
                      xml.p **para_attrs(node) do |xml_t|
         
     | 
| 
       159 
159 
     | 
    
         
             
                        xml_t << node.content
         
     | 
| 
       160 
160 
     | 
    
         
             
                      end
         
     | 
| 
       161 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 161 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       162 
162 
     | 
    
         
             
                  end
         
     | 
| 
       163 
163 
     | 
    
         | 
| 
       164 
164 
     | 
    
         
             
                  def quote_attrs(node)
         
     | 
| 
         @@ -183,7 +183,7 @@ module Metanorma 
     | 
|
| 
       183 
183 
     | 
    
         
             
                        quote_attribution(node, q)
         
     | 
| 
       184 
184 
     | 
    
         
             
                        wrap_in_para(node, q)
         
     | 
| 
       185 
185 
     | 
    
         
             
                      end
         
     | 
| 
       186 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 186 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       187 
187 
     | 
    
         
             
                  end
         
     | 
| 
       188 
188 
     | 
    
         | 
| 
       189 
189 
     | 
    
         
             
                  def listing_attrs(node)
         
     | 
| 
         @@ -32,7 +32,7 @@ module Metanorma 
     | 
|
| 
       32 
32 
     | 
    
         
             
                      xml.review **sidebar_attrs(node) do |r|
         
     | 
| 
       33 
33 
     | 
    
         
             
                        wrap_in_para(node, r)
         
     | 
| 
       34 
34 
     | 
    
         
             
                      end
         
     | 
| 
       35 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 35 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                  def todo_attrs(node)
         
     | 
| 
         @@ -41,7 +41,7 @@ module Metanorma 
     | 
|
| 
       41 
41 
     | 
    
         
             
                    attr_code(id_attr(node)
         
     | 
| 
       42 
42 
     | 
    
         
             
                      .merge(reviewer: node.attr("reviewer") || node.attr("source") ||
         
     | 
| 
       43 
43 
     | 
    
         
             
                             "(Unknown)",
         
     | 
| 
       44 
     | 
    
         
            -
                             date 
     | 
| 
      
 44 
     | 
    
         
            +
                             date:, type: "todo"))
         
     | 
| 
       45 
45 
     | 
    
         
             
                  end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  def todo(node)
         
     | 
| 
         @@ -49,7 +49,7 @@ module Metanorma 
     | 
|
| 
       49 
49 
     | 
    
         
             
                      xml.review **todo_attrs(node) do |r|
         
     | 
| 
       50 
50 
     | 
    
         
             
                        wrap_in_para(node, r)
         
     | 
| 
       51 
51 
     | 
    
         
             
                      end
         
     | 
| 
       52 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 52 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                  def termnote(node)
         
     | 
| 
         @@ -57,7 +57,7 @@ module Metanorma 
     | 
|
| 
       57 
57 
     | 
    
         
             
                      xml.termnote **termnote_attrs(node) do |ex|
         
     | 
| 
       58 
58 
     | 
    
         
             
                        wrap_in_para(node, ex)
         
     | 
| 
       59 
59 
     | 
    
         
             
                      end
         
     | 
| 
       60 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 60 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       61 
61 
     | 
    
         
             
                  end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
                  def note(node)
         
     | 
| 
         @@ -67,7 +67,7 @@ module Metanorma 
     | 
|
| 
       67 
67 
     | 
    
         
             
                      xml.note **note_attrs(node) do |c|
         
     | 
| 
       68 
68 
     | 
    
         
             
                        wrap_in_para(node, c)
         
     | 
| 
       69 
69 
     | 
    
         
             
                      end
         
     | 
| 
       70 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 70 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       71 
71 
     | 
    
         
             
                  end
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                  def boilerplate_note(node)
         
     | 
| 
         @@ -101,7 +101,7 @@ module Metanorma 
     | 
|
| 
       101 
101 
     | 
    
         
             
                        node.title.nil? or a.name { |name| name << node.title }
         
     | 
| 
       102 
102 
     | 
    
         
             
                        wrap_in_para(node, a)
         
     | 
| 
       103 
103 
     | 
    
         
             
                      end
         
     | 
| 
       104 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 104 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       105 
105 
     | 
    
         
             
                  end
         
     | 
| 
       106 
106 
     | 
    
         | 
| 
       107 
107 
     | 
    
         
             
                  def admonition_alternatives(node)
         
     | 
| 
         @@ -64,6 +64,7 @@ module Metanorma 
     | 
|
| 
       64 
64 
     | 
    
         
             
                    bookmark_cleanup(xmldoc)
         
     | 
| 
       65 
65 
     | 
    
         
             
                    termdef_cleanup(xmldoc) # feeds: relaton_iev_cleanup, term_index_cleanup
         
     | 
| 
       66 
66 
     | 
    
         
             
                    relaton_iev_cleanup(xmldoc)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    relaton_log_cleanup(xmldoc)
         
     | 
| 
       67 
68 
     | 
    
         
             
                    element_name_cleanup(xmldoc)
         
     | 
| 
       68 
69 
     | 
    
         
             
                    term_index_cleanup(xmldoc)
         
     | 
| 
       69 
70 
     | 
    
         
             
                    bpart_cleanup(xmldoc)
         
     | 
| 
         @@ -97,6 +98,20 @@ module Metanorma 
     | 
|
| 
       97 
98 
     | 
    
         
             
                    end
         
     | 
| 
       98 
99 
     | 
    
         
             
                  end
         
     | 
| 
       99 
100 
     | 
    
         | 
| 
      
 101 
     | 
    
         
            +
                  RELATON_SEVERITIES =
         
     | 
| 
      
 102 
     | 
    
         
            +
                    { "INFO": 3, "WARN": 2, "ERROR": 1, "FATAL": 0,
         
     | 
| 
      
 103 
     | 
    
         
            +
                      "UNKNOWN": 3 }.freeze
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                  def relaton_log_cleanup(_xmldoc)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    @relaton_log or return
         
     | 
| 
      
 107 
     | 
    
         
            +
                    @relaton_log.rewind
         
     | 
| 
      
 108 
     | 
    
         
            +
                    @relaton_log.string.split(/(?<=})\n(?={)/).each do |l|
         
     | 
| 
      
 109 
     | 
    
         
            +
                      e = JSON.parse(l)
         
     | 
| 
      
 110 
     | 
    
         
            +
                      @log.add("Relaton", e["key"], e["message"],
         
     | 
| 
      
 111 
     | 
    
         
            +
                               severity: RELATON_SEVERITIES[e["severity"].to_sym])
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end
         
     | 
| 
      
 113 
     | 
    
         
            +
                  end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
       100 
115 
     | 
    
         
             
                  def docidentifier_cleanup(xmldoc); end
         
     | 
| 
       101 
116 
     | 
    
         | 
| 
       102 
117 
     | 
    
         
             
                  TEXT_ELEMS =
         
     | 
| 
         @@ -36,7 +36,7 @@ module Metanorma 
     | 
|
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                  def extract_notes_from_biblio(refs)
         
     | 
| 
       38 
38 
     | 
    
         
             
                    refs.xpath("./bibitem").each do |r|
         
     | 
| 
       39 
     | 
    
         
            -
                      r.xpath("./note[@appended]"). 
     | 
| 
      
 39 
     | 
    
         
            +
                      r.xpath("./note[@appended]").reverse_each do |n|
         
     | 
| 
       40 
40 
     | 
    
         
             
                        n.delete("appended")
         
     | 
| 
       41 
41 
     | 
    
         
             
                        r.next = n
         
     | 
| 
       42 
42 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -147,34 +147,38 @@ module Metanorma 
     | 
|
| 
       147 
147 
     | 
    
         | 
| 
       148 
148 
     | 
    
         
             
                  def save_attachment(path, bib)
         
     | 
| 
       149 
149 
     | 
    
         
             
                    init_attachments
         
     | 
| 
      
 150 
     | 
    
         
            +
                    path = File.join(@localdir, path)
         
     | 
| 
       150 
151 
     | 
    
         
             
                    valid_attachment?(path, bib) or return ""
         
     | 
| 
       151 
152 
     | 
    
         
             
                    f = File.basename(path)
         
     | 
| 
       152 
153 
     | 
    
         
             
                    File.exist?(File.join(@attachmentsdir, f)) and
         
     | 
| 
       153 
154 
     | 
    
         
             
                      f += "_#{UUIDTools::UUID.random_create}"
         
     | 
| 
       154 
     | 
    
         
            -
                     
     | 
| 
       155 
     | 
    
         
            -
                    FileUtils.cp(path,  
     | 
| 
       156 
     | 
    
         
            -
                    datauri_attachment( 
     | 
| 
       157 
     | 
    
         
            -
                     
     | 
| 
      
 155 
     | 
    
         
            +
                    out_fld = File.join(@attachmentsdir, f)
         
     | 
| 
      
 156 
     | 
    
         
            +
                    FileUtils.cp(path, out_fld)
         
     | 
| 
      
 157 
     | 
    
         
            +
                    datauri_attachment(out_fld, bib.document)
         
     | 
| 
      
 158 
     | 
    
         
            +
                    File.join(@attachmentsfld, f)
         
     | 
| 
       158 
159 
     | 
    
         
             
                  end
         
     | 
| 
       159 
160 
     | 
    
         | 
| 
       160 
161 
     | 
    
         
             
                  def datauri_attachment(path, doc)
         
     | 
| 
       161 
162 
     | 
    
         
             
                    @datauriattachment or return
         
     | 
| 
       162 
     | 
    
         
            -
                     
     | 
| 
      
 163 
     | 
    
         
            +
                    m = add_misc_container(doc)
         
     | 
| 
       163 
164 
     | 
    
         
             
                    f = File.basename(path)
         
     | 
| 
       164 
     | 
    
         
            -
                    d = Vectory::Utils 
     | 
| 
       165 
     | 
    
         
            -
                     
     | 
| 
      
 165 
     | 
    
         
            +
                    d = Vectory::Utils::datauri(path, @localdir)
         
     | 
| 
      
 166 
     | 
    
         
            +
                    m << "<attachment name='#{f}'/>"
         
     | 
| 
      
 167 
     | 
    
         
            +
                    m.last_element_child << d
         
     | 
| 
       166 
168 
     | 
    
         
             
                  end
         
     | 
| 
       167 
169 
     | 
    
         | 
| 
       168 
170 
     | 
    
         
             
                  def valid_attachment?(path, bib)
         
     | 
| 
       169 
171 
     | 
    
         
             
                    File.exist?(path) and return true
         
     | 
| 
       170 
     | 
    
         
            -
                     
     | 
| 
      
 172 
     | 
    
         
            +
                    p = Pathname.new(path).cleanpath
         
     | 
| 
      
 173 
     | 
    
         
            +
                    @log.add("Bibliography", bib, "Attachment #{p} does not exist",
         
     | 
| 
       171 
174 
     | 
    
         
             
                             severity: 0)
         
     | 
| 
       172 
175 
     | 
    
         
             
                    false
         
     | 
| 
       173 
176 
     | 
    
         
             
                  end
         
     | 
| 
       174 
177 
     | 
    
         | 
| 
       175 
178 
     | 
    
         
             
                  def init_attachments
         
     | 
| 
       176 
179 
     | 
    
         
             
                    @attachmentsdir and return
         
     | 
| 
       177 
     | 
    
         
            -
                    @ 
     | 
| 
      
 180 
     | 
    
         
            +
                    @attachmentsfld = "_#{@filename}_attachments"
         
     | 
| 
      
 181 
     | 
    
         
            +
                    @attachmentsdir = File.join(@output_dir, @attachmentsfld)
         
     | 
| 
       178 
182 
     | 
    
         
             
                    FileUtils.rm_rf(@attachmentsdir)
         
     | 
| 
       179 
183 
     | 
    
         
             
                    FileUtils.mkdir_p(@attachmentsdir)
         
     | 
| 
       180 
184 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -163,7 +163,7 @@ module Metanorma 
     | 
|
| 
       163 
163 
     | 
    
         
             
                      acc << safe_noko(a[0], node.document)
         
     | 
| 
       164 
164 
     | 
    
         
             
                      a.size == 4 or next
         
     | 
| 
       165 
165 
     | 
    
         
             
                      acc << Asciidoctor.convert(
         
     | 
| 
       166 
     | 
    
         
            -
                        a[2], doctype: :inline, backend:  
     | 
| 
      
 166 
     | 
    
         
            +
                        a[2], doctype: :inline, backend: self&.backend&.to_sym || :standoc
         
     | 
| 
       167 
167 
     | 
    
         
             
                      )
         
     | 
| 
       168 
168 
     | 
    
         
             
                    end.join
         
     | 
| 
       169 
169 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,4 +1,3 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "set"
         
     | 
| 
       2 
1 
     | 
    
         
             
            require "relaton_bib"
         
     | 
| 
       3 
2 
     | 
    
         
             
            require_relative "merge_bibitems"
         
     | 
| 
       4 
3 
     | 
    
         
             
            require_relative "spans_to_bibitem"
         
     | 
| 
         @@ -18,7 +17,7 @@ module Metanorma 
     | 
|
| 
       18 
17 
     | 
    
         
             
                    bib = sort_biblio(refs.xpath("./bibitem"))
         
     | 
| 
       19 
18 
     | 
    
         
             
                    insert = refs.at("./bibitem")&.previous_element
         
     | 
| 
       20 
19 
     | 
    
         
             
                    refs.xpath("./bibitem").each(&:remove)
         
     | 
| 
       21 
     | 
    
         
            -
                    bib. 
     | 
| 
      
 20 
     | 
    
         
            +
                    bib.reverse_each do |b|
         
     | 
| 
       22 
21 
     | 
    
         
             
                      (insert and insert.next = b.to_xml) or
         
     | 
| 
       23 
22 
     | 
    
         
             
                        refs.children.first.add_previous_sibling b.to_xml
         
     | 
| 
       24 
23 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -16,9 +16,7 @@ module Metanorma 
     | 
|
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                  def move_clauses_into_preface(xml, preface)
         
     | 
| 
       19 
     | 
    
         
            -
                    xml.xpath("//*[@preface]").each  
     | 
| 
       20 
     | 
    
         
            -
                      to_preface(preface, c)
         
     | 
| 
       21 
     | 
    
         
            -
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                    xml.xpath("//*[@preface]").each { |c| to_preface(preface, c) }
         
     | 
| 
       22 
20 
     | 
    
         
             
                  end
         
     | 
| 
       23 
21 
     | 
    
         | 
| 
       24 
22 
     | 
    
         
             
                  def to_preface(preface, clause)
         
     | 
| 
         @@ -202,10 +200,9 @@ module Metanorma 
     | 
|
| 
       202 
200 
     | 
    
         
             
                  end
         
     | 
| 
       203 
201 
     | 
    
         | 
| 
       204 
202 
     | 
    
         
             
                  # only move clausebefore notes at the very end of preface
         
     | 
| 
       205 
     | 
    
         
            -
                  def endofpreface_clausebefore( 
     | 
| 
       206 
     | 
    
         
            -
                     
     | 
| 
       207 
     | 
    
         
            -
                      . 
     | 
| 
       208 
     | 
    
         
            -
                      textafter = xmldoc.xpath("//preface//*") & x.xpath("./following::*")
         
     | 
| 
      
 203 
     | 
    
         
            +
                  def endofpreface_clausebefore(xml, ins)
         
     | 
| 
      
 204 
     | 
    
         
            +
                    xml.xpath("//preface//*[@beforeclauses = 'true']").reverse.each do |x|
         
     | 
| 
      
 205 
     | 
    
         
            +
                      textafter = xml.xpath("//preface//*") & x.xpath("./following::*")
         
     | 
| 
       209 
206 
     | 
    
         
             
                      textafter.text.strip.empty? or break
         
     | 
| 
       210 
207 
     | 
    
         
             
                      x.delete("beforeclauses")
         
     | 
| 
       211 
208 
     | 
    
         
             
                      ins.previous = x.remove
         
     | 
| 
         @@ -241,9 +238,8 @@ module Metanorma 
     | 
|
| 
       241 
238 
     | 
    
         
             
                  def floating_title_preface2sections(xmldoc)
         
     | 
| 
       242 
239 
     | 
    
         
             
                    t = xmldoc.at("//preface/floating-title") or return
         
     | 
| 
       243 
240 
     | 
    
         
             
                    s = xmldoc.at("//sections")
         
     | 
| 
       244 
     | 
    
         
            -
                     
     | 
| 
      
 241 
     | 
    
         
            +
                    t.next_element or
         
     | 
| 
       245 
242 
     | 
    
         
             
                      s.children.first.previous = t.remove
         
     | 
| 
       246 
     | 
    
         
            -
                    end
         
     | 
| 
       247 
243 
     | 
    
         
             
                  end
         
     | 
| 
       248 
244 
     | 
    
         
             
                end
         
     | 
| 
       249 
245 
     | 
    
         
             
              end
         
     | 
| 
         @@ -35,7 +35,7 @@ module Metanorma 
     | 
|
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                  IGNORE_QUOTES_ELEMENTS =
         
     | 
| 
       37 
37 
     | 
    
         
             
                    %w(pre tt sourcecode stem asciimath figure bibdata passthrough
         
     | 
| 
       38 
     | 
    
         
            -
                       identifier  
     | 
| 
      
 38 
     | 
    
         
            +
                       identifier metanorma-extension).freeze
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                  def uninterrupt_quotes_around_xml_skip(elem)
         
     | 
| 
       41 
41 
     | 
    
         
             
                    !(/\A['"]/.match?(elem.text) &&
         
     | 
| 
         @@ -95,10 +95,9 @@ module Metanorma 
     | 
|
| 
       95 
95 
     | 
    
         
             
                    elem.xpath("./localityStack").size < 2 and return
         
     | 
| 
       96 
96 
     | 
    
         
             
                    elem.xpath("./localityStack[not(@connective)]").each do |l|
         
     | 
| 
       97 
97 
     | 
    
         
             
                      n = l.next_element
         
     | 
| 
       98 
     | 
    
         
            -
                      l["connective"] =  
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
                                        else "and" end
         
     | 
| 
      
 98 
     | 
    
         
            +
                      l["connective"] = "and"
         
     | 
| 
      
 99 
     | 
    
         
            +
                      n && n.name == "localityStack" && n["connective"] == "to" and
         
     | 
| 
      
 100 
     | 
    
         
            +
                        l["connective"] = "from"
         
     | 
| 
       102 
101 
     | 
    
         
             
                    end
         
     | 
| 
       103 
102 
     | 
    
         
             
                  end
         
     | 
| 
       104 
103 
     | 
    
         | 
| 
         @@ -111,8 +110,7 @@ module Metanorma 
     | 
|
| 
       111 
110 
     | 
    
         
             
                    elem.name = name
         
     | 
| 
       112 
111 
     | 
    
         
             
                    elem["bibitemid"] = elem["target"]
         
     | 
| 
       113 
112 
     | 
    
         
             
                    if ref = @anchors&.dig(elem["target"], :xref)
         
     | 
| 
       114 
     | 
    
         
            -
                      t = @anchors.dig(elem["target"], :id, elem["style"]) and
         
     | 
| 
       115 
     | 
    
         
            -
                        ref = t
         
     | 
| 
      
 113 
     | 
    
         
            +
                      t = @anchors.dig(elem["target"], :id, elem["style"]) and ref = t
         
     | 
| 
       116 
114 
     | 
    
         
             
                      elem["citeas"] = @c.decode(ref)
         
     | 
| 
       117 
115 
     | 
    
         
             
                    else xref_to_eref1(elem)
         
     | 
| 
       118 
116 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -141,9 +139,7 @@ module Metanorma 
     | 
|
| 
       141 
139 
     | 
    
         
             
                      e.name = "erefstack"
         
     | 
| 
       142 
140 
     | 
    
         
             
                      e.delete("bibitemid")
         
     | 
| 
       143 
141 
     | 
    
         
             
                      e.delete("citeas")
         
     | 
| 
       144 
     | 
    
         
            -
                      e.xpath("./eref").each  
     | 
| 
       145 
     | 
    
         
            -
                        e1["type"] = e["type"]
         
     | 
| 
       146 
     | 
    
         
            -
                      end
         
     | 
| 
      
 142 
     | 
    
         
            +
                      e.xpath("./eref").each { |e1| e1["type"] = e["type"] }
         
     | 
| 
       147 
143 
     | 
    
         
             
                      e.delete("type")
         
     | 
| 
       148 
144 
     | 
    
         
             
                    end
         
     | 
| 
       149 
145 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -219,7 +215,7 @@ module Metanorma 
     | 
|
| 
       219 
215 
     | 
    
         
             
                    unless a.size < 2 || a[0].empty? || a[1].empty?
         
     | 
| 
       220 
216 
     | 
    
         
             
                      elem["target"] = "#{a[0]}_#{a[1]}"
         
     | 
| 
       221 
217 
     | 
    
         
             
                      a.size > 2 and
         
     | 
| 
       222 
     | 
    
         
            -
                        elem.children = %{anchor="#{a[2 
     | 
| 
      
 218 
     | 
    
         
            +
                        elem.children = %{anchor="#{a[2..].join}",#{elem.children&.text}}
         
     | 
| 
       223 
219 
     | 
    
         
             
                      elem["type"] = a[0]
         
     | 
| 
       224 
220 
     | 
    
         
             
                      @internal_eref_namespaces << a[0]
         
     | 
| 
       225 
221 
     | 
    
         
             
                      xref_to_eref(elem, "eref")
         
     | 
| 
         @@ -49,6 +49,7 @@ module Metanorma 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
         
     | 
| 
       50 
50 
     | 
    
         
             
                    @datauriimage = node.attr("data-uri-image") != "false"
         
     | 
| 
       51 
51 
     | 
    
         
             
                    @datauriattachment = node.attr("data-uri-attachment") != "false"
         
     | 
| 
      
 52 
     | 
    
         
            +
                    @dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013
         
     | 
| 
       52 
53 
     | 
    
         
             
                    @blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
         
     | 
| 
       53 
54 
     | 
    
         
             
                      .map(&:strip)
         
     | 
| 
       54 
55 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -102,6 +103,7 @@ module Metanorma 
     | 
|
| 
       102 
103 
     | 
    
         
             
                  def init_biblio(node)
         
     | 
| 
       103 
104 
     | 
    
         
             
                    @no_isobib_cache = node.attr("no-isobib-cache")
         
     | 
| 
       104 
105 
     | 
    
         
             
                    @no_isobib = node.attr("no-isobib")
         
     | 
| 
      
 106 
     | 
    
         
            +
                    init_bib_log
         
     | 
| 
       105 
107 
     | 
    
         
             
                    @bibdb = nil
         
     | 
| 
       106 
108 
     | 
    
         
             
                    init_bib_caches(node)
         
     | 
| 
       107 
109 
     | 
    
         
             
                    init_iev_caches(node)
         
     | 
| 
         @@ -109,6 +111,14 @@ module Metanorma 
     | 
|
| 
       109 
111 
     | 
    
         
             
                      ::Metanorma::Standoc::LocalBiblio.new(node, @localdir, self)
         
     | 
| 
       110 
112 
     | 
    
         
             
                  end
         
     | 
| 
       111 
113 
     | 
    
         | 
| 
      
 114 
     | 
    
         
            +
                  def init_bib_log
         
     | 
| 
      
 115 
     | 
    
         
            +
                    @relaton_log = StringIO.new
         
     | 
| 
      
 116 
     | 
    
         
            +
                    relaton_logger = Relaton::Logger::Log
         
     | 
| 
      
 117 
     | 
    
         
            +
                      .new(@relaton_log, levels: %i(info warn error fatal unknown),
         
     | 
| 
      
 118 
     | 
    
         
            +
                                         formatter: Relaton::Logger::FormatterJSON)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    Relaton.logger_pool[:my_logger] = relaton_logger
         
     | 
| 
      
 120 
     | 
    
         
            +
                  end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
       112 
122 
     | 
    
         
             
                  def init_math(node)
         
     | 
| 
       113 
123 
     | 
    
         
             
                    @keepasciimath = node.attr("mn-keep-asciimath") &&
         
     | 
| 
       114 
124 
     | 
    
         
             
                      node.attr("mn-keep-asciimath") != "false"
         
     | 
| 
         @@ -43,21 +43,21 @@ module Metanorma 
     | 
|
| 
       43 
43 
     | 
    
         
             
                    if /<([^:>&]+:)?math(\s+[^>&]+)?> |
         
     | 
| 
       44 
44 
     | 
    
         
             
                      <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
         
     | 
| 
       45 
45 
     | 
    
         
             
                      math = xml_encode(text)
         
     | 
| 
       46 
     | 
    
         
            -
                      xml.stem 
     | 
| 
      
 46 
     | 
    
         
            +
                      xml.stem(type: "MathML", block:) do |s|
         
     | 
| 
       47 
47 
     | 
    
         
             
                        s << math
         
     | 
| 
       48 
48 
     | 
    
         
             
                      end
         
     | 
| 
       49 
49 
     | 
    
         
             
                    elsif style == :latexmath then latex_parse(text, xml, block)
         
     | 
| 
       50 
50 
     | 
    
         
             
                    else
         
     | 
| 
       51 
     | 
    
         
            -
                      xml.stem text&.gsub("&#", "&#"), type: "AsciiMath", block: 
     | 
| 
      
 51 
     | 
    
         
            +
                      xml.stem text&.gsub("&#", "&#"), type: "AsciiMath", block:
         
     | 
| 
       52 
52 
     | 
    
         
             
                    end
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                  def latex_parse(text, xml, block)
         
     | 
| 
       56 
56 
     | 
    
         
             
                    latex = latex_parse1(text, block) or
         
     | 
| 
       57 
     | 
    
         
            -
                      return xml.stem 
     | 
| 
       58 
     | 
    
         
            -
                    xml.stem 
     | 
| 
      
 57 
     | 
    
         
            +
                      return xml.stem(type: "MathML", block:)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    xml.stem(type: "MathML", block:) do |s|
         
     | 
| 
       59 
59 
     | 
    
         
             
                      math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                          .elements[0]
         
     | 
| 
       61 
61 
     | 
    
         
             
                      math.delete("alttext")
         
     | 
| 
       62 
62 
     | 
    
         
             
                      s.parent.children = math
         
     | 
| 
       63 
63 
     | 
    
         
             
                      s << "<latexmath>#{text}</latexmath>"
         
     | 
| 
         @@ -17,7 +17,7 @@ 
     | 
|
| 
       17 
17 
     | 
    
         
             
              these elements; we just want one namespace for any child grammars
         
     | 
| 
       18 
18 
     | 
    
         
             
              of this.
         
     | 
| 
       19 
19 
     | 
    
         
             
            -->
         
     | 
| 
       20 
     | 
    
         
            -
            <!-- VERSION v1.3. 
     | 
| 
      
 20 
     | 
    
         
            +
            <!-- VERSION v1.3.3 -->
         
     | 
| 
       21 
21 
     | 
    
         
             
            <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
         
     | 
| 
       22 
22 
     | 
    
         
             
              <include href="reqt.rng"/>
         
     | 
| 
       23 
23 
     | 
    
         
             
              <include href="basicdoc.rng">
         
     | 
| 
         @@ -331,9 +331,9 @@ 
     | 
|
| 
       331 
331 
     | 
    
         
             
                  <zeroOrMore>
         
     | 
| 
       332 
332 
     | 
    
         
             
                    <ref name="table-note"/>
         
     | 
| 
       333 
333 
     | 
    
         
             
                  </zeroOrMore>
         
     | 
| 
       334 
     | 
    
         
            -
                  < 
     | 
| 
      
 334 
     | 
    
         
            +
                  <zeroOrMore>
         
     | 
| 
       335 
335 
     | 
    
         
             
                    <ref name="source"/>
         
     | 
| 
       336 
     | 
    
         
            -
                  </ 
     | 
| 
      
 336 
     | 
    
         
            +
                  </zeroOrMore>
         
     | 
| 
       337 
337 
     | 
    
         
             
                </define>
         
     | 
| 
       338 
338 
     | 
    
         
             
                <define name="FigureAttr">
         
     | 
| 
       339 
339 
     | 
    
         
             
                  <optional>
         
     | 
| 
         @@ -380,9 +380,9 @@ 
     | 
|
| 
       380 
380 
     | 
    
         
             
                  <zeroOrMore>
         
     | 
| 
       381 
381 
     | 
    
         
             
                    <ref name="note"/>
         
     | 
| 
       382 
382 
     | 
    
         
             
                  </zeroOrMore>
         
     | 
| 
       383 
     | 
    
         
            -
                  < 
     | 
| 
      
 383 
     | 
    
         
            +
                  <zeroOrMore>
         
     | 
| 
       384 
384 
     | 
    
         
             
                    <ref name="source"/>
         
     | 
| 
       385 
     | 
    
         
            -
                  </ 
     | 
| 
      
 385 
     | 
    
         
            +
                  </zeroOrMore>
         
     | 
| 
       386 
386 
     | 
    
         
             
                </define>
         
     | 
| 
       387 
387 
     | 
    
         
             
                <define name="source">
         
     | 
| 
       388 
388 
     | 
    
         
             
                  <element name="source">
         
     | 
| 
         @@ -41,7 +41,7 @@ module Metanorma 
     | 
|
| 
       41 
41 
     | 
    
         
             
                        list_caption(node, xml_ul)
         
     | 
| 
       42 
42 
     | 
    
         
             
                        node.items.each { |item| ul_li(xml_ul, item) }
         
     | 
| 
       43 
43 
     | 
    
         
             
                      end
         
     | 
| 
       44 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 44 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       45 
45 
     | 
    
         
             
                  end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  def olist_style(style)
         
     | 
| 
         @@ -67,7 +67,7 @@ module Metanorma 
     | 
|
| 
       67 
67 
     | 
    
         
             
                        list_caption(node, xml_ol)
         
     | 
| 
       68 
68 
     | 
    
         
             
                        node.items.each { |item| li(xml_ol, item) }
         
     | 
| 
       69 
69 
     | 
    
         
             
                      end
         
     | 
| 
       70 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 70 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       71 
71 
     | 
    
         
             
                  end
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
73 
     | 
    
         
             
                  def dt(terms, xml_dl)
         
     | 
| 
         @@ -107,7 +107,7 @@ module Metanorma 
     | 
|
| 
       107 
107 
     | 
    
         
             
                          dd(dd, xml_dl)
         
     | 
| 
       108 
108 
     | 
    
         
             
                        end
         
     | 
| 
       109 
109 
     | 
    
         
             
                      end
         
     | 
| 
       110 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 110 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       111 
111 
     | 
    
         
             
                  end
         
     | 
| 
       112 
112 
     | 
    
         | 
| 
       113 
113 
     | 
    
         
             
                  def colist(node)
         
     | 
| 
         @@ -117,7 +117,7 @@ module Metanorma 
     | 
|
| 
       117 
117 
     | 
    
         
             
                          xml_li.p { |p| p << item.text }
         
     | 
| 
       118 
118 
     | 
    
         
             
                        end
         
     | 
| 
       119 
119 
     | 
    
         
             
                      end
         
     | 
| 
       120 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 120 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       121 
121 
     | 
    
         
             
                  end
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
                  def list_caption(node, out)
         
     | 
| 
         @@ -53,13 +53,19 @@ module Metanorma 
     | 
|
| 
       53 
53 
     | 
    
         
             
                class NamedEscapePreprocessor < Asciidoctor::Extensions::Preprocessor
         
     | 
| 
       54 
54 
     | 
    
         
             
                  def process(document, reader)
         
     | 
| 
       55 
55 
     | 
    
         
             
                    c = HTMLEntities.new
         
     | 
| 
      
 56 
     | 
    
         
            +
                    p = Metanorma::Utils::LineStatus.new
         
     | 
| 
       56 
57 
     | 
    
         
             
                    lines = reader.lines.map do |l|
         
     | 
| 
       57 
     | 
    
         
            -
                       
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                      end.join
         
     | 
| 
      
 58 
     | 
    
         
            +
                      p.process(l)
         
     | 
| 
      
 59 
     | 
    
         
            +
                      p.pass ? l : convert(l, c)
         
     | 
| 
       60 
60 
     | 
    
         
             
                    end
         
     | 
| 
       61 
61 
     | 
    
         
             
                    ::Asciidoctor::PreprocessorReader.new document, lines
         
     | 
| 
       62 
62 
     | 
    
         
             
                  end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                  def convert(line, esc)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    line.split(/(&[A-Za-z][^&;]*;)/).map do |s|
         
     | 
| 
      
 66 
     | 
    
         
            +
                      /^&[A-Za-z]/.match?(s) ? esc.encode(esc.decode(s), :hexadecimal) : s
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end.join
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
       63 
69 
     | 
    
         
             
                end
         
     | 
| 
       64 
70 
     | 
    
         | 
| 
       65 
71 
     | 
    
         
             
                class ColumnBreakBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
         
     | 
| 
         @@ -75,51 +81,16 @@ module Metanorma 
     | 
|
| 
       75 
81 
     | 
    
         
             
                # Not using TreeProcessor because that is still too close to
         
     | 
| 
       76 
82 
     | 
    
         
             
                # inline expressions being processed on access (e.g. titles)
         
     | 
| 
       77 
83 
     | 
    
         
             
                class LinkProtectPreprocessor < Asciidoctor::Extensions::Preprocessor
         
     | 
| 
       78 
     | 
    
         
            -
                  def init
         
     | 
| 
       79 
     | 
    
         
            -
                    pass = true # process as passthrough: init = true until
         
     | 
| 
       80 
     | 
    
         
            -
                    # hit end of doc header
         
     | 
| 
       81 
     | 
    
         
            -
                    is_delim = false # current line is a no-substititon block delimiter
         
     | 
| 
       82 
     | 
    
         
            -
                    pass_delim = false # current line is a passthrough delimiter
         
     | 
| 
       83 
     | 
    
         
            -
                    delimln = "" # delimiter line of current block(s);
         
     | 
| 
       84 
     | 
    
         
            -
                    # init value looks for end of doc header
         
     | 
| 
       85 
     | 
    
         
            -
                    { pass: pass, is_delim: is_delim, pass_delim: pass_delim,
         
     | 
| 
       86 
     | 
    
         
            -
                      delimln: delimln }
         
     | 
| 
       87 
     | 
    
         
            -
                  end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
84 
     | 
    
         
             
                  def process(document, reader)
         
     | 
| 
       90 
     | 
    
         
            -
                    p =  
     | 
| 
      
 85 
     | 
    
         
            +
                    p = Metanorma::Utils::LineStatus.new
         
     | 
| 
       91 
86 
     | 
    
         
             
                    lines = reader.lines.map do |t|
         
     | 
| 
       92 
     | 
    
         
            -
                      p 
     | 
| 
       93 
     | 
    
         
            -
                      !p 
     | 
| 
      
 87 
     | 
    
         
            +
                      p.process(t)
         
     | 
| 
      
 88 
     | 
    
         
            +
                      !p.pass && t.include?(":") and t = inlinelinkmacro(inlinelink(t))
         
     | 
| 
       94 
89 
     | 
    
         
             
                      t
         
     | 
| 
       95 
90 
     | 
    
         
             
                    end
         
     | 
| 
       96 
91 
     | 
    
         
             
                    ::Asciidoctor::PreprocessorReader.new document, lines
         
     | 
| 
       97 
92 
     | 
    
         
             
                  end
         
     | 
| 
       98 
93 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
                  def pass_status(status, text)
         
     | 
| 
       100 
     | 
    
         
            -
                    text == "++++" && !status[:delimln] and status[:pass] = !status[:pass]
         
     | 
| 
       101 
     | 
    
         
            -
                    status[:midline_docattr] && !/^:[^ :]+: /.match?(text) and
         
     | 
| 
       102 
     | 
    
         
            -
                      status[:midline_docattr] = false
         
     | 
| 
       103 
     | 
    
         
            -
                    if (status[:is_delim] && /^(-+|\*+|=+|_+)$/.match?(text)) ||
         
     | 
| 
       104 
     | 
    
         
            -
                        (!status[:is_delim] && !status[:delimln] && /^-----*$|^\.\.\.\.\.*$/.match?(text))
         
     | 
| 
       105 
     | 
    
         
            -
                      status[:delimln] = text
         
     | 
| 
       106 
     | 
    
         
            -
                      status[:pass] = true
         
     | 
| 
       107 
     | 
    
         
            -
                    elsif status[:pass_delim]
         
     | 
| 
       108 
     | 
    
         
            -
                      status[:delimln] = "" # end of paragraph for paragraph with [pass]
         
     | 
| 
       109 
     | 
    
         
            -
                    elsif status[:delimln] && text == status[:delimln]
         
     | 
| 
       110 
     | 
    
         
            -
                      status[:pass] = false
         
     | 
| 
       111 
     | 
    
         
            -
                      status[:delimln] = nil
         
     | 
| 
       112 
     | 
    
         
            -
                    elsif /^:[^ :]+: /.match?(text) &&
         
     | 
| 
       113 
     | 
    
         
            -
                        (status[:prev_line].empty? || status[:midline_docattr])
         
     | 
| 
       114 
     | 
    
         
            -
                      status[:pass] = true
         
     | 
| 
       115 
     | 
    
         
            -
                      status[:midline_docattr] = true
         
     | 
| 
       116 
     | 
    
         
            -
                    end
         
     | 
| 
       117 
     | 
    
         
            -
                    status[:is_delim] = /^\[(source|listing|literal|pass)\b/.match?(text)
         
     | 
| 
       118 
     | 
    
         
            -
                    status[:pass_delim] = /^\[(pass)\b/.match?(text)
         
     | 
| 
       119 
     | 
    
         
            -
                    status[:prev_line] = text.strip
         
     | 
| 
       120 
     | 
    
         
            -
                    status
         
     | 
| 
       121 
     | 
    
         
            -
                  end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
94 
     | 
    
         
             
                  PASS_INLINE_MACROS = %w(pass pass-format identifier std-link stem)
         
     | 
| 
       124 
95 
     | 
    
         
             
                    .join("|").freeze
         
     | 
| 
       125 
96 
     | 
    
         | 
| 
         @@ -133,7 +104,7 @@ module Metanorma 
     | 
|
| 
       133 
104 
     | 
    
         
             
                      \\[.*?(?<!\\\\)\\]                     # [ ... ] not preceded by \\
         
     | 
| 
       134 
105 
     | 
    
         
             
                    )
         
     | 
| 
       135 
106 
     | 
    
         
             
                  REGEX
         
     | 
| 
       136 
     | 
    
         
            -
                  PASS_INLINE_MACRO_RX = /#{PASS_INLINE_MACRO_STR}/xo 
     | 
| 
      
 107 
     | 
    
         
            +
                  PASS_INLINE_MACRO_RX = /#{PASS_INLINE_MACRO_STR}/xo
         
     | 
| 
       137 
108 
     | 
    
         | 
| 
       138 
109 
     | 
    
         
             
                  def pass_inline_split(text)
         
     | 
| 
       139 
110 
     | 
    
         
             
                    text.split(PASS_INLINE_MACRO_RX).each.map do |x|
         
     | 
| 
         @@ -143,7 +114,7 @@ module Metanorma 
     | 
|
| 
       143 
114 
     | 
    
         | 
| 
       144 
115 
     | 
    
         
             
                  # InlineLinkRx = %r((^|link:|#{CG_BLANK}|<|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m
         
     | 
| 
       145 
116 
     | 
    
         
             
                  #
         
     | 
| 
       146 
     | 
    
         
            -
                  InlineLinkRx = %r((^|(?<![-\\])\blink:(?!\+)|\p{Blank}|<|[<>\(\)\[\];"'])((?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)(?:(\[(|.*?[^\\])\])|([^\s\[\]<]*([^\s,.?!\[\]<\)])))))m 
     | 
| 
      
 117 
     | 
    
         
            +
                  InlineLinkRx = %r((^|(?<![-\\])\blink:(?!\+)|\p{Blank}|<|[<>\(\)\[\];"'])((?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)(?:(\[(|.*?[^\\])\])|([^\s\[\]<]*([^\s,.?!\[\]<\)])))))m
         
     | 
| 
       147 
118 
     | 
    
         | 
| 
       148 
119 
     | 
    
         
             
                  def inlinelink(text)
         
     | 
| 
       149 
120 
     | 
    
         
             
                    text.include?("://") or return text
         
     | 
| 
         @@ -173,7 +144,7 @@ module Metanorma 
     | 
|
| 
       173 
144 
     | 
    
         
             
                    (|[^:\\s\\[][^\\s\\[]*)          # link: ... up to [
         
     | 
| 
       174 
145 
     | 
    
         
             
                    (\\[(|.*?[^\\\\])\\])            # [ ... ], no ]
         
     | 
| 
       175 
146 
     | 
    
         
             
                  REGEX
         
     | 
| 
       176 
     | 
    
         
            -
                  InlineLinkMacroRx = /#{InlineLinkMacroRx1}/x 
     | 
| 
      
 147 
     | 
    
         
            +
                  InlineLinkMacroRx = /#{InlineLinkMacroRx1}/x
         
     | 
| 
       177 
148 
     | 
    
         | 
| 
       178 
149 
     | 
    
         
             
                  def inlinelinkmacro(text)
         
     | 
| 
       179 
150 
     | 
    
         
             
                    (text.include?("[") &&
         
     | 
| 
         @@ -37,18 +37,19 @@ module Metanorma 
     | 
|
| 
       37 
37 
     | 
    
         
             
                  def process(doc, reader)
         
     | 
| 
       38 
38 
     | 
    
         
             
                    reader.eof? and return reader
         
     | 
| 
       39 
39 
     | 
    
         
             
                    r = ::Asciidoctor::PreprocessorNoIfdefsReader.new doc, reader.lines
         
     | 
| 
      
 40 
     | 
    
         
            +
                    p = Metanorma::Utils::LineStatus.new
         
     | 
| 
       40 
41 
     | 
    
         
             
                    lines = r.readlines
         
     | 
| 
       41 
42 
     | 
    
         
             
                    headings = lines.grep(/^== /).map(&:strip)
         
     | 
| 
       42 
43 
     | 
    
         
             
                    ret = lines.each_with_object(embed_acc(doc, r)) do |line, m|
         
     | 
| 
       43 
     | 
    
         
            -
                      process_line(line, m, headings)
         
     | 
| 
      
 44 
     | 
    
         
            +
                      process_line(line, m, headings, p)
         
     | 
| 
       44 
45 
     | 
    
         
             
                    end
         
     | 
| 
       45 
46 
     | 
    
         
             
                    return_to_document(doc, ret)
         
     | 
| 
       46 
47 
     | 
    
         
             
                  end
         
     | 
| 
       47 
48 
     | 
    
         | 
| 
       48 
49 
     | 
    
         
             
                  def embed_acc(doc, reader)
         
     | 
| 
       49 
50 
     | 
    
         
             
                    { lines: [], hdr: [], id: [],
         
     | 
| 
       50 
     | 
    
         
            -
                      orig: doc, doc 
     | 
| 
       51 
     | 
    
         
            -
                      reader 
     | 
| 
      
 51 
     | 
    
         
            +
                      orig: doc, doc:, file: nil, path: nil,
         
     | 
| 
      
 52 
     | 
    
         
            +
                      reader:, prev: nil }
         
     | 
| 
       52 
53 
     | 
    
         
             
                  end
         
     | 
| 
       53 
54 
     | 
    
         | 
| 
       54 
55 
     | 
    
         
             
                  # presupposes single embed
         
     | 
| 
         @@ -93,13 +94,14 @@ module Metanorma 
     | 
|
| 
       93 
94 
     | 
    
         | 
| 
       94 
95 
     | 
    
         
             
                  def update_embeds(lines, acc, emb)
         
     | 
| 
       95 
96 
     | 
    
         
             
                    lines.empty? or
         
     | 
| 
       96 
     | 
    
         
            -
                      acc << { file: emb[:file], path: emb[:path], lines:  
     | 
| 
      
 97 
     | 
    
         
            +
                      acc << { file: emb[:file], path: emb[:path], lines: }
         
     | 
| 
       97 
98 
     | 
    
         
             
                    [[], acc]
         
     | 
| 
       98 
99 
     | 
    
         
             
                  end
         
     | 
| 
       99 
100 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
                  def process_line(line, acc, headings)
         
     | 
| 
       101 
     | 
    
         
            -
                     
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
                  def process_line(line, acc, headings, status)
         
     | 
| 
      
 102 
     | 
    
         
            +
                    status.process(line)
         
     | 
| 
      
 103 
     | 
    
         
            +
                    if !status.pass && /^embed::/.match?(line)
         
     | 
| 
      
 104 
     | 
    
         
            +
                      e = embed(line, acc, headings, status)
         
     | 
| 
       103 
105 
     | 
    
         
             
                      acc = process_embed(acc, e, acc[:prev])
         
     | 
| 
       104 
106 
     | 
    
         
             
                    else
         
     | 
| 
       105 
107 
     | 
    
         
             
                      acc[:lines] << line
         
     | 
| 
         @@ -148,7 +150,7 @@ module Metanorma 
     | 
|
| 
       148 
150 
     | 
    
         
             
                    end
         
     | 
| 
       149 
151 
     | 
    
         
             
                  end
         
     | 
| 
       150 
152 
     | 
    
         | 
| 
       151 
     | 
    
         
            -
                  def embed(line, acc, headings)
         
     | 
| 
      
 153 
     | 
    
         
            +
                  def embed(line, acc, headings, status)
         
     | 
| 
       152 
154 
     | 
    
         
             
                    fname, inc_path = filename(line, acc)
         
     | 
| 
       153 
155 
     | 
    
         
             
                    lines = filter_sections(read(inc_path), headings)
         
     | 
| 
       154 
156 
     | 
    
         
             
                    n = Asciidoctor::Document
         
     | 
| 
         @@ -158,12 +160,12 @@ module Metanorma 
     | 
|
| 
       158 
160 
     | 
    
         
             
                      .merge(file: fname, path: inc_path, orig: acc[:orig])
         
     | 
| 
       159 
161 
     | 
    
         
             
                    ret[:hdr] or
         
     | 
| 
       160 
162 
     | 
    
         
             
                      raise "Embedding an incomplete document with no header: #{ret[:path]}"
         
     | 
| 
       161 
     | 
    
         
            -
                    embed_recurse(ret, n, r, headings)
         
     | 
| 
      
 163 
     | 
    
         
            +
                    embed_recurse(ret, n, r, headings, status)
         
     | 
| 
       162 
164 
     | 
    
         
             
                  end
         
     | 
| 
       163 
165 
     | 
    
         | 
| 
       164 
     | 
    
         
            -
                  def embed_recurse(ret, doc, reader, headings)
         
     | 
| 
      
 166 
     | 
    
         
            +
                  def embed_recurse(ret, doc, reader, headings, status)
         
     | 
| 
       165 
167 
     | 
    
         
             
                    ret1 = ret[:lines].each_with_object(embed_acc(doc, reader)) do |line, m|
         
     | 
| 
       166 
     | 
    
         
            -
                      process_line(line, m, headings)
         
     | 
| 
      
 168 
     | 
    
         
            +
                      process_line(line, m, headings, status)
         
     | 
| 
       167 
169 
     | 
    
         
             
                    end
         
     | 
| 
       168 
170 
     | 
    
         
             
                    ret.merge(
         
     | 
| 
       169 
171 
     | 
    
         
             
                      { lines: ret1[:lines], id: ret[:id] + ret1[:id],
         
     | 
| 
         @@ -172,7 +174,7 @@ module Metanorma 
     | 
|
| 
       172 
174 
     | 
    
         
             
                  end
         
     | 
| 
       173 
175 
     | 
    
         | 
| 
       174 
176 
     | 
    
         
             
                  def strip_header(lines)
         
     | 
| 
       175 
     | 
    
         
            -
                    return { lines 
     | 
| 
      
 177 
     | 
    
         
            +
                    return { lines:, hdr: nil } unless !lines.empty? &&
         
     | 
| 
       176 
178 
     | 
    
         
             
                      lines.first.start_with?("= ")
         
     | 
| 
       177 
179 
     | 
    
         | 
| 
       178 
180 
     | 
    
         
             
                    skip = true
         
     | 
| 
         @@ -27,7 +27,7 @@ module Metanorma 
     | 
|
| 
       27 
27 
     | 
    
         
             
                  def isorefmatchescode(match, _item)
         
     | 
| 
       28 
28 
     | 
    
         
             
                    code = analyse_ref_code(match[:code])
         
     | 
| 
       29 
29 
     | 
    
         
             
                    yr = norm_year(match[:year])
         
     | 
| 
       30 
     | 
    
         
            -
                    { code: match[:code], year: yr, match 
     | 
| 
      
 30 
     | 
    
         
            +
                    { code: match[:code], year: yr, match:,
         
     | 
| 
       31 
31 
     | 
    
         
             
                      title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel],
         
     | 
| 
       32 
32 
     | 
    
         
             
                      analyse_code: code, lang: @lang || :all }
         
     | 
| 
       33 
33 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -47,7 +47,7 @@ module Metanorma 
     | 
|
| 
       47 
47 
     | 
    
         
             
                  def isorefmatches2code(match, _item)
         
     | 
| 
       48 
48 
     | 
    
         
             
                    code = analyse_ref_code(match[:code])
         
     | 
| 
       49 
49 
     | 
    
         
             
                    { code: match[:code], no_year: true, lang: @lang || :all,
         
     | 
| 
       50 
     | 
    
         
            -
                      note: match[:fn], year: nil, match 
     | 
| 
      
 50 
     | 
    
         
            +
                      note: match[:fn], year: nil, match:, analyse_code: code,
         
     | 
| 
       51 
51 
     | 
    
         
             
                      title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel] }
         
     | 
| 
       52 
52 
     | 
    
         
             
                  end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
         @@ -77,7 +77,7 @@ module Metanorma 
     | 
|
| 
       77 
77 
     | 
    
         
             
                    code = analyse_ref_code(match[:code])
         
     | 
| 
       78 
78 
     | 
    
         
             
                    yr = norm_year(match[:year])
         
     | 
| 
       79 
79 
     | 
    
         
             
                    hasyr = !yr.nil? && yr != "--"
         
     | 
| 
       80 
     | 
    
         
            -
                    { code: match[:code], match 
     | 
| 
      
 80 
     | 
    
         
            +
                    { code: match[:code], match:, yr:, hasyr:,
         
     | 
| 
       81 
81 
     | 
    
         
             
                      year: hasyr ? yr : nil, lang: @lang || :all,
         
     | 
| 
       82 
82 
     | 
    
         
             
                      all_parts: true, no_year: yr == "--",
         
     | 
| 
       83 
83 
     | 
    
         
             
                      title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel] }
         
     | 
| 
         @@ -162,11 +162,11 @@ module Metanorma 
     | 
|
| 
       162 
162 
     | 
    
         
             
                  def refitem1code(_item, match)
         
     | 
| 
       163 
163 
     | 
    
         
             
                    code = analyse_ref_code(match[:code])
         
     | 
| 
       164 
164 
     | 
    
         
             
                    ((code[:id] && code[:numeric]) || code[:nofetch]) and
         
     | 
| 
       165 
     | 
    
         
            -
                      return { code: nil, match 
     | 
| 
      
 165 
     | 
    
         
            +
                      return { code: nil, match:, analyse_code: code,
         
     | 
| 
       166 
166 
     | 
    
         
             
                               hidden: code[:hidden] }
         
     | 
| 
       167 
167 
     | 
    
         
             
                    { code: code[:id], analyse_code: code, localfile: code[:localfile],
         
     | 
| 
       168 
168 
     | 
    
         
             
                      year: (m = refitem1yr(code[:id])) ? m[:year] : nil,
         
     | 
| 
       169 
     | 
    
         
            -
                      title: match[:text], match 
     | 
| 
      
 169 
     | 
    
         
            +
                      title: match[:text], match:, hidden: code[:hidden],
         
     | 
| 
       170 
170 
     | 
    
         
             
                      usrlbl: match[:usrlbl] || code[:usrlabel], lang: @lang || :all }
         
     | 
| 
       171 
171 
     | 
    
         
             
                  end
         
     | 
| 
       172 
172 
     | 
    
         | 
| 
         @@ -187,29 +187,26 @@ module Metanorma 
     | 
|
| 
       187 
187 
     | 
    
         
             
                  ISO_REF =
         
     | 
| 
       188 
188 
     | 
    
         
             
                    %r{^<ref\sid="(?<anchor>[^"]+)">
         
     | 
| 
       189 
189 
     | 
    
         
             
                  \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
         
     | 
| 
       190 
     | 
    
         
            -
                  (?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm 
     | 
| 
      
 190 
     | 
    
         
            +
                  (?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
         
     | 
| 
       191 
191 
     | 
    
         | 
| 
       192 
192 
     | 
    
         
             
                  ISO_REF_NO_YEAR =
         
     | 
| 
       193 
193 
     | 
    
         
             
                    %r{^<ref\sid="(?<anchor>[^"]+)">
         
     | 
| 
       194 
194 
     | 
    
         
             
                  \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+):
         
     | 
| 
       195 
     | 
    
         
            -
                  ( 
     | 
| 
      
 195 
     | 
    
         
            +
                  (?:--|–|—|&\#821[12];)\]</ref>,?\s*
         
     | 
| 
       196 
196 
     | 
    
         
             
                    (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
         
     | 
| 
       197 
     | 
    
         
            -
                      .freeze
         
     | 
| 
       198 
197 
     | 
    
         | 
| 
       199 
198 
     | 
    
         
             
                  ISO_REF_ALL_PARTS =
         
     | 
| 
       200 
199 
     | 
    
         
             
                    %r{^<ref\sid="(?<anchor>[^"]+)">
         
     | 
| 
       201 
200 
     | 
    
         
             
                  \[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9]+)
         
     | 
| 
       202 
     | 
    
         
            -
                  (?::(?<year 
     | 
| 
      
 201 
     | 
    
         
            +
                  (?::(?<year>--|–|—|&\#821[12];|[0-9][0-9-]+))?\s
         
     | 
| 
       203 
202 
     | 
    
         
             
                  \(all\sparts\)\]</ref>,?\s*
         
     | 
| 
       204 
     | 
    
         
            -
                    (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm 
     | 
| 
      
 203 
     | 
    
         
            +
                    (?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
         
     | 
| 
       205 
204 
     | 
    
         | 
| 
       206 
205 
     | 
    
         
             
                  NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
         
     | 
| 
       207 
206 
     | 
    
         
             
                  \[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
         
     | 
| 
       208 
     | 
    
         
            -
                    .freeze
         
     | 
| 
       209 
207 
     | 
    
         | 
| 
       210 
208 
     | 
    
         
             
                  NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
         
     | 
| 
       211 
209 
     | 
    
         
             
                  (?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
         
     | 
| 
       212 
     | 
    
         
            -
                    .freeze
         
     | 
| 
       213 
210 
     | 
    
         | 
| 
       214 
211 
     | 
    
         
             
                  def reference1_matches(item)
         
     | 
| 
       215 
212 
     | 
    
         
             
                    matched = ISO_REF.match item
         
     | 
| 
         @@ -40,7 +40,7 @@ module Metanorma 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  def reference_queue(results, size)
         
     | 
| 
       41 
41 
     | 
    
         
             
                    (1..size).each.with_object([]) do |_, m|
         
     | 
| 
       42 
42 
     | 
    
         
             
                      ref, i, doc = results.pop
         
     | 
| 
       43 
     | 
    
         
            -
                      m[i.to_i] = { ref:  
     | 
| 
      
 43 
     | 
    
         
            +
                      m[i.to_i] = { ref: }
         
     | 
| 
       44 
44 
     | 
    
         
             
                      if doc.is_a?(RelatonBib::RequestError)
         
     | 
| 
       45 
45 
     | 
    
         
             
                        @log.add("Bibliography", nil, "Could not retrieve #{ref[:code]}: " \
         
     | 
| 
       46 
46 
     | 
    
         
             
                                                      "no access to online site", severity: 1)
         
     | 
| 
         @@ -69,7 +69,7 @@ module Metanorma 
     | 
|
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                  def merge_publishers(base, add)
         
     | 
| 
       71 
71 
     | 
    
         
             
                    ins = base.at("//contributor[last()]") || base.children[-1]
         
     | 
| 
       72 
     | 
    
         
            -
                    add.xpath("//contributor[role/@type = 'publisher']"). 
     | 
| 
      
 72 
     | 
    
         
            +
                    add.xpath("//contributor[role/@type = 'publisher']").reverse_each do |p|
         
     | 
| 
       73 
73 
     | 
    
         
             
                      ins.next = p
         
     | 
| 
       74 
74 
     | 
    
         
             
                    end
         
     | 
| 
       75 
75 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -80,14 +80,14 @@ module Metanorma 
     | 
|
| 
       80 
80 
     | 
    
         
             
                      v.at("//docidentifier[@primary = 'true']") or
         
     | 
| 
       81 
81 
     | 
    
         
             
                        v.at("//docidentifier")["primary"] = true
         
     | 
| 
       82 
82 
     | 
    
         
             
                    end
         
     | 
| 
       83 
     | 
    
         
            -
                    add.xpath("//docidentifier"). 
     | 
| 
      
 83 
     | 
    
         
            +
                    add.xpath("//docidentifier").reverse_each do |p|
         
     | 
| 
       84 
84 
     | 
    
         
             
                      ins.next = p
         
     | 
| 
       85 
85 
     | 
    
         
             
                    end
         
     | 
| 
       86 
86 
     | 
    
         
             
                  end
         
     | 
| 
       87 
87 
     | 
    
         | 
| 
       88 
88 
     | 
    
         
             
                  def merge_urls(base, add)
         
     | 
| 
       89 
89 
     | 
    
         
             
                    ins = base.at("./uri[last()]") || base.at("./title[last()]")
         
     | 
| 
       90 
     | 
    
         
            -
                    add.xpath("./uri"). 
     | 
| 
      
 90 
     | 
    
         
            +
                    add.xpath("./uri").reverse_each do |p|
         
     | 
| 
       91 
91 
     | 
    
         
             
                      ins.next = p
         
     | 
| 
       92 
92 
     | 
    
         
             
                    end
         
     | 
| 
       93 
93 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -122,16 +122,14 @@ module Metanorma 
     | 
|
| 
       122 
122 
     | 
    
         
             
                  end
         
     | 
| 
       123 
123 
     | 
    
         | 
| 
       124 
124 
     | 
    
         
             
                  def local_ievcache_name(cachename)
         
     | 
| 
       125 
     | 
    
         
            -
                     
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
                    cachename.nil? and return nil
         
     | 
| 
       127 
126 
     | 
    
         
             
                    cachename += "_iev" unless cachename.empty?
         
     | 
| 
       128 
127 
     | 
    
         
             
                    cachename = "iev" if cachename.empty?
         
     | 
| 
       129 
128 
     | 
    
         
             
                    "#{cachename}/cache"
         
     | 
| 
       130 
129 
     | 
    
         
             
                  end
         
     | 
| 
       131 
130 
     | 
    
         | 
| 
       132 
131 
     | 
    
         
             
                  def fetch_ref(xml, code, year, **opts)
         
     | 
| 
       133 
     | 
    
         
            -
                     
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
      
 132 
     | 
    
         
            +
                    opts[:no_year] and return nil
         
     | 
| 
       135 
133 
     | 
    
         
             
                    code = code.sub(/^\([^)]+\)/, "")
         
     | 
| 
       136 
134 
     | 
    
         
             
                    hit = fetch_ref1(code, year, opts) or return nil
         
     | 
| 
       137 
135 
     | 
    
         
             
                    xml.parent.add_child(smart_render_xml(hit, code, opts))
         
     | 
| 
         @@ -200,8 +200,8 @@ module Metanorma 
     | 
|
| 
       200 
200 
     | 
    
         | 
| 
       201 
201 
     | 
    
         
             
                  MALFORMED_REF = <<~REF.freeze
         
     | 
| 
       202 
202 
     | 
    
         
             
                    no anchor on reference, markup may be malformed: see
         
     | 
| 
       203 
     | 
    
         
            -
                    https://www.metanorma. 
     | 
| 
       204 
     | 
    
         
            -
                    https://www.metanorma. 
     | 
| 
      
 203 
     | 
    
         
            +
                    https://www.metanorma.org/author/topics/sections/bibliography/ ,
         
     | 
| 
      
 204 
     | 
    
         
            +
                    https://www.metanorma.org/author/iso/topics/markup/#bibliographies
         
     | 
| 
       205 
205 
     | 
    
         
             
                  REF
         
     | 
| 
       206 
206 
     | 
    
         | 
| 
       207 
207 
     | 
    
         
             
                  def ref_normalise(ref)
         
     | 
| 
         @@ -16,8 +16,7 @@ module Metanorma 
     | 
|
| 
       16 
16 
     | 
    
         
             
                        .gsub(%r{<index>.*?</index>}m, "")
         
     | 
| 
       17 
17 
     | 
    
         
             
                        .gsub(%r{<fn[^>]*>.*?</fn>}m, "")
         
     | 
| 
       18 
18 
     | 
    
         
             
                        .gsub(/<[^>]+>/, "")
         
     | 
| 
       19 
     | 
    
         
            -
                        .strip.downcase
         
     | 
| 
       20 
     | 
    
         
            -
                        .sub(/\.$/, "")
         
     | 
| 
      
 19 
     | 
    
         
            +
                        .strip.downcase.sub(/\.$/, "")
         
     | 
| 
       21 
20 
     | 
    
         
             
                  end
         
     | 
| 
       22 
21 
     | 
    
         | 
| 
       23 
22 
     | 
    
         
             
                  def sectiontype(node, level = true)
         
     | 
| 
         @@ -41,7 +40,8 @@ module Metanorma 
     | 
|
| 
       41 
40 
     | 
    
         
             
                      "terms, definitions and abbreviated terms"
         
     | 
| 
       42 
41 
     | 
    
         
             
                      "terms and definitions"
         
     | 
| 
       43 
42 
     | 
    
         
             
                    when "symbols and abbreviated terms",
         
     | 
| 
       44 
     | 
    
         
            -
                      "symbols", "abbreviated terms", "abbreviations"
         
     | 
| 
      
 43 
     | 
    
         
            +
                      "symbols", "abbreviated terms", "abbreviations",
         
     | 
| 
      
 44 
     | 
    
         
            +
                      "symbols and abbreviations"
         
     | 
| 
       45 
45 
     | 
    
         
             
                      "symbols and abbreviated terms"
         
     | 
| 
       46 
46 
     | 
    
         
             
                    when "acknowledgements", "acknowledgments"
         
     | 
| 
       47 
47 
     | 
    
         
             
                      "acknowledgements"
         
     | 
| 
         @@ -170,7 +170,7 @@ module Metanorma 
     | 
|
| 
       170 
170 
     | 
    
         
             
                        seen_xref = Nokogiri::XML.fragment(matched[:xref])
         
     | 
| 
       171 
171 
     | 
    
         
             
                        add_term_source(node, xml_t, seen_xref, matched)
         
     | 
| 
       172 
172 
     | 
    
         
             
                      end
         
     | 
| 
       173 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 173 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       174 
174 
     | 
    
         
             
                  end
         
     | 
| 
       175 
175 
     | 
    
         | 
| 
       176 
176 
     | 
    
         
             
                  def termdefinition(node)
         
     | 
| 
         @@ -178,7 +178,7 @@ module Metanorma 
     | 
|
| 
       178 
178 
     | 
    
         
             
                      xml.definition **attr_code(type: node.attr("type")) do |d|
         
     | 
| 
       179 
179 
     | 
    
         
             
                        d << node.content
         
     | 
| 
       180 
180 
     | 
    
         
             
                      end
         
     | 
| 
       181 
     | 
    
         
            -
                    end.join(" 
     | 
| 
      
 181 
     | 
    
         
            +
                    end.join("")
         
     | 
| 
       182 
182 
     | 
    
         
             
                  end
         
     | 
| 
       183 
183 
     | 
    
         
             
                end
         
     | 
| 
       184 
184 
     | 
    
         
             
              end
         
     | 
| 
         @@ -48,7 +48,6 @@ module Metanorma 
     | 
|
| 
       48 
48 
     | 
    
         
             
                  def mathml_sanitise(math)
         
     | 
| 
       49 
49 
     | 
    
         
             
                    math.to_xml(encoding: "US-ASCII").gsub(/ xmlns=["'][^"']+["']/, "")
         
     | 
| 
       50 
50 
     | 
    
         
             
                      .gsub(%r{<[^:/>]+:}, "<").gsub(%r{</[^:/>]+:}, "</")
         
     | 
| 
       51 
     | 
    
         
            -
                    # .gsub(/&#([^;]+);/) { |x| "&#x#{$1.to_i.to_s(16)};" }
         
     | 
| 
       52 
51 
     | 
    
         
             
                  end
         
     | 
| 
       53 
52 
     | 
    
         | 
| 
       54 
53 
     | 
    
         
             
                  def math_validate_error(math, elem, error)
         
     | 
| 
         @@ -133,7 +132,7 @@ module Metanorma 
     | 
|
| 
       133 
132 
     | 
    
         
             
                    doc.xpath(WILDCARD_ATTRS, "m" => SVG_NS).each do |n|
         
     | 
| 
       134 
133 
     | 
    
         
             
                      n.elements.each do |e|
         
     | 
| 
       135 
134 
     | 
    
         
             
                        e.traverse do |e1|
         
     | 
| 
       136 
     | 
    
         
            -
                          e1.element? and e1.each { |k, _v| e1.delete(k) }
         
     | 
| 
      
 135 
     | 
    
         
            +
                          e1.element? and e1.each { |k, _v| e1.delete(k) } # rubocop:disable Style/HashEachMethods
         
     | 
| 
       137 
136 
     | 
    
         
             
                        end
         
     | 
| 
       138 
137 
     | 
    
         
             
                      end
         
     | 
| 
       139 
138 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -143,6 +142,7 @@ module Metanorma 
     | 
|
| 
       143 
142 
     | 
    
         | 
| 
       144 
143 
     | 
    
         
             
                  def image_validate(doc)
         
     | 
| 
       145 
144 
     | 
    
         
             
                    image_exists(doc)
         
     | 
| 
      
 145 
     | 
    
         
            +
                    image_toobig(doc)
         
     | 
| 
       146 
146 
     | 
    
         
             
                    png_validate(doc)
         
     | 
| 
       147 
147 
     | 
    
         
             
                  end
         
     | 
| 
       148 
148 
     | 
    
         | 
| 
         @@ -183,6 +183,18 @@ module Metanorma 
     | 
|
| 
       183 
183 
     | 
    
         
             
                             "Corrupt PNG image detected: #{e.message}")
         
     | 
| 
       184 
184 
     | 
    
         
             
                  end
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
      
 186 
     | 
    
         
            +
                  TOO_BIG_IMG_ERR = <<~ERR.freeze
         
     | 
| 
      
 187 
     | 
    
         
            +
                    Image too large for Data URI encoding: disable Data URI encoding (`:data-uri-image: false`), or set `:data-uri-maxsize: 0`
         
     | 
| 
      
 188 
     | 
    
         
            +
                  ERR
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
                  def image_toobig(doc)
         
     | 
| 
      
 191 
     | 
    
         
            +
                    @dataurimaxsize.zero? and return
         
     | 
| 
      
 192 
     | 
    
         
            +
                    doc.xpath("//image").each do |i|
         
     | 
| 
      
 193 
     | 
    
         
            +
                      i["src"].size > @dataurimaxsize and
         
     | 
| 
      
 194 
     | 
    
         
            +
                        @log.add("Images", i.parent, TOO_BIG_IMG_ERR, severity: 0)
         
     | 
| 
      
 195 
     | 
    
         
            +
                    end
         
     | 
| 
      
 196 
     | 
    
         
            +
                  end
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
       186 
198 
     | 
    
         
             
                  def validate(doc)
         
     | 
| 
       187 
199 
     | 
    
         
             
                    content_validate(doc)
         
     | 
| 
       188 
200 
     | 
    
         
             
                    schema_validate(formattedstr_strip(doc.dup),
         
     | 
    
        data/metanorma-standoc.gemspec
    CHANGED
    
    | 
         @@ -32,11 +32,12 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       32 
32 
     | 
    
         
             
              spec.add_dependency "asciidoctor", "~> 2.0.0"
         
     | 
| 
       33 
33 
     | 
    
         
             
              spec.add_dependency "crass", "~> 1.0.0"
         
     | 
| 
       34 
34 
     | 
    
         
             
              spec.add_dependency "iev", "~> 0.3.0"
         
     | 
| 
       35 
     | 
    
         
            -
              spec.add_dependency "isodoc", "~> 2.10. 
     | 
| 
      
 35 
     | 
    
         
            +
              spec.add_dependency "isodoc", "~> 2.10.5"
         
     | 
| 
       36 
36 
     | 
    
         
             
              spec.add_dependency "metanorma", ">= 1.6.0"
         
     | 
| 
       37 
37 
     | 
    
         
             
              spec.add_dependency "metanorma-plugin-datastruct", "~> 0.3.0"
         
     | 
| 
       38 
38 
     | 
    
         
             
              spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.0"
         
     | 
| 
       39 
39 
     | 
    
         
             
              spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.0"
         
     | 
| 
      
 40 
     | 
    
         
            +
              spec.add_dependency "metanorma-utils", "~> 1.9.0"
         
     | 
| 
       40 
41 
     | 
    
         
             
              spec.add_dependency "ruby-jing"
         
     | 
| 
       41 
42 
     | 
    
         
             
              # relaton-cli not just relaton, to avoid circular reference in metanorma
         
     | 
| 
       42 
43 
     | 
    
         
             
              spec.add_dependency "asciimath2unitsml", "~> 0.4.0"
         
     | 
| 
         @@ -58,5 +59,6 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       58 
59 
     | 
    
         
             
              spec.add_development_dependency "timecop", "~> 0.9"
         
     | 
| 
       59 
60 
     | 
    
         
             
              spec.add_development_dependency "vcr", "~> 6.1.0"
         
     | 
| 
       60 
61 
     | 
    
         
             
              spec.add_development_dependency "webmock"
         
     | 
| 
      
 62 
     | 
    
         
            +
              spec.add_development_dependency "xml-c14n"
         
     | 
| 
       61 
63 
     | 
    
         
             
              # spec.metadata["rubygems_mfa_required"] = "true"
         
     | 
| 
       62 
64 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: metanorma-standoc
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.9. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.9.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ribose Inc.
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-08-05 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: addressable
         
     | 
| 
         @@ -72,14 +72,14 @@ dependencies: 
     | 
|
| 
       72 
72 
     | 
    
         
             
                requirements:
         
     | 
| 
       73 
73 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       74 
74 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       75 
     | 
    
         
            -
                    version: 2.10. 
     | 
| 
      
 75 
     | 
    
         
            +
                    version: 2.10.5
         
     | 
| 
       76 
76 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       77 
77 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       78 
78 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       79 
79 
     | 
    
         
             
                requirements:
         
     | 
| 
       80 
80 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       81 
81 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       82 
     | 
    
         
            -
                    version: 2.10. 
     | 
| 
      
 82 
     | 
    
         
            +
                    version: 2.10.5
         
     | 
| 
       83 
83 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       84 
84 
     | 
    
         
             
              name: metanorma
         
     | 
| 
       85 
85 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -136,6 +136,20 @@ dependencies: 
     | 
|
| 
       136 
136 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       137 
137 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       138 
138 
     | 
    
         
             
                    version: 0.7.0
         
     | 
| 
      
 139 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 140 
     | 
    
         
            +
              name: metanorma-utils
         
     | 
| 
      
 141 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 142 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 143 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 144 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 145 
     | 
    
         
            +
                    version: 1.9.0
         
     | 
| 
      
 146 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 147 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 148 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 149 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 150 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 151 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 152 
     | 
    
         
            +
                    version: 1.9.0
         
     | 
| 
       139 
153 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       140 
154 
     | 
    
         
             
              name: ruby-jing
         
     | 
| 
       141 
155 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -402,6 +416,20 @@ dependencies: 
     | 
|
| 
       402 
416 
     | 
    
         
             
                - - ">="
         
     | 
| 
       403 
417 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       404 
418 
     | 
    
         
             
                    version: '0'
         
     | 
| 
      
 419 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 420 
     | 
    
         
            +
              name: xml-c14n
         
     | 
| 
      
 421 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 422 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 423 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 424 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 425 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 426 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 427 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 428 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 429 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 430 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 431 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 432 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       405 
433 
     | 
    
         
             
            description: |
         
     | 
| 
       406 
434 
     | 
    
         
             
              metanorma-standoc realises standards following the Metanorma standoc model
         
     | 
| 
       407 
435 
     | 
    
         |