metanorma-standoc 2.3.2 → 2.3.4
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/isodoc/html/htmlstyle.css +30 -1
 - data/lib/metanorma/standoc/blocks.rb +2 -1
 - data/lib/metanorma/standoc/cleanup.rb +0 -1
 - data/lib/metanorma/standoc/cleanup_asciibib.rb +0 -8
 - data/lib/metanorma/standoc/cleanup_maths.rb +44 -80
 - data/lib/metanorma/standoc/cleanup_ref.rb +33 -12
 - data/lib/metanorma/standoc/cleanup_section_names.rb +2 -4
 - data/lib/metanorma/standoc/front_contributor.rb +5 -5
 - data/lib/metanorma/standoc/inline.rb +7 -8
 - data/lib/metanorma/standoc/merge_bibitems.rb +107 -0
 - data/lib/metanorma/standoc/ref.rb +9 -10
 - data/lib/metanorma/standoc/ref_sect.rb +10 -1
 - data/lib/metanorma/standoc/ref_utility.rb +1 -2
 - data/lib/metanorma/standoc/render.rb +6 -6
 - data/lib/metanorma/standoc/section.rb +2 -1
 - data/lib/metanorma/standoc/spans_to_bibitem.rb +261 -0
 - data/lib/metanorma/standoc/utils.rb +8 -0
 - data/lib/metanorma/standoc/validate.rb +33 -10
 - data/lib/metanorma/standoc/version.rb +1 -1
 - metadata +4 -3
 - data/lib/metanorma/standoc/cleanup_biblio.rb +0 -242
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 62a2a480483e6cad337d48919668d1276a587c0c6173ffc7ea8cb773f605b1fb
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5a9bf620c79d8ec2993a96727f7b8c2874ee8d8c3865a5efd71941fb83ed8fc1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 226d8eaa68590e2dbf12917371afe5f2c4c60242397e459543da0ec3471a7a0abc7f5736e92b43f053854329f460bbc70155040bd0ae1df89efa0a62f8765d8e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 65a7c4e9794199fd48f3d18f3009a41d02ae837753d9e9e9cd41f755384f7b89f3376f5a6c9182de5f184eb4934a9fc9682b8ea708037aa315d9e243f83485bf
         
     | 
| 
         @@ -132,6 +132,35 @@ a.FootnoteRef + a.FootnoteRef:before { 
     | 
|
| 
       132 
132 
     | 
    
         
             
              color: red;
         
     | 
| 
       133 
133 
     | 
    
         
             
              text-decoration: line-through; }
         
     | 
| 
       134 
134 
     | 
    
         | 
| 
      
 135 
     | 
    
         
            +
            /* code highlighting with line numbers */
         
     | 
| 
      
 136 
     | 
    
         
            +
            table.rouge-line-table td.rouge-gutter {
         
     | 
| 
      
 137 
     | 
    
         
            +
              -moz-user-select: none;
         
     | 
| 
      
 138 
     | 
    
         
            +
              -ms-user-select: none;
         
     | 
| 
      
 139 
     | 
    
         
            +
              -webkit-user-select: none;
         
     | 
| 
      
 140 
     | 
    
         
            +
              user-select: none;
         
     | 
| 
      
 141 
     | 
    
         
            +
              padding-right: 1em; }
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
            table.rouge-line-table td.rouge-code {
         
     | 
| 
      
 144 
     | 
    
         
            +
              -moz-user-select: all;
         
     | 
| 
      
 145 
     | 
    
         
            +
              -ms-user-select: all;
         
     | 
| 
      
 146 
     | 
    
         
            +
              -webkit-user-select: all;
         
     | 
| 
      
 147 
     | 
    
         
            +
              user-select: all; }
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
            table.rouge-line-table,
         
     | 
| 
      
 150 
     | 
    
         
            +
            table.rouge-line-table th,
         
     | 
| 
      
 151 
     | 
    
         
            +
            table.rouge-line-table td {
         
     | 
| 
      
 152 
     | 
    
         
            +
              width: auto;
         
     | 
| 
      
 153 
     | 
    
         
            +
              border: none;
         
     | 
| 
      
 154 
     | 
    
         
            +
              margin: 0;
         
     | 
| 
      
 155 
     | 
    
         
            +
              padding: 0;
         
     | 
| 
      
 156 
     | 
    
         
            +
              font-size: 100%; }
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
            table.rouge-line-table pre {
         
     | 
| 
      
 159 
     | 
    
         
            +
              margin: 0;
         
     | 
| 
      
 160 
     | 
    
         
            +
              padding: 0;
         
     | 
| 
      
 161 
     | 
    
         
            +
              overflow-x: visible;
         
     | 
| 
      
 162 
     | 
    
         
            +
              font-size: 100%; }
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
       135 
164 
     | 
    
         
             
            #brochure-band {
         
     | 
| 
       136 
165 
     | 
    
         
             
              background-color: #0AC442; }
         
     | 
| 
       137 
166 
     | 
    
         | 
| 
         @@ -734,7 +763,7 @@ table { 
     | 
|
| 
       734 
763 
     | 
    
         
             
              table th, table td {
         
     | 
| 
       735 
764 
     | 
    
         
             
                padding: 1em; }
         
     | 
| 
       736 
765 
     | 
    
         
             
              table td.header {
         
     | 
| 
       737 
     | 
    
         
            -
                font- 
     | 
| 
      
 766 
     | 
    
         
            +
                font-weight: 400; }
         
     | 
| 
       738 
767 
     | 
    
         | 
| 
       739 
768 
     | 
    
         
             
            p.TableTitle {
         
     | 
| 
       740 
769 
     | 
    
         
             
              text-align: center;
         
     | 
| 
         @@ -231,7 +231,8 @@ module Metanorma 
     | 
|
| 
       231 
231 
     | 
    
         
             
                  end
         
     | 
| 
       232 
232 
     | 
    
         | 
| 
       233 
233 
     | 
    
         
             
                  def listing_attrs(node)
         
     | 
| 
       234 
     | 
    
         
            -
                    linenums =  
     | 
| 
      
 234 
     | 
    
         
            +
                    linenums = node.option?("linenums") || node.attributes[3] ||
         
     | 
| 
      
 235 
     | 
    
         
            +
                      @source_linenums
         
     | 
| 
       235 
236 
     | 
    
         
             
                    attr_code(id_attr(node).merge(keep_attrs(node)
         
     | 
| 
       236 
237 
     | 
    
         
             
                              .merge(lang: node.attr("language"),
         
     | 
| 
       237 
238 
     | 
    
         
             
                                     linenums: linenums ? "true" : nil,
         
     | 
| 
         @@ -6,7 +6,6 @@ require_relative "./cleanup_table" 
     | 
|
| 
       6 
6 
     | 
    
         
             
            require_relative "./cleanup_footnotes"
         
     | 
| 
       7 
7 
     | 
    
         
             
            require_relative "./cleanup_ref"
         
     | 
| 
       8 
8 
     | 
    
         
             
            require_relative "./cleanup_asciibib"
         
     | 
| 
       9 
     | 
    
         
            -
            require_relative "./cleanup_biblio"
         
     | 
| 
       10 
9 
     | 
    
         
             
            require_relative "./cleanup_boilerplate"
         
     | 
| 
       11 
10 
     | 
    
         
             
            require_relative "./cleanup_section"
         
     | 
| 
       12 
11 
     | 
    
         
             
            require_relative "./cleanup_terms"
         
     | 
| 
         @@ -54,14 +54,6 @@ module Metanorma 
     | 
|
| 
       54 
54 
     | 
    
         
             
                    end
         
     | 
| 
       55 
55 
     | 
    
         
             
                  end
         
     | 
| 
       56 
56 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                  def link_unwrap(para)
         
     | 
| 
       58 
     | 
    
         
            -
                    elems = para.elements
         
     | 
| 
       59 
     | 
    
         
            -
                    if elems.size == 1 && elems[0].name == "link"
         
     | 
| 
       60 
     | 
    
         
            -
                      para.at("./link").replace(elems[0]["target"].strip)
         
     | 
| 
       61 
     | 
    
         
            -
                    end
         
     | 
| 
       62 
     | 
    
         
            -
                    para
         
     | 
| 
       63 
     | 
    
         
            -
                  end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
57 
     | 
    
         
             
                  def dd_bib_extract(dtd)
         
     | 
| 
       66 
58 
     | 
    
         
             
                    return nil if dtd.children.empty?
         
     | 
| 
       67 
59 
     | 
    
         | 
| 
         @@ -110,93 +110,57 @@ module Metanorma 
     | 
|
| 
       110 
110 
     | 
    
         
             
                    { multiplier: :space }
         
     | 
| 
       111 
111 
     | 
    
         
             
                  end
         
     | 
| 
       112 
112 
     | 
    
         | 
| 
      
 113 
     | 
    
         
            +
                  MATHVARIANT_OVERRIDE = {
         
     | 
| 
      
 114 
     | 
    
         
            +
                    bold: { normal: "bold", italic: "bold-italic", fraktur: "bold-fraktur",
         
     | 
| 
      
 115 
     | 
    
         
            +
                            script: "bold-script", "sans-serif": "bold-sans-serif",
         
     | 
| 
      
 116 
     | 
    
         
            +
                            "sans-serif-italic": "sans-serif-bold-italic" },
         
     | 
| 
      
 117 
     | 
    
         
            +
                    italic: { normal: "italic", bod: "bold-italic",
         
     | 
| 
      
 118 
     | 
    
         
            +
                              "sans-serif": "sans-serif-italic",
         
     | 
| 
      
 119 
     | 
    
         
            +
                              "bold-sans-serif": "sans-serif-bold-italic" },
         
     | 
| 
      
 120 
     | 
    
         
            +
                    "bold-italic": { normal: "bold-italic", bold: "bold-italic",
         
     | 
| 
      
 121 
     | 
    
         
            +
                                     italic: "bold-italic",
         
     | 
| 
      
 122 
     | 
    
         
            +
                                     "sans-serif": "sans-serif-bold-italic",
         
     | 
| 
      
 123 
     | 
    
         
            +
                                     "bold-sans-serif": "sans-serif-bold-italic",
         
     | 
| 
      
 124 
     | 
    
         
            +
                                     "sans-serif-italic": "sans-serif-bold-italic" },
         
     | 
| 
      
 125 
     | 
    
         
            +
                    fraktur: { normal: "fraktur", bold: "bold-fraktur" },
         
     | 
| 
      
 126 
     | 
    
         
            +
                    "bold-fraktur": { normal: "bold-fraktur", fraktur: "bold-fraktur" },
         
     | 
| 
      
 127 
     | 
    
         
            +
                    script: { normal: "script", bold: "bold-script" },
         
     | 
| 
      
 128 
     | 
    
         
            +
                    "bold-script": { normal: "script", script: "bold-script" },
         
     | 
| 
      
 129 
     | 
    
         
            +
                    "sans-serif": { normal: "sans-serif", bold: "bold-sans-serif",
         
     | 
| 
      
 130 
     | 
    
         
            +
                                    italic: "sans-serif-italic",
         
     | 
| 
      
 131 
     | 
    
         
            +
                                    "bold-italic": "sans-serif-bold-italic" },
         
     | 
| 
      
 132 
     | 
    
         
            +
                    "bold-sans-serif": { normal: "bold-sans-serif", bold: "bold-sans-serif",
         
     | 
| 
      
 133 
     | 
    
         
            +
                                         "sans-serif": "bold-sans-serif",
         
     | 
| 
      
 134 
     | 
    
         
            +
                                         italic: "sans-serif-bold-italic",
         
     | 
| 
      
 135 
     | 
    
         
            +
                                         "bold-italic": "sans-serif-bold-italic",
         
     | 
| 
      
 136 
     | 
    
         
            +
                                         "sans-serif-italic": "sans-serif-bold-italic" },
         
     | 
| 
      
 137 
     | 
    
         
            +
                    "sans-serif-italic": { normal: "sans-serif-italic",
         
     | 
| 
      
 138 
     | 
    
         
            +
                                           italic: "sans-serif-italic",
         
     | 
| 
      
 139 
     | 
    
         
            +
                                           "sans-serif": "sans-serif-italic",
         
     | 
| 
      
 140 
     | 
    
         
            +
                                           bold: "sans-serif-bold-italic",
         
     | 
| 
      
 141 
     | 
    
         
            +
                                           "bold-italic": "sans-serif-bold-italic",
         
     | 
| 
      
 142 
     | 
    
         
            +
                                           "sans-serif-bold": "sans-serif-bold-italic" },
         
     | 
| 
      
 143 
     | 
    
         
            +
                    "sans-serif-bold-italic": { normal: "sans-serif-bold-italic",
         
     | 
| 
      
 144 
     | 
    
         
            +
                                                italic: "sans-serif-bold-italic",
         
     | 
| 
      
 145 
     | 
    
         
            +
                                                "sans-serif": "sans-serif-bold-italic",
         
     | 
| 
      
 146 
     | 
    
         
            +
                                                "sans-serif-italic": "sans-serif-bold-italic",
         
     | 
| 
      
 147 
     | 
    
         
            +
                                                bold: "sans-serif-bold-italic",
         
     | 
| 
      
 148 
     | 
    
         
            +
                                                "bold-italic": "sans-serif-bold-italic",
         
     | 
| 
      
 149 
     | 
    
         
            +
                                                "sans-serif-bold": "sans-serif-bold-italic" },
         
     | 
| 
      
 150 
     | 
    
         
            +
                  }.freeze
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
       113 
152 
     | 
    
         
             
                  def mathvariant_override(inner, outer)
         
     | 
| 
       114 
     | 
    
         
            -
                     
     | 
| 
       115 
     | 
    
         
            -
                     
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
                      when "italic" then "bold-italic"
         
     | 
| 
       119 
     | 
    
         
            -
                      when "fraktur" then "bold-fraktur"
         
     | 
| 
       120 
     | 
    
         
            -
                      when "script" then "bold-script"
         
     | 
| 
       121 
     | 
    
         
            -
                      when "sans-serif" then "bold-sans-serif"
         
     | 
| 
       122 
     | 
    
         
            -
                      when "sans-serif-italic" then "sans-serif-bold-italic"
         
     | 
| 
       123 
     | 
    
         
            -
                      else inner
         
     | 
| 
       124 
     | 
    
         
            -
                      end
         
     | 
| 
       125 
     | 
    
         
            -
                    when "italic"
         
     | 
| 
       126 
     | 
    
         
            -
                      case inner
         
     | 
| 
       127 
     | 
    
         
            -
                      when "normal" then "italic"
         
     | 
| 
       128 
     | 
    
         
            -
                      when "bold" then "bold-italic"
         
     | 
| 
       129 
     | 
    
         
            -
                      when "sans-serif" then "sans-serif-italic"
         
     | 
| 
       130 
     | 
    
         
            -
                      when "bold-sans-serif" then "sans-serif-bold-italic"
         
     | 
| 
       131 
     | 
    
         
            -
                      else inner
         
     | 
| 
       132 
     | 
    
         
            -
                      end
         
     | 
| 
       133 
     | 
    
         
            -
                    when "bold-italic"
         
     | 
| 
       134 
     | 
    
         
            -
                      case inner
         
     | 
| 
       135 
     | 
    
         
            -
                      when "normal", "bold", "italic" then "bold-italic"
         
     | 
| 
       136 
     | 
    
         
            -
                      when "sans-serif", "bold-sans-serif", "sans-serif-italic"
         
     | 
| 
       137 
     | 
    
         
            -
                        "sans-serif-bold-italic"
         
     | 
| 
       138 
     | 
    
         
            -
                      else inner
         
     | 
| 
       139 
     | 
    
         
            -
                      end
         
     | 
| 
       140 
     | 
    
         
            -
                    when "fraktur"
         
     | 
| 
       141 
     | 
    
         
            -
                      case inner
         
     | 
| 
       142 
     | 
    
         
            -
                      when "normal" then "fraktur"
         
     | 
| 
       143 
     | 
    
         
            -
                      when "bold" then "bold-fraktur"
         
     | 
| 
       144 
     | 
    
         
            -
                      else inner
         
     | 
| 
       145 
     | 
    
         
            -
                      end
         
     | 
| 
       146 
     | 
    
         
            -
                    when "bold-fraktur"
         
     | 
| 
       147 
     | 
    
         
            -
                      case inner
         
     | 
| 
       148 
     | 
    
         
            -
                      when "normal", "fraktur" then "bold-fraktur"
         
     | 
| 
       149 
     | 
    
         
            -
                      else inner
         
     | 
| 
       150 
     | 
    
         
            -
                      end
         
     | 
| 
       151 
     | 
    
         
            -
                    when "script"
         
     | 
| 
       152 
     | 
    
         
            -
                      case inner
         
     | 
| 
       153 
     | 
    
         
            -
                      when "normal" then "script"
         
     | 
| 
       154 
     | 
    
         
            -
                      when "bold" then "bold-script"
         
     | 
| 
       155 
     | 
    
         
            -
                      else inner
         
     | 
| 
       156 
     | 
    
         
            -
                      end
         
     | 
| 
       157 
     | 
    
         
            -
                    when "bold-script"
         
     | 
| 
       158 
     | 
    
         
            -
                      case inner
         
     | 
| 
       159 
     | 
    
         
            -
                      when "normal", "script" then "bold-script"
         
     | 
| 
       160 
     | 
    
         
            -
                      else inner
         
     | 
| 
       161 
     | 
    
         
            -
                      end
         
     | 
| 
       162 
     | 
    
         
            -
                    when "sans-serif"
         
     | 
| 
       163 
     | 
    
         
            -
                      case inner
         
     | 
| 
       164 
     | 
    
         
            -
                      when "normal" then "sans-serif"
         
     | 
| 
       165 
     | 
    
         
            -
                      when "bold" then "bold-sans-serif"
         
     | 
| 
       166 
     | 
    
         
            -
                      when "italic" then "sans-serif-italic"
         
     | 
| 
       167 
     | 
    
         
            -
                      when "bold-italic" then "sans-serif-bold-italic"
         
     | 
| 
       168 
     | 
    
         
            -
                      else inner
         
     | 
| 
       169 
     | 
    
         
            -
                      end
         
     | 
| 
       170 
     | 
    
         
            -
                    when "bold-sans-serif"
         
     | 
| 
       171 
     | 
    
         
            -
                      case inner
         
     | 
| 
       172 
     | 
    
         
            -
                      when "normal", "bold", "sans-serif" then "bold-sans-serif"
         
     | 
| 
       173 
     | 
    
         
            -
                      when "italic", "bold-italic", "sans-serif-italic"
         
     | 
| 
       174 
     | 
    
         
            -
                        "sans-serif-bold-italic"
         
     | 
| 
       175 
     | 
    
         
            -
                      else inner
         
     | 
| 
       176 
     | 
    
         
            -
                      end
         
     | 
| 
       177 
     | 
    
         
            -
                    when "sans-serif-italic"
         
     | 
| 
       178 
     | 
    
         
            -
                      case inner
         
     | 
| 
       179 
     | 
    
         
            -
                      when "normal", "italic", "sans-serif" then "sans-serif-italic"
         
     | 
| 
       180 
     | 
    
         
            -
                      when "bold", "bold-italic", "sans-serif-bold"
         
     | 
| 
       181 
     | 
    
         
            -
                        "sans-serif-bold-italic"
         
     | 
| 
       182 
     | 
    
         
            -
                      else inner
         
     | 
| 
       183 
     | 
    
         
            -
                      end
         
     | 
| 
       184 
     | 
    
         
            -
                    when "sans-serif-bold-italic"
         
     | 
| 
       185 
     | 
    
         
            -
                      case inner
         
     | 
| 
       186 
     | 
    
         
            -
                      when "normal", "italic", "sans-serif", "sans-serif-italic",
         
     | 
| 
       187 
     | 
    
         
            -
                      "bold", "bold-italic", "sans-serif-bold"
         
     | 
| 
       188 
     | 
    
         
            -
                        "sans-serif-bold-italic"
         
     | 
| 
       189 
     | 
    
         
            -
                      else inner
         
     | 
| 
       190 
     | 
    
         
            -
                      end
         
     | 
| 
       191 
     | 
    
         
            -
                    else inner
         
     | 
| 
       192 
     | 
    
         
            -
                    end
         
     | 
| 
      
 153 
     | 
    
         
            +
                    o = outer.to_sym
         
     | 
| 
      
 154 
     | 
    
         
            +
                    i = inner.to_sym
         
     | 
| 
      
 155 
     | 
    
         
            +
                    MATHVARIANT_OVERRIDE[o] or return inner
         
     | 
| 
      
 156 
     | 
    
         
            +
                    MATHVARIANT_OVERRIDE[o][i] || inner
         
     | 
| 
       193 
157 
     | 
    
         
             
                  end
         
     | 
| 
       194 
158 
     | 
    
         | 
| 
       195 
159 
     | 
    
         
             
                  def mathml_mathvariant(math)
         
     | 
| 
       196 
160 
     | 
    
         
             
                    math.xpath(".//*[@mathvariant]").each do |outer|
         
     | 
| 
       197 
161 
     | 
    
         
             
                      outer.xpath(".//*[@mathvariant]").each do |inner|
         
     | 
| 
       198 
162 
     | 
    
         
             
                        inner["mathvariant"] =
         
     | 
| 
       199 
     | 
    
         
            -
                          mathvariant_override( 
     | 
| 
      
 163 
     | 
    
         
            +
                          mathvariant_override(inner["mathvariant"], outer["mathvariant"])
         
     | 
| 
       200 
164 
     | 
    
         
             
                      end
         
     | 
| 
       201 
165 
     | 
    
         
             
                    end
         
     | 
| 
       202 
166 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,9 +1,36 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "set"
         
     | 
| 
       2 
2 
     | 
    
         
             
            require "relaton_bib"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "merge_bibitems"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "spans_to_bibitem"
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
6 
     | 
    
         
             
            module Metanorma
         
     | 
| 
       5 
7 
     | 
    
         
             
              module Standoc
         
     | 
| 
       6 
8 
     | 
    
         
             
                module Cleanup
         
     | 
| 
      
 9 
     | 
    
         
            +
                  def formattedref_spans(xmldoc)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    xmldoc.xpath("//bibitem[formattedref//span]").each do |b|
         
     | 
| 
      
 11 
     | 
    
         
            +
                      ret = new_bibitem_from_formattedref_spans(b)
         
     | 
| 
      
 12 
     | 
    
         
            +
                      merge_bibitem_from_formattedref_spans(b, ret)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    end
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def new_bibitem_from_formattedref_spans(bib)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    ret = SpansToBibitem.new(bib).convert
         
     | 
| 
      
 18 
     | 
    
         
            +
                    ret.err.each do |e|
         
     | 
| 
      
 19 
     | 
    
         
            +
                      @log.add("Bibliography", bib, e[:msg])
         
     | 
| 
      
 20 
     | 
    
         
            +
                      e[:fatal] and @fatalerror << e[:msg]
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                    ret.out
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  def merge_bibitem_from_formattedref_spans(bib, new)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    new["type"] and bib["type"] = new["type"]
         
     | 
| 
      
 27 
     | 
    
         
            +
                    if bib.at("./title") # there already is a fetched record here: merge
         
     | 
| 
      
 28 
     | 
    
         
            +
                      bib.children = MergeBibitems
         
     | 
| 
      
 29 
     | 
    
         
            +
                        .new(bib.to_xml, new.to_xml).merge.to_noko.children
         
     | 
| 
      
 30 
     | 
    
         
            +
                    else bib << new.children.to_xml
         
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       7 
34 
     | 
    
         
             
                  def biblio_reorder(xmldoc)
         
     | 
| 
       8 
35 
     | 
    
         
             
                    xmldoc.xpath("//references[@normative = 'false']").each do |r|
         
     | 
| 
       9 
36 
     | 
    
         
             
                      biblio_reorder1(r)
         
     | 
| 
         @@ -54,9 +81,8 @@ module Metanorma 
     | 
|
| 
       54 
81 
     | 
    
         
             
                                 "[not(@hidden = 'true')]").each do |r|
         
     | 
| 
       55 
82 
     | 
    
         
             
                      r.xpath("./bibitem[not(@hidden = 'true')]").each do |b|
         
     | 
| 
       56 
83 
     | 
    
         
             
                        i += 1
         
     | 
| 
       57 
     | 
    
         
            -
                         
     | 
| 
       58 
     | 
    
         
            -
                         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 84 
     | 
    
         
            +
                        docid = b.at("./docidentifier[@type = 'metanorma']") or next
         
     | 
| 
      
 85 
     | 
    
         
            +
                        /^\[\d+\]$/.match?(docid.text) or next
         
     | 
| 
       60 
86 
     | 
    
         
             
                        docid.children = "[#{i}]"
         
     | 
| 
       61 
87 
     | 
    
         
             
                      end
         
     | 
| 
       62 
88 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -97,8 +123,7 @@ module Metanorma 
     | 
|
| 
       97 
123 
     | 
    
         
             
                  end
         
     | 
| 
       98 
124 
     | 
    
         | 
| 
       99 
125 
     | 
    
         
             
                  def biblio_linkonly(xmldoc)
         
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 126 
     | 
    
         
            +
                    xmldoc.at("//xref[@hidden]") or return
         
     | 
| 
       102 
127 
     | 
    
         
             
                    ins = xmldoc.at("//bibliography")
         
     | 
| 
       103 
128 
     | 
    
         
             
                      .add_child("<references hidden='true' normative='true'/>").first
         
     | 
| 
       104 
129 
     | 
    
         
             
                    refs = xmldoc.xpath("//xref[@hidden]").each_with_object([]) do |x, m|
         
     | 
| 
         @@ -122,8 +147,7 @@ module Metanorma 
     | 
|
| 
       122 
147 
     | 
    
         | 
| 
       123 
148 
     | 
    
         
             
                  def biblio_annex(xmldoc)
         
     | 
| 
       124 
149 
     | 
    
         
             
                    xmldoc.xpath("//annex[references/references]").each do |t|
         
     | 
| 
       125 
     | 
    
         
            -
                       
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
      
 150 
     | 
    
         
            +
                      t.xpath("./clause | ./references | ./terms").size == 1 or next
         
     | 
| 
       127 
151 
     | 
    
         
             
                      r = t.at("./references")
         
     | 
| 
       128 
152 
     | 
    
         
             
                      r.xpath("./references").each { |b| b["normative"] = r["normative"] }
         
     | 
| 
       129 
153 
     | 
    
         
             
                      r.replace(r.elements)
         
     | 
| 
         @@ -140,9 +164,7 @@ module Metanorma 
     | 
|
| 
       140 
164 
     | 
    
         | 
| 
       141 
165 
     | 
    
         
             
                  def format_ref(ref, type)
         
     | 
| 
       142 
166 
     | 
    
         
             
                    ret = Nokogiri::XML.fragment(ref)
         
     | 
| 
       143 
     | 
    
         
            -
                    ret.traverse  
     | 
| 
       144 
     | 
    
         
            -
                      x.remove if x.name == "fn"
         
     | 
| 
       145 
     | 
    
         
            -
                    end
         
     | 
| 
      
 167 
     | 
    
         
            +
                    ret.traverse { |x| x.remove if x.name == "fn"}
         
     | 
| 
       146 
168 
     | 
    
         
             
                    ref = to_xml(ret)
         
     | 
| 
       147 
169 
     | 
    
         
             
                    return @isodoc.docid_prefix(type, ref) if type != "metanorma"
         
     | 
| 
       148 
170 
     | 
    
         
             
                    return "[#{ref}]" if /^\d+$/.match(ref) && !/^\[.*\]$/.match(ref)
         
     | 
| 
         @@ -191,8 +213,7 @@ module Metanorma 
     | 
|
| 
       191 
213 
     | 
    
         
             
                  end
         
     | 
| 
       192 
214 
     | 
    
         | 
| 
       193 
215 
     | 
    
         
             
                  def read_local_bibitem_file(uri)
         
     | 
| 
       194 
     | 
    
         
            -
                     
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
      
 216 
     | 
    
         
            +
                    %r{^https?://}.match?(uri) and return nil
         
     | 
| 
       196 
217 
     | 
    
         
             
                    file = "#{@localdir}#{uri}.rxl"
         
     | 
| 
       197 
218 
     | 
    
         
             
                    File.file?(file) or file = "#{@localdir}#{uri}.xml"
         
     | 
| 
       198 
219 
     | 
    
         
             
                    File.file?(file) or return nil
         
     | 
| 
         @@ -13,11 +13,9 @@ module Metanorma 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                  def replace_title(doc, xpath, text, first = false)
         
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
                    text or return
         
     | 
| 
       18 
17 
     | 
    
         
             
                    doc.xpath(xpath).each_with_index do |node, i|
         
     | 
| 
       19 
     | 
    
         
            -
                       
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
                      first && !i.zero? and next
         
     | 
| 
       21 
19 
     | 
    
         
             
                      title = get_or_make_title(node)
         
     | 
| 
       22 
20 
     | 
    
         
             
                      fn = title.xpath("./fn")
         
     | 
| 
       23 
21 
     | 
    
         
             
                      fn.each(&:remove)
         
     | 
| 
         @@ -39,7 +39,7 @@ module Metanorma 
     | 
|
| 
       39 
39 
     | 
    
         
             
                    end
         
     | 
| 
       40 
40 
     | 
    
         
             
                    node.attr("pub-phone") and person.phone node.attr("pub-phone")
         
     | 
| 
       41 
41 
     | 
    
         
             
                    node.attr("pub-fax") and
         
     | 
| 
       42 
     | 
    
         
            -
                      person.phone node.attr("pub-fax"),  
     | 
| 
      
 42 
     | 
    
         
            +
                      person.phone node.attr("pub-fax"), type: "fax"
         
     | 
| 
       43 
43 
     | 
    
         
             
                    node.attr("pub-email") and person.email node.attr("pub-email")
         
     | 
| 
       44 
44 
     | 
    
         
             
                    node.attr("pub-uri") and person.uri node.attr("pub-uri")
         
     | 
| 
       45 
45 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -48,7 +48,7 @@ module Metanorma 
     | 
|
| 
       48 
48 
     | 
    
         
             
                    csv_split(node.attr("publisher") || default_publisher || "")
         
     | 
| 
       49 
49 
     | 
    
         
             
                      &.each do |p|
         
     | 
| 
       50 
50 
     | 
    
         
             
                      xml.contributor do |c|
         
     | 
| 
       51 
     | 
    
         
            -
                        c.role  
     | 
| 
      
 51 
     | 
    
         
            +
                        c.role type: "author"
         
     | 
| 
       52 
52 
     | 
    
         
             
                        c.organization do |a|
         
     | 
| 
       53 
53 
     | 
    
         
             
                          organization(a, p, false, node, !node.attr("publisher"))
         
     | 
| 
       54 
54 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -69,13 +69,13 @@ module Metanorma 
     | 
|
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                  def personal_role(node, contrib, suffix)
         
     | 
| 
       71 
71 
     | 
    
         
             
                    type = node.attr("role#{suffix}")&.downcase || "author"
         
     | 
| 
       72 
     | 
    
         
            -
                    contrib.role  
     | 
| 
      
 72 
     | 
    
         
            +
                    contrib.role type: type
         
     | 
| 
       73 
73 
     | 
    
         
             
                  end
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
       75 
75 
     | 
    
         
             
                  def personal_contact(node, suffix, person)
         
     | 
| 
       76 
76 
     | 
    
         
             
                    node.attr("phone#{suffix}") and person.phone node.attr("phone#{suffix}")
         
     | 
| 
       77 
77 
     | 
    
         
             
                    node.attr("fax#{suffix}") and
         
     | 
| 
       78 
     | 
    
         
            -
                      person.phone node.attr("fax#{suffix}"),  
     | 
| 
      
 78 
     | 
    
         
            +
                      person.phone node.attr("fax#{suffix}"), type: "fax"
         
     | 
| 
       79 
79 
     | 
    
         
             
                    node.attr("email#{suffix}") and person.email node.attr("email#{suffix}")
         
     | 
| 
       80 
80 
     | 
    
         
             
                    node.attr("contributor-uri#{suffix}") and
         
     | 
| 
       81 
81 
     | 
    
         
             
                      person.uri node.attr("contributor-uri#{suffix}")
         
     | 
| 
         @@ -156,7 +156,7 @@ module Metanorma 
     | 
|
| 
       156 
156 
     | 
    
         
             
                    publishers = node.attr("publisher") || default_publisher || return
         
     | 
| 
       157 
157 
     | 
    
         
             
                    csv_split(publishers)&.each do |p|
         
     | 
| 
       158 
158 
     | 
    
         
             
                      xml.contributor do |c|
         
     | 
| 
       159 
     | 
    
         
            -
                        c.role  
     | 
| 
      
 159 
     | 
    
         
            +
                        c.role type: "publisher"
         
     | 
| 
       160 
160 
     | 
    
         
             
                        c.organization do |a|
         
     | 
| 
       161 
161 
     | 
    
         
             
                          organization(a, p, true, node, !node.attr("publisher"))
         
     | 
| 
       162 
162 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -49,8 +49,7 @@ module Metanorma 
     | 
|
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                  def concatenate_attributes_to_xref_text(node)
         
     | 
| 
       51 
51 
     | 
    
         
             
                    node.attributes.each_with_object([]) do |(k, v), m|
         
     | 
| 
       52 
     | 
    
         
            -
                       
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
                      %w(path fragment refid).include?(k) and next
         
     | 
| 
       54 
53 
     | 
    
         
             
                      m << "#{k}=#{v}%"
         
     | 
| 
       55 
54 
     | 
    
         
             
                    end.map { |x| x.sub(/%+/, "%") }.join + (node.text || "")
         
     | 
| 
       56 
55 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -116,7 +115,7 @@ module Metanorma 
     | 
|
| 
       116 
115 
     | 
    
         
             
                    @fn_number ||= 0
         
     | 
| 
       117 
116 
     | 
    
         
             
                    noko do |xml|
         
     | 
| 
       118 
117 
     | 
    
         
             
                      @fn_number += 1
         
     | 
| 
       119 
     | 
    
         
            -
                      xml.fn  
     | 
| 
      
 118 
     | 
    
         
            +
                      xml.fn reference: @fn_number do |fn|
         
     | 
| 
       120 
119 
     | 
    
         
             
                        fn.p { |p| p << node.text }
         
     | 
| 
       121 
120 
     | 
    
         
             
                      end
         
     | 
| 
       122 
121 
     | 
    
         
             
                    end.join
         
     | 
| 
         @@ -160,16 +159,16 @@ module Metanorma 
     | 
|
| 
       160 
159 
     | 
    
         
             
                    if /<([^:>&]+:)?math(\s+[^>&]+)?> |
         
     | 
| 
       161 
160 
     | 
    
         
             
                      <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
         
     | 
| 
       162 
161 
     | 
    
         
             
                      math = xml_encode(text)
         
     | 
| 
       163 
     | 
    
         
            -
                      xml.stem math,  
     | 
| 
      
 162 
     | 
    
         
            +
                      xml.stem math, type: "MathML"
         
     | 
| 
       164 
163 
     | 
    
         
             
                    elsif style == :latexmath then latex_parse(text, xml)
         
     | 
| 
       165 
164 
     | 
    
         
             
                    else
         
     | 
| 
       166 
     | 
    
         
            -
                      xml.stem text&.gsub(/&#/, "&#"),  
     | 
| 
      
 165 
     | 
    
         
            +
                      xml.stem text&.gsub(/&#/, "&#"), type: "AsciiMath"
         
     | 
| 
       167 
166 
     | 
    
         
             
                    end
         
     | 
| 
       168 
167 
     | 
    
         
             
                  end
         
     | 
| 
       169 
168 
     | 
    
         | 
| 
       170 
169 
     | 
    
         
             
                  def latex_parse(text, xml)
         
     | 
| 
       171 
     | 
    
         
            -
                    latex = latex_parse1(text) or return xml.stem  
     | 
| 
       172 
     | 
    
         
            -
                    xml.stem  
     | 
| 
      
 170 
     | 
    
         
            +
                    latex = latex_parse1(text) or return xml.stem type: "MathML"
         
     | 
| 
      
 171 
     | 
    
         
            +
                    xml.stem type: "MathML" do |s|
         
     | 
| 
       173 
172 
     | 
    
         
             
                      math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
         
     | 
| 
       174 
173 
     | 
    
         
             
                        .elements[0]
         
     | 
| 
       175 
174 
     | 
    
         
             
                      math.delete("alttext")
         
     | 
| 
         @@ -209,7 +208,7 @@ module Metanorma 
     | 
|
| 
       209 
208 
     | 
    
         
             
                        when "smallcap" then xml.smallcap { |s| s << node.text }
         
     | 
| 
       210 
209 
     | 
    
         
             
                        when "keyword" then xml.keyword { |s| s << node.text }
         
     | 
| 
       211 
210 
     | 
    
         
             
                        when /^css /
         
     | 
| 
       212 
     | 
    
         
            -
                          xml.span  
     | 
| 
      
 211 
     | 
    
         
            +
                          xml.span style: node.role.sub(/^css /, "") do |s|
         
     | 
| 
       213 
212 
     | 
    
         
             
                            s << node.text
         
     | 
| 
       214 
213 
     | 
    
         
             
                          end
         
     | 
| 
       215 
214 
     | 
    
         
             
                        else
         
     | 
| 
         @@ -0,0 +1,107 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "metanorma-utils"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Metanorma
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Standoc
         
     | 
| 
      
 5 
     | 
    
         
            +
                module Cleanup
         
     | 
| 
      
 6 
     | 
    
         
            +
                  class MergeBibitems
         
     | 
| 
      
 7 
     | 
    
         
            +
                    Hash.include Metanorma::Utils::Hash
         
     | 
| 
      
 8 
     | 
    
         
            +
                    Array.include Metanorma::Utils::Array
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                    class ::Array
         
     | 
| 
      
 11 
     | 
    
         
            +
                      def blank?
         
     | 
| 
      
 12 
     | 
    
         
            +
                        nil? || empty?
         
     | 
| 
      
 13 
     | 
    
         
            +
                      end
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    def initialize(old, new)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      @old = load_bibitem(old)
         
     | 
| 
      
 18 
     | 
    
         
            +
                      @new = load_bibitem(new)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    def load_bibitem(item)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      ret = RelatonBib::XMLParser.from_xml(item)
         
     | 
| 
      
 23 
     | 
    
         
            +
                      ret.to_hash.symbolize_all_keys
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    def to_noko
         
     | 
| 
      
 27 
     | 
    
         
            +
                      out = RelatonBib::HashConverter.hash_to_bib(@old)
         
     | 
| 
      
 28 
     | 
    
         
            +
                      Nokogiri::XML(RelatonBib::BibliographicItem.new(**out).to_xml).root
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    def merge
         
     | 
| 
      
 32 
     | 
    
         
            +
                      @old.delete(:formattedref)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      merge1(@old, @new)
         
     | 
| 
      
 34 
     | 
    
         
            +
                      self
         
     | 
| 
      
 35 
     | 
    
         
            +
                    end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    def merge1(old, new)
         
     | 
| 
      
 38 
     | 
    
         
            +
                      %i(link docidentifier date title series).each do |k|
         
     | 
| 
      
 39 
     | 
    
         
            +
                        merge_by_type(old, new, k, :type)
         
     | 
| 
      
 40 
     | 
    
         
            +
                      end
         
     | 
| 
      
 41 
     | 
    
         
            +
                      merge_extent(old, new)
         
     | 
| 
      
 42 
     | 
    
         
            +
                      merge_contributor(old, new)
         
     | 
| 
      
 43 
     | 
    
         
            +
                      %i(place).each do |k|
         
     | 
| 
      
 44 
     | 
    
         
            +
                        merge_simple(old, new, k)
         
     | 
| 
      
 45 
     | 
    
         
            +
                      end
         
     | 
| 
      
 46 
     | 
    
         
            +
                      merge_relations(old, new)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                    def merge_simple(old, new, field)
         
     | 
| 
      
 50 
     | 
    
         
            +
                      new[field].blank? and return
         
     | 
| 
      
 51 
     | 
    
         
            +
                      old[field] = new[field]
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                    # ensure return value goes into extent[0]
         
     | 
| 
      
 55 
     | 
    
         
            +
                    def merge_extent(old, new)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      old.dig(:extent, 0, :locality) and
         
     | 
| 
      
 57 
     | 
    
         
            +
                        old[:extent] = [{ locality_stack: old[:extent] }]
         
     | 
| 
      
 58 
     | 
    
         
            +
                      new.dig(:extent, 0, :locality) and
         
     | 
| 
      
 59 
     | 
    
         
            +
                        new[:extent] = [{ locality_stack: new[:extent] }]
         
     | 
| 
      
 60 
     | 
    
         
            +
                      ret = merge_by_type(old.dig(:extent, 0),
         
     | 
| 
      
 61 
     | 
    
         
            +
                                          new.dig(:extent, 0), :locality_stack,
         
     | 
| 
      
 62 
     | 
    
         
            +
                                          %i[locality type])
         
     | 
| 
      
 63 
     | 
    
         
            +
                      (ret && !old.dig(:extent, 0)) or return
         
     | 
| 
      
 64 
     | 
    
         
            +
                      old[:extent] ||= []
         
     | 
| 
      
 65 
     | 
    
         
            +
                      old[:extent][0] ||= {}
         
     | 
| 
      
 66 
     | 
    
         
            +
                      old[:extent][0][:locality_stack] = ret
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                    def merge_contributor(old, new)
         
     | 
| 
      
 70 
     | 
    
         
            +
                      merge_by_type(old, new, :contributor, [:role, 0, :type])
         
     | 
| 
      
 71 
     | 
    
         
            +
                    end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                    def merge_relations(old, new)
         
     | 
| 
      
 74 
     | 
    
         
            +
                      merge_by_type(old, new, :relation, :type, recurse: true)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                    # @old.field is an array, overwrite only those array elements
         
     | 
| 
      
 78 
     | 
    
         
            +
                    # where @old.field[attribute] = @new.field[attribute]
         
     | 
| 
      
 79 
     | 
    
         
            +
                    def merge_by_type(old, new, field, attributes, opt = {})
         
     | 
| 
      
 80 
     | 
    
         
            +
                      new.nil? || new[field].blank? and return
         
     | 
| 
      
 81 
     | 
    
         
            +
                      old.nil? and return new[field]
         
     | 
| 
      
 82 
     | 
    
         
            +
                      if !old[field].is_a?(::Array) || old[field].empty?
         
     | 
| 
      
 83 
     | 
    
         
            +
                        return old[field] = new[field]
         
     | 
| 
      
 84 
     | 
    
         
            +
                      end
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                      old[field] = merge_by_type1(old, new, field, attributes, opt)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                    def merge_by_type1(old, new, field, attributes, opt)
         
     | 
| 
      
 90 
     | 
    
         
            +
                      old1 = array_to_hash(old[field], attributes)
         
     | 
| 
      
 91 
     | 
    
         
            +
                      new1 = array_to_hash(new[field], attributes)
         
     | 
| 
      
 92 
     | 
    
         
            +
                      out = opt[:recurse] ? old1.deep_merge(new1) : old1.merge(new1)
         
     | 
| 
      
 93 
     | 
    
         
            +
                      out.each_value.with_object([]) do |v, m|
         
     | 
| 
      
 94 
     | 
    
         
            +
                        v.each { |v1| m << v1 }
         
     | 
| 
      
 95 
     | 
    
         
            +
                      end
         
     | 
| 
      
 96 
     | 
    
         
            +
                    end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                    def array_to_hash(array, attributes)
         
     | 
| 
      
 99 
     | 
    
         
            +
                      array.each_with_object({}) do |k, m|
         
     | 
| 
      
 100 
     | 
    
         
            +
                        m[k.dig(*Array(attributes))] ||= []
         
     | 
| 
      
 101 
     | 
    
         
            +
                        m[k.dig(*Array(attributes))] << k
         
     | 
| 
      
 102 
     | 
    
         
            +
                      end
         
     | 
| 
      
 103 
     | 
    
         
            +
                    end
         
     | 
| 
      
 104 
     | 
    
         
            +
                  end
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
              end
         
     | 
| 
      
 107 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -6,7 +6,7 @@ module Metanorma 
     | 
|
| 
       6 
6 
     | 
    
         
             
                  def iso_publisher(bib, code)
         
     | 
| 
       7 
7 
     | 
    
         
             
                    code.sub(/ .*$/, "").split("/").each do |abbrev|
         
     | 
| 
       8 
8 
     | 
    
         
             
                      bib.contributor do |c|
         
     | 
| 
       9 
     | 
    
         
            -
                        c.role  
     | 
| 
      
 9 
     | 
    
         
            +
                        c.role type: "publisher"
         
     | 
| 
       10 
10 
     | 
    
         
             
                        c.organization do |org|
         
     | 
| 
       11 
11 
     | 
    
         
             
                          organization(org, abbrev, true)
         
     | 
| 
       12 
12 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -33,7 +33,7 @@ module Metanorma 
     | 
|
| 
       33 
33 
     | 
    
         
             
                    else
         
     | 
| 
       34 
34 
     | 
    
         
             
                      xml.bibitem **attr_code(ref_attributes(item[:ref][:match])) do |t|
         
     | 
| 
       35 
35 
     | 
    
         
             
                        isorefrender1(t, item[:ref][:match], item[:ref][:year])
         
     | 
| 
       36 
     | 
    
         
            -
                        item[:ref][:year] and t.date  
     | 
| 
      
 36 
     | 
    
         
            +
                        item[:ref][:year] and t.date type: "published" do |d|
         
     | 
| 
       37 
37 
     | 
    
         
             
                          set_date_range(d, item[:ref][:year])
         
     | 
| 
       38 
38 
     | 
    
         
             
                        end
         
     | 
| 
       39 
39 
     | 
    
         
             
                        iso_publisher(t, item[:ref][:match][:code])
         
     | 
| 
         @@ -56,7 +56,7 @@ module Metanorma 
     | 
|
| 
       56 
56 
     | 
    
         
             
                  def isorefmatches2_1(xml, match)
         
     | 
| 
       57 
57 
     | 
    
         
             
                    xml.bibitem **attr_code(ref_attributes(match)) do |t|
         
     | 
| 
       58 
58 
     | 
    
         
             
                      isorefrender1(t, match, "--")
         
     | 
| 
       59 
     | 
    
         
            -
                      t.date  
     | 
| 
      
 59 
     | 
    
         
            +
                      t.date type: "published" do |d|
         
     | 
| 
       60 
60 
     | 
    
         
             
                        d.on "--"
         
     | 
| 
       61 
61 
     | 
    
         
             
                      end
         
     | 
| 
       62 
62 
     | 
    
         
             
                      iso_publisher(t, match[:code])
         
     | 
| 
         @@ -97,7 +97,7 @@ module Metanorma 
     | 
|
| 
       97 
97 
     | 
    
         
             
                          p << (match[:fn]).to_s
         
     | 
| 
       98 
98 
     | 
    
         
             
                        end
         
     | 
| 
       99 
99 
     | 
    
         
             
                      end
         
     | 
| 
       100 
     | 
    
         
            -
                      t.extent  
     | 
| 
      
 100 
     | 
    
         
            +
                      t.extent type: "part" do |e|
         
     | 
| 
       101 
101 
     | 
    
         
             
                        e.referenceFrom "all"
         
     | 
| 
       102 
102 
     | 
    
         
             
                      end
         
     | 
| 
       103 
103 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -105,21 +105,21 @@ module Metanorma 
     | 
|
| 
       105 
105 
     | 
    
         | 
| 
       106 
106 
     | 
    
         
             
                  def refitem_render1(match, code, bib)
         
     | 
| 
       107 
107 
     | 
    
         
             
                    if code[:type] == "path"
         
     | 
| 
       108 
     | 
    
         
            -
                      bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""),  
     | 
| 
       109 
     | 
    
         
            -
                      bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""),  
     | 
| 
      
 108 
     | 
    
         
            +
                      bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), type: "URI"
         
     | 
| 
      
 109 
     | 
    
         
            +
                      bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), type: "citation"
         
     | 
| 
       110 
110 
     | 
    
         
             
                    end
         
     | 
| 
       111 
111 
     | 
    
         
             
                    # code[:id].sub!(/[:-](19|20)[0-9][0-9]$/, "")
         
     | 
| 
       112 
112 
     | 
    
         
             
                    docid(bib, match[:usrlbl]) if match[:usrlbl]
         
     | 
| 
       113 
113 
     | 
    
         
             
                    docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
         
     | 
| 
       114 
114 
     | 
    
         
             
                    code[:type] == "repo" and
         
     | 
| 
       115 
     | 
    
         
            -
                      bib.docidentifier code[:key],  
     | 
| 
      
 115 
     | 
    
         
            +
                      bib.docidentifier code[:key], type: "repository"
         
     | 
| 
       116 
116 
     | 
    
         
             
                  end
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                  def refitem_render(xml, match, code)
         
     | 
| 
       119 
119 
     | 
    
         
             
                    xml.bibitem **attr_code(id: match[:anchor],
         
     | 
| 
       120 
120 
     | 
    
         
             
                                            suppress_identifier: code[:dropid],
         
     | 
| 
       121 
121 
     | 
    
         
             
                                            hidden: code[:hidden]) do |t|
         
     | 
| 
       122 
     | 
    
         
            -
                      t.formattedref  
     | 
| 
      
 122 
     | 
    
         
            +
                      t.formattedref format: "application/x-isodoc+xml" do |i|
         
     | 
| 
       123 
123 
     | 
    
         
             
                        i << ref_normalise_no_format(match[:text])
         
     | 
| 
       124 
124 
     | 
    
         
             
                      end
         
     | 
| 
       125 
125 
     | 
    
         
             
                      yr_match = /[:-](?<year>(?:19|20)[0-9][0-9])\b/.match(code[:id])
         
     | 
| 
         @@ -156,8 +156,7 @@ module Metanorma 
     | 
|
| 
       156 
156 
     | 
    
         
             
                  end
         
     | 
| 
       157 
157 
     | 
    
         | 
| 
       158 
158 
     | 
    
         
             
                  def refitemout(item, xml)
         
     | 
| 
       159 
     | 
    
         
            -
                     
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
      
 159 
     | 
    
         
            +
                    item[:ref][:match].nil? and return nil
         
     | 
| 
       161 
160 
     | 
    
         
             
                    item[:doc] or return refitem_render(xml, item[:ref][:match],
         
     | 
| 
       162 
161 
     | 
    
         
             
                                                        item[:ref][:analyse_code])
         
     | 
| 
       163 
162 
     | 
    
         
             
                    use_retrieved_relaton(item, xml)
         
     | 
| 
         @@ -85,8 +85,13 @@ module Metanorma 
     | 
|
| 
       85 
85 
     | 
    
         
             
                    end
         
     | 
| 
       86 
86 
     | 
    
         
             
                  end
         
     | 
| 
       87 
87 
     | 
    
         | 
| 
      
 88 
     | 
    
         
            +
                  def fetchable_ref_code?(ref)
         
     | 
| 
      
 89 
     | 
    
         
            +
                    ref[:code].nil? || ref[:code].empty? || ref[:no_year] ||
         
     | 
| 
      
 90 
     | 
    
         
            +
                      (@bibdb.nil? && !ref[:localfile])
         
     | 
| 
      
 91 
     | 
    
         
            +
                  end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
       88 
93 
     | 
    
         
             
                  def fetch_ref_async(ref, idx, res)
         
     | 
| 
       89 
     | 
    
         
            -
                    if  
     | 
| 
      
 94 
     | 
    
         
            +
                    if fetchable_ref_code?(ref)
         
     | 
| 
       90 
95 
     | 
    
         
             
                      res << [ref, idx, nil]
         
     | 
| 
       91 
96 
     | 
    
         
             
                    elsif ref[:localfile]
         
     | 
| 
       92 
97 
     | 
    
         
             
                      res << [ref, idx, @local_bibdb.get(ref[:code], ref[:localfile])]
         
     | 
| 
         @@ -115,12 +120,16 @@ module Metanorma 
     | 
|
| 
       115 
120 
     | 
    
         
             
                    end
         
     | 
| 
       116 
121 
     | 
    
         
             
                  end
         
     | 
| 
       117 
122 
     | 
    
         | 
| 
      
 123 
     | 
    
         
            +
                  # supply title if missing;
         
     | 
| 
      
 124 
     | 
    
         
            +
                  # add title with spans in it as formattedref, to emend bibitem with later
         
     | 
| 
       118 
125 
     | 
    
         
             
                  def emend_biblio_title(xml, code, title)
         
     | 
| 
       119 
126 
     | 
    
         
             
                    unless xml.at("/bibitem/title[text()]")
         
     | 
| 
       120 
127 
     | 
    
         
             
                      @log.add("Bibliography", nil,
         
     | 
| 
       121 
128 
     | 
    
         
             
                               "ERROR: No title retrieved for #{code}")
         
     | 
| 
       122 
129 
     | 
    
         
             
                      xml.root << "<title>#{title || '(MISSING TITLE)'}</title>"
         
     | 
| 
       123 
130 
     | 
    
         
             
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
                    /<span class=/.match?(title) and
         
     | 
| 
      
 132 
     | 
    
         
            +
                      xml.root << "<formattedref>#{title}</formattedref>"
         
     | 
| 
       124 
133 
     | 
    
         
             
                  end
         
     | 
| 
       125 
134 
     | 
    
         | 
| 
       126 
135 
     | 
    
         
             
                  def emend_biblio_usrlbl(xml, usrlbl)
         
     | 
| 
         @@ -110,8 +110,7 @@ module Metanorma 
     | 
|
| 
       110 
110 
     | 
    
         
             
                  # dropid(code) | # (repo|path):(key,code) | local-file(source,? key)
         
     | 
| 
       111 
111 
     | 
    
         
             
                  def analyse_ref_code(code)
         
     | 
| 
       112 
112 
     | 
    
         
             
                    ret = { id: code }
         
     | 
| 
       113 
     | 
    
         
            -
                     
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
      
 113 
     | 
    
         
            +
                    code.nil? || code.empty? and return ret
         
     | 
| 
       115 
114 
     | 
    
         
             
                    analyse_ref_numeric(
         
     | 
| 
       116 
115 
     | 
    
         
             
                      analyse_ref_repo_path(
         
     | 
| 
       117 
116 
     | 
    
         
             
                        analyse_ref_dropid(
         
     | 
| 
         @@ -85,12 +85,12 @@ module Metanorma 
     | 
|
| 
       85 
85 
     | 
    
         | 
| 
       86 
86 
     | 
    
         
             
                  def pdf_extract_attributes(node)
         
     | 
| 
       87 
87 
     | 
    
         
             
                    pdf_options = %w(pdf-encrypt pdf-encryption-length pdf-user-password
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 88 
     | 
    
         
            +
                                     pdf-owner-password pdf-allow-copy-content
         
     | 
| 
      
 89 
     | 
    
         
            +
                                     pdf-allow-edit-content pdf-allow-fill-in-forms
         
     | 
| 
      
 90 
     | 
    
         
            +
                                     pdf-allow-assemble-document pdf-allow-edit-annotations
         
     | 
| 
      
 91 
     | 
    
         
            +
                                     pdf-allow-print pdf-allow-print-hq
         
     | 
| 
      
 92 
     | 
    
         
            +
                                     pdf-allow-access-content pdf-encrypt-metadata fonts
         
     | 
| 
      
 93 
     | 
    
         
            +
                                     font-license-agreement).each_with_object({}) do |x, m|
         
     | 
| 
       94 
94 
     | 
    
         
             
                      m[x.gsub(/-/, "").to_i] = node.attr(x)
         
     | 
| 
       95 
95 
     | 
    
         
             
                    end
         
     | 
| 
       96 
96 
     | 
    
         |