isodoc 1.8.0 → 1.8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/isodoc.gemspec +1 -1
- data/lib/isodoc/class_utils.rb +1 -1
- data/lib/isodoc/convert.rb +8 -0
- data/lib/isodoc/function/inline.rb +3 -5
- data/lib/isodoc/html_function/html.rb +1 -0
- data/lib/isodoc/html_function/postprocess.rb +4 -6
- data/lib/isodoc/metadata_date.rb +13 -11
- data/lib/isodoc/presentation_function/bibdata.rb +2 -2
- data/lib/isodoc/presentation_function/terms.rb +74 -30
- data/lib/isodoc/presentation_xml_convert.rb +1 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +24 -14
- data/lib/isodoc/word_function/comments.rb +0 -4
- data/lib/isodoc/xref/xref_gen.rb +18 -22
- data/lib/isodoc/xref/xref_gen_seq.rb +10 -16
- data/lib/isodoc-yaml/i18n-ar.yaml +3 -0
- data/lib/isodoc-yaml/i18n-de.yaml +3 -0
- data/lib/isodoc-yaml/i18n-en.yaml +8 -5
- data/lib/isodoc-yaml/i18n-es.yaml +3 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +3 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +3 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +3 -0
- data/spec/isodoc/blocks_spec.rb +14 -8
- data/spec/isodoc/i18n_spec.rb +15 -10
- data/spec/isodoc/inline_spec.rb +33 -43
- data/spec/isodoc/lists_spec.rb +344 -222
- data/spec/isodoc/section_spec.rb +12 -12
- data/spec/isodoc/table_spec.rb +71 -73
- data/spec/isodoc/terms_spec.rb +266 -212
- data/spec/isodoc/xref_numbering_spec.rb +347 -0
- data/spec/isodoc/xref_spec.rb +271 -350
- data/spec/spec_helper.rb +1 -1
- metadata +8 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: acaea1b02c6f852beb40a1344fff745a7ff335cebba6484151acc0e73d4146a4
         | 
| 4 | 
            +
              data.tar.gz: 23fce1207ac948de9b61c487dc8a91c2fd8ceeddb1a522b3608a85aad02c1923
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ad28bd8420ad35320fc9f67470bf5e4b44b3dc7e27c48867e50bfc6446ed0b57709bc4576518337e87bf72f8920a8035e4a34dd7486c7f739c2edcfc348b709e
         | 
| 7 | 
            +
              data.tar.gz: 3c04a7a2eb965caeda51cd538a770387bb7d0a610893f46b6c09f4ef44178024b493c077390f0a6e765b17330e3af5004e2308964920061eef3f10c73e894b2e
         | 
    
        data/isodoc.gemspec
    CHANGED
    
    | @@ -43,7 +43,7 @@ Gem::Specification.new do |spec| | |
| 43 43 | 
             
              spec.add_dependency "twitter_cldr", ">= 6.6.0"
         | 
| 44 44 | 
             
              spec.add_dependency "uuidtools"
         | 
| 45 45 |  | 
| 46 | 
            -
              spec.add_development_dependency " | 
| 46 | 
            +
              spec.add_development_dependency "debug"
         | 
| 47 47 | 
             
              spec.add_development_dependency "equivalent-xml", "~> 0.6"
         | 
| 48 48 | 
             
              spec.add_development_dependency "guard", "~> 2.14"
         | 
| 49 49 | 
             
              spec.add_development_dependency "guard-rspec", "~> 4.7"
         | 
    
        data/lib/isodoc/class_utils.rb
    CHANGED
    
    | @@ -16,7 +16,7 @@ module IsoDoc | |
| 16 16 | 
             
                  xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1")
         | 
| 17 17 | 
             
                    .gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
         | 
| 18 18 | 
             
                    .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1")
         | 
| 19 | 
            -
                    .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/] | 
| 19 | 
            +
                    .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*[/\]])}, "[xmlns:\\1")
         | 
| 20 20 | 
             
                end
         | 
| 21 21 |  | 
| 22 22 | 
             
                def liquid(doc)
         | 
    
        data/lib/isodoc/convert.rb
    CHANGED
    
    | @@ -119,6 +119,7 @@ module IsoDoc | |
| 119 119 |  | 
| 120 120 | 
             
                def convert1(docxml, filename, dir)
         | 
| 121 121 | 
             
                  @xrefs.parse docxml
         | 
| 122 | 
            +
                  bibitem_lookup(docxml)
         | 
| 122 123 | 
             
                  noko do |xml|
         | 
| 123 124 | 
             
                    xml.html **{ lang: @lang.to_s } do |html|
         | 
| 124 125 | 
             
                      html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
         | 
| @@ -130,6 +131,13 @@ module IsoDoc | |
| 130 131 | 
             
                  end.join("\n")
         | 
| 131 132 | 
             
                end
         | 
| 132 133 |  | 
| 134 | 
            +
                def bibitem_lookup(docxml)
         | 
| 135 | 
            +
                  @bibitems = docxml.xpath(ns("//references/bibitem"))
         | 
| 136 | 
            +
                    .each_with_object({}) do |b, m|
         | 
| 137 | 
            +
                    m[b["id"]] = b
         | 
| 138 | 
            +
                  end
         | 
| 139 | 
            +
                end
         | 
| 140 | 
            +
             | 
| 133 141 | 
             
                def metadata_init(lang, script, i18n)
         | 
| 134 142 | 
             
                  @meta = Metadata.new(lang, script, i18n)
         | 
| 135 143 | 
             
                end
         | 
| @@ -5,7 +5,7 @@ module IsoDoc | |
| 5 5 | 
             
                module Inline
         | 
| 6 6 | 
             
                  def link_parse(node, out)
         | 
| 7 7 | 
             
                    url = node["target"]
         | 
| 8 | 
            -
                    node[" | 
| 8 | 
            +
                    node["update-type"] == "true" and url = suffix_url(url)
         | 
| 9 9 | 
             
                    out.a **attr_code(href: url, title: node["alt"]) do |l|
         | 
| 10 10 | 
             
                      if node.text.empty?
         | 
| 11 11 | 
             
                        l << node["target"].sub(/^mailto:/, "")
         | 
| @@ -41,10 +41,8 @@ module IsoDoc | |
| 41 41 | 
             
                  end
         | 
| 42 42 |  | 
| 43 43 | 
             
                  def eref_target(node)
         | 
| 44 | 
            -
                     | 
| 45 | 
            -
             | 
| 46 | 
            -
                                     "uri[@type = 'citation']"))
         | 
| 47 | 
            -
                    return href unless url
         | 
| 44 | 
            +
                    return "##{node['bibitemid']}" unless url = @bibitems[node["bibitemid"]]
         | 
| 45 | 
            +
                      &.at(ns("./uri[@type = 'citation']"))
         | 
| 48 46 |  | 
| 49 47 | 
             
                    href = suffix_url(url.text)
         | 
| 50 48 | 
             
                    anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
         | 
| @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require "isodoc/html_function/mathvariant_to_plain"
         | 
| 2 2 | 
             
            require_relative "postprocess_footnotes"
         | 
| 3 | 
            +
            require "metanorma-utils"
         | 
| 3 4 |  | 
| 4 5 | 
             
            module IsoDoc
         | 
| 5 6 | 
             
              module HtmlFunction
         | 
| @@ -74,7 +75,8 @@ module IsoDoc | |
| 74 75 | 
             
                    head = docxml.at("//*[local-name() = 'head']")
         | 
| 75 76 | 
             
                    head << htmlstylesheet(@htmlstylesheet)
         | 
| 76 77 | 
             
                    s = htmlstylesheet(@htmlstylesheet_override) and head << s
         | 
| 77 | 
            -
                    @bare and | 
| 78 | 
            +
                    @bare and
         | 
| 79 | 
            +
                      head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>"
         | 
| 78 80 | 
             
                    docxml
         | 
| 79 81 | 
             
                  end
         | 
| 80 82 |  | 
| @@ -167,11 +169,7 @@ module IsoDoc | |
| 167 169 | 
             
                  end
         | 
| 168 170 |  | 
| 169 171 | 
             
                  def datauri(img)
         | 
| 170 | 
            -
                     | 
| 171 | 
            -
                    supertype = type == "xml" ? "application" : "image"
         | 
| 172 | 
            -
                    bin = IO.binread(image_localfile(img))
         | 
| 173 | 
            -
                    data = Base64.strict_encode64(bin)
         | 
| 174 | 
            -
                    img["src"] = "data:#{supertype}/#{type};base64,#{data}"
         | 
| 172 | 
            +
                    img["src"] = Metanorma::Utils::datauri(img["src"], @localdir)
         | 
| 175 173 | 
             
                  end
         | 
| 176 174 |  | 
| 177 175 | 
             
                  def image_suffix(img)
         | 
    
        data/lib/isodoc/metadata_date.rb
    CHANGED
    
    | @@ -6,7 +6,7 @@ module IsoDoc | |
| 6 6 | 
             
                               vote-ended}.freeze
         | 
| 7 7 |  | 
| 8 8 | 
             
                def months
         | 
| 9 | 
            -
             | 
| 9 | 
            +
                  {
         | 
| 10 10 | 
             
                    "01": @labels["month_january"],
         | 
| 11 11 | 
             
                    "02": @labels["month_february"],
         | 
| 12 12 | 
             
                    "03": @labels["month_march"],
         | 
| @@ -19,30 +19,32 @@ module IsoDoc | |
| 19 19 | 
             
                    "10": @labels["month_october"],
         | 
| 20 20 | 
             
                    "11": @labels["month_november"],
         | 
| 21 21 | 
             
                    "12": @labels["month_december"],
         | 
| 22 | 
            -
             | 
| 22 | 
            +
                  }
         | 
| 23 23 | 
             
                end
         | 
| 24 24 |  | 
| 25 25 | 
             
                def monthyr(isodate)
         | 
| 26 26 | 
             
                  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
         | 
| 27 27 | 
             
                  return isodate unless m && m[:yr] && m[:mo]
         | 
| 28 | 
            +
             | 
| 28 29 | 
             
                  l10n("#{months[m[:mo].to_sym]} #{m[:yr]}",
         | 
| 29 | 
            -
             | 
| 30 | 
            +
                       @lang, @script)
         | 
| 30 31 | 
             
                end
         | 
| 31 32 |  | 
| 32 33 | 
             
                def MMMddyyyy(isodate)
         | 
| 33 34 | 
             
                  return nil if isodate.nil?
         | 
| 35 | 
            +
             | 
| 34 36 | 
             
                  arr = isodate.split("-")
         | 
| 35 | 
            -
                   | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 37 | 
            +
                  if arr.size == 1 && (/^\d+$/.match isodate)
         | 
| 38 | 
            +
                    Date.new(*arr.map(&:to_i)).strftime("%Y")
         | 
| 39 | 
            +
                  elsif arr.size == 2
         | 
| 40 | 
            +
                    Date.new(*arr.map(&:to_i)).strftime("%B %Y")
         | 
| 41 | 
            +
                  else
         | 
| 42 | 
            +
                    Date.parse(isodate).strftime("%B %d, %Y")
         | 
| 43 | 
            +
                  end
         | 
| 42 44 | 
             
                end
         | 
| 43 45 |  | 
| 44 46 | 
             
                def bibdate(isoxml, _out)
         | 
| 45 | 
            -
                  isoxml.xpath(ns( | 
| 47 | 
            +
                  isoxml.xpath(ns("//bibdata/date")).each do |d|
         | 
| 46 48 | 
             
                    set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
         | 
| 47 49 | 
             
                  end
         | 
| 48 50 | 
             
                end
         | 
| @@ -10,7 +10,7 @@ module IsoDoc | |
| 10 10 | 
             
                    "</localized-strings>"
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 | 
            -
             | 
| 13 | 
            +
                def docid_prefixes(docxml)
         | 
| 14 14 | 
             
                  docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
         | 
| 15 15 | 
             
                    i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
         | 
| 16 16 | 
             
                  end
         | 
| @@ -97,7 +97,7 @@ module IsoDoc | |
| 97 97 |  | 
| 98 98 | 
             
                # https://stackoverflow.com/a/31822406
         | 
| 99 99 | 
             
                def blank?(elem)
         | 
| 100 | 
            -
                  elem.nil? || elem.respond_to?(:empty?) && elem.empty?
         | 
| 100 | 
            +
                  elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
         | 
| 101 101 | 
             
                end
         | 
| 102 102 |  | 
| 103 103 | 
             
                def trim_hash(hash)
         | 
| @@ -28,11 +28,7 @@ module IsoDoc | |
| 28 28 | 
             
                  ref = node.at(ns("./xref | ./eref | ./termref"))
         | 
| 29 29 | 
             
                  ref && opts[:ref] != "false" and r&.next = " "
         | 
| 30 30 | 
             
                  opts[:ital] == "true" and r&.name = "em"
         | 
| 31 | 
            -
                   | 
| 32 | 
            -
                    ref2 = ref.clone
         | 
| 33 | 
            -
                    r2 = r.clone
         | 
| 34 | 
            -
                    r.replace(ref2).children = r2
         | 
| 35 | 
            -
                  end
         | 
| 31 | 
            +
                  concept1_linkmention(ref, r, opts)
         | 
| 36 32 | 
             
                  concept1_ref(node, ref, opts)
         | 
| 37 33 | 
             
                  if opts[:ital] == "false"
         | 
| 38 34 | 
             
                    r = node.at(ns(".//renderterm"))
         | 
| @@ -41,6 +37,14 @@ module IsoDoc | |
| 41 37 | 
             
                  node.replace(node.children)
         | 
| 42 38 | 
             
                end
         | 
| 43 39 |  | 
| 40 | 
            +
                def concept1_linkmention(ref, renderterm, opts)
         | 
| 41 | 
            +
                  if opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
         | 
| 42 | 
            +
                    ref2 = ref.clone
         | 
| 43 | 
            +
                    r2 = renderterm.clone
         | 
| 44 | 
            +
                    renderterm.replace(ref2).children = r2
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 44 48 | 
             
                def concept1_ref(_node, ref, opts)
         | 
| 45 49 | 
             
                  ref.nil? and return
         | 
| 46 50 | 
             
                  return ref.remove if opts[:ref] == "false"
         | 
| @@ -78,39 +82,71 @@ module IsoDoc | |
| 78 82 | 
             
                end
         | 
| 79 83 |  | 
| 80 84 | 
             
                def designation(docxml)
         | 
| 81 | 
            -
                  docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
         | 
| 82 | 
            -
                    designation1(p)
         | 
| 83 | 
            -
                  end
         | 
| 84 85 | 
             
                  docxml.xpath(ns("//term")).each do |t|
         | 
| 85 86 | 
             
                    merge_second_preferred(t)
         | 
| 86 87 | 
             
                  end
         | 
| 88 | 
            +
                  docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
         | 
| 89 | 
            +
                    designation1(p)
         | 
| 90 | 
            +
                  end
         | 
| 87 91 | 
             
                end
         | 
| 88 92 |  | 
| 89 93 | 
             
                def merge_second_preferred(term)
         | 
| 90 94 | 
             
                  pref = nil
         | 
| 91 | 
            -
                  term.xpath(ns("./preferred")).each_with_index do |p, i|
         | 
| 95 | 
            +
                  term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i|
         | 
| 92 96 | 
             
                    if i.zero? then pref = p
         | 
| 93 | 
            -
                     | 
| 94 | 
            -
                      pref | 
| 97 | 
            +
                    elsif merge_preferred_eligible?(pref, p)
         | 
| 98 | 
            +
                      pref.at(ns("./expression/name")) <<
         | 
| 99 | 
            +
                        l10n("; #{p.at(ns('./expression/name')).children.to_xml}")
         | 
| 95 100 | 
             
                      p.remove
         | 
| 96 101 | 
             
                    end
         | 
| 97 102 | 
             
                  end
         | 
| 98 103 | 
             
                end
         | 
| 99 104 |  | 
| 105 | 
            +
                def merge_preferred_eligible?(first, second)
         | 
| 106 | 
            +
                  firstex = first.at(ns("./expression")) || {}
         | 
| 107 | 
            +
                  secondex = second.at(ns("./expression")) || {}
         | 
| 108 | 
            +
                  first["geographic-area"] == second["geographic-area"] &&
         | 
| 109 | 
            +
                    firstex["language"] == secondex["language"] &&
         | 
| 110 | 
            +
                    !first.at(ns("./pronunciation | ./grammar")) &&
         | 
| 111 | 
            +
                    !second.at(ns("./pronunciation | ./grammar"))
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
             | 
| 100 114 | 
             
                def designation1(desgn)
         | 
| 101 115 | 
             
                  s = desgn.at(ns("./termsource"))
         | 
| 102 116 | 
             
                  name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
         | 
| 103 117 | 
             
                                     "./graphical-symbol")) or return
         | 
| 104 118 |  | 
| 119 | 
            +
                  designation_annotate(desgn, name)
         | 
| 120 | 
            +
                  s and desgn.next = s
         | 
| 121 | 
            +
                end
         | 
| 122 | 
            +
             | 
| 123 | 
            +
                def designation_annotate(desgn, name)
         | 
| 124 | 
            +
                  designation_field(desgn, name)
         | 
| 125 | 
            +
                  designation_boldface(desgn)
         | 
| 105 126 | 
             
                  g = desgn.at(ns("./expression/grammar")) and
         | 
| 106 | 
            -
                    name << " #{designation_grammar(g).join(', ')}"
         | 
| 127 | 
            +
                    name << ", #{designation_grammar(g).join(', ')}"
         | 
| 128 | 
            +
                  designation_localization(desgn, name)
         | 
| 129 | 
            +
                  designation_pronunciation(desgn, name)
         | 
| 107 130 | 
             
                  desgn.children = name.children
         | 
| 108 | 
            -
             | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                def designation_boldface(desgn)
         | 
| 134 | 
            +
                  desgn.name == "preferred" or return
         | 
| 135 | 
            +
                  name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
         | 
| 136 | 
            +
                  name.children = "<strong>#{name.children}</strong>"
         | 
| 137 | 
            +
                end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                def designation_field(desgn, name)
         | 
| 140 | 
            +
                  f = desgn.xpath(ns("./field-of-application | ./usage-info"))
         | 
| 141 | 
            +
                    &.map { |u| u.children.to_xml }&.join(", ")
         | 
| 142 | 
            +
                  return nil if f&.empty?
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                  name << ", <#{f}>"
         | 
| 109 145 | 
             
                end
         | 
| 110 146 |  | 
| 111 147 | 
             
                def designation_grammar(grammar)
         | 
| 112 148 | 
             
                  ret = []
         | 
| 113 | 
            -
                  grammar.xpath(ns("./gender")).each do |x|
         | 
| 149 | 
            +
                  grammar.xpath(ns("./gender | ./number")).each do |x|
         | 
| 114 150 | 
             
                    ret << @i18n.grammar_abbrevs[x.text]
         | 
| 115 151 | 
             
                  end
         | 
| 116 152 | 
             
                  %w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
         | 
| @@ -121,20 +157,28 @@ module IsoDoc | |
| 121 157 | 
             
                  ret
         | 
| 122 158 | 
             
                end
         | 
| 123 159 |  | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 160 | 
            +
                def designation_localization(desgn, name)
         | 
| 161 | 
            +
                  loc = [desgn&.at(ns("./expression/@language"))&.text,
         | 
| 162 | 
            +
                         desgn&.at(ns("./expression/@script"))&.text,
         | 
| 163 | 
            +
                         desgn&.at(ns("./@geographic-area"))&.text].compact
         | 
| 164 | 
            +
                  return if loc.empty?
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                  name << ", #{loc.join(' ')}"
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                def designation_pronunciation(desgn, name)
         | 
| 170 | 
            +
                  f = desgn.at(ns("./expression/pronunciation")) or return
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                  name << ", /#{f.children.to_xml}/"
         | 
| 173 | 
            +
                end
         | 
| 130 174 |  | 
| 131 | 
            -
             | 
| 175 | 
            +
                def termexample(docxml)
         | 
| 132 176 | 
             
                  docxml.xpath(ns("//termexample")).each do |f|
         | 
| 133 177 | 
             
                    example1(f)
         | 
| 134 178 | 
             
                  end
         | 
| 135 179 | 
             
                end
         | 
| 136 180 |  | 
| 137 | 
            -
             | 
| 181 | 
            +
                def termnote(docxml)
         | 
| 138 182 | 
             
                  docxml.xpath(ns("//termnote")).each do |f|
         | 
| 139 183 | 
             
                    termnote1(f)
         | 
| 140 184 | 
             
                  end
         | 
| @@ -155,7 +199,7 @@ module IsoDoc | |
| 155 199 | 
             
                def termdefinition1(elem)
         | 
| 156 200 | 
             
                  unwrap_definition(elem)
         | 
| 157 201 | 
             
                  multidef(elem) if elem.xpath(ns("./definition")).size > 1
         | 
| 158 | 
            -
             | 
| 202 | 
            +
                end
         | 
| 159 203 |  | 
| 160 204 | 
             
                def multidef(elem)
         | 
| 161 205 | 
             
                  d = elem.at(ns("./definition"))
         | 
| @@ -167,13 +211,13 @@ module IsoDoc | |
| 167 211 | 
             
                  d.wrap("<definition></definition>")
         | 
| 168 212 | 
             
                end
         | 
| 169 213 |  | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
                      v = d&.at(ns(" | 
| 174 | 
            -
                       | 
| 175 | 
            -
                      d.children = nodes
         | 
| 176 | 
            -
                         end
         | 
| 214 | 
            +
                def unwrap_definition(elem)
         | 
| 215 | 
            +
                  elem.xpath(ns("./definition")).each do |d|
         | 
| 216 | 
            +
                    %w(verbal-definition non-verbal-representation).each do |e|
         | 
| 217 | 
            +
                      v = d&.at(ns("./#{e}"))
         | 
| 218 | 
            +
                      v&.replace(v.children)
         | 
| 177 219 | 
             
                    end
         | 
| 220 | 
            +
                  end
         | 
| 221 | 
            +
                end
         | 
| 178 222 | 
             
              end
         | 
| 179 223 | 
             
            end
         | 
    
        data/lib/isodoc/version.rb
    CHANGED
    
    
| @@ -54,11 +54,11 @@ module IsoDoc | |
| 54 54 | 
             
                  end
         | 
| 55 55 |  | 
| 56 56 | 
             
                  def para_class(_node)
         | 
| 57 | 
            -
                     | 
| 58 | 
            -
                     | 
| 59 | 
            -
                     | 
| 60 | 
            -
             | 
| 61 | 
            -
                     | 
| 57 | 
            +
                    return "Sourcecode" if @annotation
         | 
| 58 | 
            +
                    return "MsoCommentText" if @in_comment
         | 
| 59 | 
            +
                    return "Note" if @note
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    nil
         | 
| 62 62 | 
             
                  end
         | 
| 63 63 |  | 
| 64 64 | 
             
                  def para_parse(node, out)
         | 
| @@ -86,21 +86,31 @@ module IsoDoc | |
| 86 86 | 
             
                  end
         | 
| 87 87 |  | 
| 88 88 | 
             
                  def dl_parse(node, out)
         | 
| 89 | 
            +
                    return super unless node.ancestors("table, dl").empty?
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                    dl_parse_table(node, out)
         | 
| 92 | 
            +
                  end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                  def dl_parse_table(node, out)
         | 
| 89 95 | 
             
                    out.table **{ class: "dl" } do |v|
         | 
| 90 96 | 
             
                      node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
         | 
| 91 | 
            -
                        v | 
| 92 | 
            -
                          tr.td **{ valign: "top", align: "left" } do |term|
         | 
| 93 | 
            -
                            dt_parse(dt, term)
         | 
| 94 | 
            -
                          end
         | 
| 95 | 
            -
                          tr.td **{ valign: "top" } do |listitem|
         | 
| 96 | 
            -
                            dd.children.each { |n| parse(n, listitem) }
         | 
| 97 | 
            -
                          end
         | 
| 98 | 
            -
                        end
         | 
| 97 | 
            +
                        dl_parse_table1(v, dt, dd)
         | 
| 99 98 | 
             
                      end
         | 
| 100 99 | 
             
                      dl_parse_notes(node, v)
         | 
| 101 100 | 
             
                    end
         | 
| 102 101 | 
             
                  end
         | 
| 103 102 |  | 
| 103 | 
            +
                  def dl_parse_table1(table, dterm, ddefn)
         | 
| 104 | 
            +
                    table.tr do |tr|
         | 
| 105 | 
            +
                      tr.td **{ valign: "top", align: "left" } do |term|
         | 
| 106 | 
            +
                        dt_parse(dterm, term)
         | 
| 107 | 
            +
                      end
         | 
| 108 | 
            +
                      tr.td **{ valign: "top" } do |listitem|
         | 
| 109 | 
            +
                        ddefn.children.each { |n| parse(n, listitem) }
         | 
| 110 | 
            +
                      end
         | 
| 111 | 
            +
                    end
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
             | 
| 104 114 | 
             
                  def dl_parse_notes(node, out)
         | 
| 105 115 | 
             
                    return if node.elements.reject { |n| dt_dd? n }.empty?
         | 
| 106 116 |  | 
| @@ -120,8 +130,8 @@ module IsoDoc | |
| 120 130 | 
             
                    dl
         | 
| 121 131 | 
             
                  end
         | 
| 122 132 |  | 
| 133 | 
            +
                  # get rid of footnote link, it is in diagram
         | 
| 123 134 | 
             
                  def figure_aside_process(fig, aside, key)
         | 
| 124 | 
            -
                    # get rid of footnote link, it is in diagram
         | 
| 125 135 | 
             
                    fig&.at("./a[@class='TableFootnoteRef']")&.remove
         | 
| 126 136 | 
             
                    fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
         | 
| 127 137 | 
             
                    tr = key.add_child("<tr></tr>").first
         | 
    
        data/lib/isodoc/xref/xref_gen.rb
    CHANGED
    
    | @@ -7,6 +7,10 @@ module IsoDoc | |
| 7 7 | 
             
                                       recommendation permission figure table formula
         | 
| 8 8 | 
             
                                       admonition sourcecode).freeze
         | 
| 9 9 |  | 
| 10 | 
            +
                  def blank?(text)
         | 
| 11 | 
            +
                    text.nil? || text.empty?
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 10 14 | 
             
                  def amend_preprocess(xmldoc)
         | 
| 11 15 | 
             
                    xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
         | 
| 12 16 | 
             
                      autonum = amend_autonums(a)
         | 
| @@ -39,11 +43,9 @@ module IsoDoc | |
| 39 43 | 
             
                  end
         | 
| 40 44 |  | 
| 41 45 | 
             
                  def termnote_anchor_names(docxml)
         | 
| 42 | 
            -
                    docxml.xpath(ns("//term[ | 
| 46 | 
            +
                    docxml.xpath(ns("//term[termnote]")).each do |t|
         | 
| 43 47 | 
             
                      c = Counter.new
         | 
| 44 | 
            -
                      t.xpath(ns(" | 
| 45 | 
            -
                        next if n["id"].nil? || n["id"].empty?
         | 
| 46 | 
            -
             | 
| 48 | 
            +
                      t.xpath(ns("./termnote")).reject { |n| blank?(n["id"]) }.each do |n|
         | 
| 47 49 | 
             
                        c.increment(n)
         | 
| 48 50 | 
             
                        @anchors[n["id"]] =
         | 
| 49 51 | 
             
                          { label: termnote_label(c.print), type: "termnote", value: c.print,
         | 
| @@ -54,18 +56,18 @@ module IsoDoc | |
| 54 56 | 
             
                  end
         | 
| 55 57 |  | 
| 56 58 | 
             
                  def termexample_anchor_names(docxml)
         | 
| 57 | 
            -
                    docxml.xpath(ns("//term[ | 
| 58 | 
            -
                      examples = t.xpath(ns(" | 
| 59 | 
            +
                    docxml.xpath(ns("//term[termexample]")).each do |t|
         | 
| 60 | 
            +
                      examples = t.xpath(ns("./termexample"))
         | 
| 59 61 | 
             
                      c = Counter.new
         | 
| 60 | 
            -
                      examples.each do |n|
         | 
| 61 | 
            -
                        next if n["id"].nil? || n["id"].empty?
         | 
| 62 | 
            -
             | 
| 62 | 
            +
                      examples.reject { |n| blank?(n["id"]) }.each do |n|
         | 
| 63 63 | 
             
                        c.increment(n)
         | 
| 64 64 | 
             
                        idx = increment_label(examples, n, c, false)
         | 
| 65 65 | 
             
                        @anchors[n["id"]] =
         | 
| 66 | 
            -
                          { type: "termexample", label: idx, value: c.print,
         | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 66 | 
            +
                          # { type: "termexample", label: idx, value: c.print,
         | 
| 67 | 
            +
                          # xref: l10n("#{anchor(t['id'], :xref)}, "\
         | 
| 68 | 
            +
                          # "#{@labels['example_xref']} #{c.print}") }
         | 
| 69 | 
            +
                          anchor_struct(idx, n,
         | 
| 70 | 
            +
                                        @labels["example_xref"], "termexample", n["unnumbered"])
         | 
| 69 71 | 
             
                      end
         | 
| 70 72 | 
             
                    end
         | 
| 71 73 | 
             
                  end
         | 
| @@ -127,9 +129,7 @@ module IsoDoc | |
| 127 129 | 
             
                      notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
         | 
| 128 130 | 
             
                        s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
         | 
| 129 131 | 
             
                      c = Counter.new
         | 
| 130 | 
            -
                      notes.each do |n|
         | 
| 131 | 
            -
                        next if n["id"].nil? || n["id"].empty?
         | 
| 132 | 
            -
             | 
| 132 | 
            +
                      notes.reject { |n| blank?(n["id"]) }.each do |n|
         | 
| 133 133 | 
             
                        @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
         | 
| 134 134 | 
             
                                                          @labels["list"], "list", false)
         | 
| 135 135 | 
             
                        list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
         | 
| @@ -158,9 +158,7 @@ module IsoDoc | |
| 158 158 | 
             
                      notes = s.xpath(ns(".//dl")) - s.xpath(ns(".//clause//dl")) -
         | 
| 159 159 | 
             
                        s.xpath(ns(".//appendix//dl")) - s.xpath(ns(".//dl//dl"))
         | 
| 160 160 | 
             
                      c = Counter.new
         | 
| 161 | 
            -
                      notes.each do |n|
         | 
| 162 | 
            -
                        next if n["id"].nil? || n["id"].empty?
         | 
| 163 | 
            -
             | 
| 161 | 
            +
                      notes.reject { |n| blank?(n["id"]) }.each do |n|
         | 
| 164 162 | 
             
                        @anchors[n["id"]] =
         | 
| 165 163 | 
             
                          anchor_struct(increment_label(notes, n, c), n,
         | 
| 166 164 | 
             
                                        @labels["deflist"], "deflist", false)
         | 
| @@ -183,10 +181,8 @@ module IsoDoc | |
| 183 181 | 
             
                    end
         | 
| 184 182 | 
             
                  end
         | 
| 185 183 |  | 
| 186 | 
            -
                  def bookmark_anchor_names( | 
| 187 | 
            -
                     | 
| 188 | 
            -
                      next if n["id"].nil? || n["id"].empty?
         | 
| 189 | 
            -
             | 
| 184 | 
            +
                  def bookmark_anchor_names(xml)
         | 
| 185 | 
            +
                    xml.xpath(ns(".//bookmark")).reject { |n| blank?(n["id"]) }.each do |n|
         | 
| 190 186 | 
             
                      parent = nil
         | 
| 191 187 | 
             
                      n.ancestors.each do |a|
         | 
| 192 188 | 
             
                        next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
         | 
| @@ -34,8 +34,7 @@ module IsoDoc::XrefGen | |
| 34 34 |  | 
| 35 35 | 
             
                def sequential_table_names(clause)
         | 
| 36 36 | 
             
                  c = Counter.new
         | 
| 37 | 
            -
                  clause.xpath(ns(".//table")).each do |t|
         | 
| 38 | 
            -
                    next if t["id"].nil? || t["id"].empty?
         | 
| 37 | 
            +
                  clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 39 38 |  | 
| 40 39 | 
             
                    @anchors[t["id"]] = anchor_struct(
         | 
| 41 40 | 
             
                      c.increment(t).print, nil,
         | 
| @@ -46,8 +45,7 @@ module IsoDoc::XrefGen | |
| 46 45 |  | 
| 47 46 | 
             
                def sequential_formula_names(clause)
         | 
| 48 47 | 
             
                  c = Counter.new
         | 
| 49 | 
            -
                  clause.xpath(ns(".//formula")).each do |t|
         | 
| 50 | 
            -
                    next if t["id"].nil? || t["id"].empty?
         | 
| 48 | 
            +
                  clause.xpath(ns(".//formula")).reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 51 49 |  | 
| 52 50 | 
             
                    @anchors[t["id"]] = anchor_struct(
         | 
| 53 51 | 
             
                      c.increment(t).print, t,
         | 
| @@ -62,8 +60,8 @@ module IsoDoc::XrefGen | |
| 62 60 |  | 
| 63 61 | 
             
                def sequential_permission_names(clause, klass, label)
         | 
| 64 62 | 
             
                  c = Counter.new
         | 
| 65 | 
            -
                  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")) | 
| 66 | 
            -
                     | 
| 63 | 
            +
                  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
         | 
| 64 | 
            +
                    .reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 67 65 |  | 
| 68 66 | 
             
                    id = c.increment(t).print
         | 
| 69 67 | 
             
                    @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
         | 
| @@ -82,8 +80,7 @@ module IsoDoc::XrefGen | |
| 82 80 |  | 
| 83 81 | 
             
                def sequential_permission_names1(block, lbl, klass, label)
         | 
| 84 82 | 
             
                  c = Counter.new
         | 
| 85 | 
            -
                  block.xpath(ns("./#{klass}")).each do |t|
         | 
| 86 | 
            -
                    next if t["id"].nil? || t["id"].empty?
         | 
| 83 | 
            +
                  block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 87 84 |  | 
| 88 85 | 
             
                    id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
         | 
| 89 86 | 
             
                    @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
         | 
| @@ -118,8 +115,7 @@ module IsoDoc::XrefGen | |
| 118 115 |  | 
| 119 116 | 
             
                def hierarchical_table_names(clause, num)
         | 
| 120 117 | 
             
                  c = Counter.new
         | 
| 121 | 
            -
                  clause.xpath(ns(".//table")).each do |t|
         | 
| 122 | 
            -
                    next if t["id"].nil? || t["id"].empty?
         | 
| 118 | 
            +
                  clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 123 119 |  | 
| 124 120 | 
             
                    @anchors[t["id"]] =
         | 
| 125 121 | 
             
                      anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
         | 
| @@ -141,8 +137,7 @@ module IsoDoc::XrefGen | |
| 141 137 |  | 
| 142 138 | 
             
                def hierarchical_formula_names(clause, num)
         | 
| 143 139 | 
             
                  c = Counter.new
         | 
| 144 | 
            -
                  clause.xpath(ns(".//formula")).each do |t|
         | 
| 145 | 
            -
                    next if t["id"].nil? || t["id"].empty?
         | 
| 140 | 
            +
                  clause.xpath(ns(".//formula")).reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 146 141 |  | 
| 147 142 | 
             
                    @anchors[t["id"]] = anchor_struct(
         | 
| 148 143 | 
             
                      "#{num}#{hiersep}#{c.increment(t).print}", nil,
         | 
| @@ -154,8 +149,8 @@ module IsoDoc::XrefGen | |
| 154 149 |  | 
| 155 150 | 
             
                def hierarchical_permission_names(clause, num, klass, label)
         | 
| 156 151 | 
             
                  c = Counter.new
         | 
| 157 | 
            -
                  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")) | 
| 158 | 
            -
                     | 
| 152 | 
            +
                  clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
         | 
| 153 | 
            +
                    .reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 159 154 |  | 
| 160 155 | 
             
                    id = "#{num}#{hiersep}#{c.increment(t).print}"
         | 
| 161 156 | 
             
                    @anchors[t["id"]] =
         | 
| @@ -175,8 +170,7 @@ module IsoDoc::XrefGen | |
| 175 170 |  | 
| 176 171 | 
             
                def hierarchical_permission_names1(block, lbl, klass, label)
         | 
| 177 172 | 
             
                  c = Counter.new
         | 
| 178 | 
            -
                  block.xpath(ns("./#{klass}")).each do |t|
         | 
| 179 | 
            -
                    next if t["id"].nil? || t["id"].empty?
         | 
| 173 | 
            +
                  block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
         | 
| 180 174 |  | 
| 181 175 | 
             
                    id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
         | 
| 182 176 | 
             
                    @anchors[t["id"]] =
         |