metanorma-standoc 2.9.5 → 2.9.7
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 +4 -1
- data/lib/metanorma/standoc/base.rb +8 -8
- data/lib/metanorma/standoc/basicdoc.rng +909 -464
- data/lib/metanorma/standoc/biblio-standoc.rng +87 -20
- data/lib/metanorma/standoc/biblio.rng +884 -325
- data/lib/metanorma/standoc/blocks.rb +1 -1
- data/lib/metanorma/standoc/cleanup.rb +4 -2
- data/lib/metanorma/standoc/cleanup_bibitem.rb +18 -6
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +9 -93
- data/lib/metanorma/standoc/cleanup_inline.rb +1 -1
- data/lib/metanorma/standoc/cleanup_maths.rb +51 -101
- data/lib/metanorma/standoc/cleanup_mathvariant.rb +88 -0
- data/lib/metanorma/standoc/cleanup_terms.rb +4 -1
- data/lib/metanorma/standoc/cleanup_terms_boilerplate.rb +106 -0
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +1 -2
- data/lib/metanorma/standoc/cleanup_text.rb +11 -4
- data/lib/metanorma/standoc/cleanup_xref.rb +1 -1
- data/lib/metanorma/standoc/converter.rb +2 -0
- data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +1 -1
- data/lib/metanorma/standoc/init.rb +23 -4
- data/lib/metanorma/standoc/inline.rb +27 -14
- data/lib/metanorma/standoc/isodoc.rng +1031 -912
- data/lib/metanorma/standoc/localbib.rb +1 -1
- data/lib/metanorma/standoc/macros.rb +1 -1
- data/lib/metanorma/standoc/macros_inline.rb +11 -9
- data/lib/metanorma/standoc/macros_plantuml.rb +1 -1
- data/lib/metanorma/standoc/ref.rb +1 -1
- data/lib/metanorma/standoc/ref_queue.rb +1 -1
- data/lib/metanorma/standoc/ref_utility.rb +7 -6
- data/lib/metanorma/standoc/reqt.rng +94 -72
- data/lib/metanorma/standoc/section.rb +2 -2
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +2 -2
- data/lib/metanorma/standoc/utils.rb +4 -2
- data/lib/metanorma/standoc/version.rb +1 -1
- metadata +4 -2
| @@ -2,8 +2,8 @@ module Metanorma | |
| 2 2 | 
             
              module Standoc
         | 
| 3 3 | 
             
                module Cleanup
         | 
| 4 4 | 
             
                  def textcleanup(result)
         | 
| 5 | 
            -
                    text = result.flatten.map | 
| 6 | 
            -
                    text = text.gsub( | 
| 5 | 
            +
                    text = result.flatten.map(&:rstrip) * "\n"
         | 
| 6 | 
            +
                    text = text.gsub(/(?<!\s)\s+<fn /, "<fn ")
         | 
| 7 7 | 
             
                    %w(passthrough passthrough-inline).each do |v|
         | 
| 8 8 | 
             
                      text.gsub!(%r{<#{v}\s+formats="metanorma">([^<]*)
         | 
| 9 9 | 
             
                                </#{v}>}mx) { @c.decode($1) }
         | 
| @@ -40,14 +40,21 @@ module Metanorma | |
| 40 40 | 
             
                  def linebreak_cleanup_block(block)
         | 
| 41 41 | 
             
                    block.each_with_index do |e, i|
         | 
| 42 42 | 
             
                      e[:skip] and next
         | 
| 43 | 
            -
                      lines = e[ | 
| 44 | 
            -
                      e[:last] or lines << block[i + 1][:text].lines.first # next token context
         | 
| 43 | 
            +
                      lines = lines_strip_textspan(e, block[i + 1])
         | 
| 45 44 | 
             
                      out = Metanorma::Utils.line_sanitise(lines)
         | 
| 46 45 | 
             
                      e[:last] or out.pop
         | 
| 47 46 | 
             
                      e[:elem].replace(out.join)
         | 
| 48 47 | 
             
                    end
         | 
| 49 48 | 
             
                  end
         | 
| 50 49 |  | 
| 50 | 
            +
                  def lines_strip_textspan(span, nextspan)
         | 
| 51 | 
            +
                    lines = span[:text].lines[0..-2].map(&:rstrip) <<
         | 
| 52 | 
            +
                      span[:text].lines[-1]&.sub(/\n$/, "")
         | 
| 53 | 
            +
                    # no final line rstrip: can be space linking to next line
         | 
| 54 | 
            +
                    span[:last] or lines << nextspan[:text].lines.first # next token context
         | 
| 55 | 
            +
                    lines
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 51 58 | 
             
                  def gather_text_for_linebreak_cleanup(block)
         | 
| 52 59 | 
             
                    x = block.xpath(".//text()").map do |e|
         | 
| 53 60 | 
             
                      { elem: e, text: e.text,
         | 
| @@ -176,7 +176,7 @@ module Metanorma | |
| 176 176 |  | 
| 177 177 | 
             
                  def xref_compound_cleanup1(xref, locations)
         | 
| 178 178 | 
             
                    xref.children.empty? and xref.children = "<sentinel/>"
         | 
| 179 | 
            -
                    xref_parse_compound_locations(locations). | 
| 179 | 
            +
                    xref_parse_compound_locations(locations).reverse_each do |y|
         | 
| 180 180 | 
             
                      xref.children.first.previous =
         | 
| 181 181 | 
             
                        "<xref target='#{y[1]}' connective='#{y[0]}'/>"
         | 
| 182 182 | 
             
                    end
         | 
| @@ -25,6 +25,7 @@ module Metanorma | |
| 25 25 | 
             
                    preprocessor Metanorma::Plugin::Lutaml::LutamlPreprocessor
         | 
| 26 26 | 
             
                    preprocessor Metanorma::Plugin::Lutaml::LutamlUmlAttributesTablePreprocessor
         | 
| 27 27 | 
             
                    preprocessor Metanorma::Plugin::Lutaml::LutamlUmlDatamodelDescriptionPreprocessor
         | 
| 28 | 
            +
                    preprocessor Metanorma::Plugin::Lutaml::LutamlEaXmiPreprocessor
         | 
| 28 29 | 
             
                    preprocessor Metanorma::Plugin::Lutaml::LutamlUmlClassPreprocessor
         | 
| 29 30 | 
             
                    inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
         | 
| 30 31 | 
             
                    inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
         | 
| @@ -33,6 +34,7 @@ module Metanorma | |
| 33 34 | 
             
                    block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
         | 
| 34 35 | 
             
                    block_macro Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlockMacro
         | 
| 35 36 | 
             
                    block Metanorma::Plugin::Lutaml::LutamlGmlDictionaryBlock
         | 
| 37 | 
            +
                    block_macro Metanorma::Plugin::Lutaml::LutamlKlassTableBlockMacro
         | 
| 36 38 | 
             
                    preprocessor Metanorma::Standoc::EmbedIncludeProcessor
         | 
| 37 39 | 
             
                    preprocessor Metanorma::Standoc::LinkProtectPreprocessor
         | 
| 38 40 | 
             
                    preprocessor Metanorma::Standoc::Datamodel::AttributesTablePreprocessor
         | 
| @@ -7,6 +7,8 @@ module Metanorma | |
| 7 7 | 
             
                    init_vars
         | 
| 8 8 | 
             
                    init_misc(node)
         | 
| 9 9 | 
             
                    init_processing(node)
         | 
| 10 | 
            +
                    init_log(node)
         | 
| 11 | 
            +
                    init_image(node)
         | 
| 10 12 | 
             
                    init_reqt(node)
         | 
| 11 13 | 
             
                    init_toc(node)
         | 
| 12 14 | 
             
                    init_output(node) # feeds init_biblio
         | 
| @@ -47,11 +49,22 @@ module Metanorma | |
| 47 49 | 
             
                    @smartquotes = node.attr("smartquotes") != "false"
         | 
| 48 50 | 
             
                    @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
         | 
| 49 51 | 
             
                    @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
         | 
| 52 | 
            +
                    @blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
         | 
| 53 | 
            +
                      .map(&:strip)
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  def init_log(node)
         | 
| 57 | 
            +
                    @log or return
         | 
| 58 | 
            +
                    severity = node.attr("log-filter-severity")&.to_i || 4
         | 
| 59 | 
            +
                    category = node.attr("log-filter-category") || ""
         | 
| 60 | 
            +
                    category = category.split(",").map(&:strip)
         | 
| 61 | 
            +
                    @log.suppress_log = { severity:, category: }
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def init_image(node)
         | 
| 50 65 | 
             
                    @datauriimage = node.attr("data-uri-image") != "false"
         | 
| 51 66 | 
             
                    @datauriattachment = node.attr("data-uri-attachment") != "false"
         | 
| 52 67 | 
             
                    @dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013
         | 
| 53 | 
            -
                    @blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
         | 
| 54 | 
            -
                      .map(&:strip)
         | 
| 55 68 | 
             
                  end
         | 
| 56 69 |  | 
| 57 70 | 
             
                  def init_reqt(node)
         | 
| @@ -103,6 +116,7 @@ module Metanorma | |
| 103 116 | 
             
                  def init_biblio(node)
         | 
| 104 117 | 
             
                    @no_isobib_cache = node.attr("no-isobib-cache")
         | 
| 105 118 | 
             
                    @no_isobib = node.attr("no-isobib")
         | 
| 119 | 
            +
                    @flush_caches = node.attr("flush-caches")
         | 
| 106 120 | 
             
                    init_bib_log
         | 
| 107 121 | 
             
                    @bibdb = nil
         | 
| 108 122 | 
             
                    init_bib_caches(node)
         | 
| @@ -122,10 +136,15 @@ module Metanorma | |
| 122 136 | 
             
                  def init_math(node)
         | 
| 123 137 | 
             
                    @keepasciimath = node.attr("mn-keep-asciimath") &&
         | 
| 124 138 | 
             
                      node.attr("mn-keep-asciimath") != "false"
         | 
| 125 | 
            -
                    @numberfmt_default = kv_parse(node.attr("number-presentation"))
         | 
| 139 | 
            +
                    @numberfmt_default = kv_parse(@c.decode(node.attr("number-presentation")))
         | 
| 140 | 
            +
                    @numberfmt_formula = @c.decode(node.attr("number-presentation-formula"))
         | 
| 141 | 
            +
                    @numberfmt_formula == "number-presentation" and
         | 
| 142 | 
            +
                      @numberfmt_formula = @c.decode(node.attr("number-presentation"))
         | 
| 143 | 
            +
                    @numberfmt_formula == "default" and
         | 
| 144 | 
            +
                      @numberfmt_formula = "notation='basic'"
         | 
| 126 145 | 
             
                    @numberfmt_prof =  node.attributes.each_with_object({}) do |(k, v), m|
         | 
| 127 146 | 
             
                      p = /^number-presentation-profile-(.*)$/.match(k) or next
         | 
| 128 | 
            -
                      m[p[1]] = kv_parse(v)
         | 
| 147 | 
            +
                      m[p[1]] = kv_parse(@c.decode(v))
         | 
| 129 148 | 
             
                    end
         | 
| 130 149 | 
             
                  end
         | 
| 131 150 |  | 
| @@ -39,25 +39,38 @@ module Metanorma | |
| 39 39 | 
             
                    results.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 |  | 
| 42 | 
            -
                  def stem_parse(text, xml, style,  | 
| 42 | 
            +
                  def stem_parse(text, xml, style, node)
         | 
| 43 | 
            +
                    attrs, text = stem_attrs(node, text)
         | 
| 43 44 | 
             
                    if /<([^:>&]+:)?math(\s+[^>&]+)?> |
         | 
| 44 45 | 
             
                      <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
         | 
| 45 | 
            -
                       | 
| 46 | 
            -
             | 
| 47 | 
            -
                        s << math
         | 
| 46 | 
            +
                      xml.stem **attrs.merge(type: "MathML") do |s|
         | 
| 47 | 
            +
                        s << xml_encode(text)
         | 
| 48 48 | 
             
                      end
         | 
| 49 | 
            -
                    elsif style == :latexmath then latex_parse(text, xml,  | 
| 49 | 
            +
                    elsif style == :latexmath then latex_parse(text, xml, attrs)
         | 
| 50 50 | 
             
                    else
         | 
| 51 | 
            -
                      xml.stem text&.gsub("&#", "&#"), type: "AsciiMath" | 
| 51 | 
            +
                      xml.stem text&.gsub("&#", "&#"), **attrs.merge(type: "AsciiMath")
         | 
| 52 52 | 
             
                    end
         | 
| 53 53 | 
             
                  end
         | 
| 54 54 |  | 
| 55 | 
            -
                   | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                     | 
| 55 | 
            +
                  STEM_ATTRS = "number-format".freeze
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  def stem_attrs(node, text)
         | 
| 58 | 
            +
                    attrs = STEM_ATTRS.split("|").each_with_object({}) do |k, m|
         | 
| 59 | 
            +
                      n = node.attr(k) and m[k.to_sym] = n
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
                    while m = /^(#{STEM_ATTRS})(=[^%]+)?%(.*)$/o.match(text)
         | 
| 62 | 
            +
                      text = m[3]
         | 
| 63 | 
            +
                      attrs[m[1].to_sym] = m[2]&.sub(/^=/, "")
         | 
| 64 | 
            +
                    end
         | 
| 65 | 
            +
                    [{ block: node.block? }.merge(attrs), text]
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  def latex_parse(text, xml, attr)
         | 
| 69 | 
            +
                    latex = latex_parse1(text, attr[:block]) or
         | 
| 70 | 
            +
                      return xml.stem **attr.merge(type: "MathML")
         | 
| 71 | 
            +
                    xml.stem **attr.merge(type: "MathML") do |s|
         | 
| 59 72 | 
             
                      math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
         | 
| 60 | 
            -
             | 
| 73 | 
            +
                        .elements[0]
         | 
| 61 74 | 
             
                      math.delete("alttext")
         | 
| 62 75 | 
             
                      s.parent.children = math
         | 
| 63 76 | 
             
                      s << "<latexmath>#{text}</latexmath>"
         | 
| @@ -78,8 +91,8 @@ module Metanorma | |
| 78 91 | 
             
                      when :single then xml << "'#{node.text}'"
         | 
| 79 92 | 
             
                      when :superscript then xml.sup { |s| s << node.text }
         | 
| 80 93 | 
             
                      when :subscript then xml.sub { |s| s << node.text }
         | 
| 81 | 
            -
                      when :asciimath then stem_parse(node.text, xml, :asciimath,  | 
| 82 | 
            -
                      when :latexmath then stem_parse(node.text, xml, :latexmath,  | 
| 94 | 
            +
                      when :asciimath then stem_parse(node.text, xml, :asciimath, node)
         | 
| 95 | 
            +
                      when :latexmath then stem_parse(node.text, xml, :latexmath, node)
         | 
| 83 96 | 
             
                      when :mark then highlight_parse(node.text, xml)
         | 
| 84 97 | 
             
                      else
         | 
| 85 98 | 
             
                        case node.role
         | 
| @@ -123,7 +136,7 @@ module Metanorma | |
| 123 136 | 
             
                    end
         | 
| 124 137 | 
             
                    uri = node.image_uri (nodetarget)
         | 
| 125 138 | 
             
                    if Gem.win_platform? && /^\/[a-zA-Z]:/.match?(uri)
         | 
| 126 | 
            -
                      uri = uri[1 | 
| 139 | 
            +
                      uri = uri[1..]
         | 
| 127 140 | 
             
                    end
         | 
| 128 141 | 
             
                    types = if /^data:/.match?(uri) then Vectory::Utils::datauri2mime(uri)
         | 
| 129 142 | 
             
                            else MIME::Types.type_for(uri)
         |