isodoc 1.3.1 → 1.4.0
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-yaml/i18n-en.yaml +55 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +56 -0
- data/lib/isodoc/convert.rb +1 -1
- data/lib/isodoc/function/section.rb +1 -1
- data/lib/isodoc/html_function/mathvariant_to_plain.rb +82 -0
- data/lib/isodoc/html_function/postprocess.rb +29 -17
- data/lib/isodoc/metadata_contributor.rb +4 -3
- data/lib/isodoc/presentation_function/section.rb +3 -0
- data/lib/isodoc/presentation_xml_convert.rb +1 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref/xref_sect_gen.rb +1 -1
- data/spec/isodoc/blocks_spec.rb +1 -1
- data/spec/isodoc/metadata_spec.rb +3 -1
- data/spec/isodoc/postproc_spec.rb +166 -3
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bf37a37eb402d844a36b33e3911c67d3ebcbef7bf7f864dfc0e9f3a8aca7603c
         | 
| 4 | 
            +
              data.tar.gz: cc3645b92e85d43e2c6e49cfce67cc13d0f656cf1c16d67247cb7053eceba394
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 83bfcc73e86c73c9373bf9b42170ebc58c4ae50e4a0789cacddefa05c5b80fe1c59559e3abde2071e79aa3fd839d7844b3c0145ca89ed09b9d6d7e09b1e03de9
         | 
| 7 | 
            +
              data.tar.gz: 11fbb6a5a6a19eadae64d22dd032185eaed46a1dd007f188e26cc73153e75ceb16ec3c64c8613c8dc05e0263fafab98655287e23993c34ebcf815096dca50bda
         | 
| @@ -97,3 +97,58 @@ locality: { | |
| 97 97 | 
             
                                  note: Note,
         | 
| 98 98 | 
             
                                  formula: Formula
         | 
| 99 99 | 
             
                                }
         | 
| 100 | 
            +
            inflection:
         | 
| 101 | 
            +
              Clause:
         | 
| 102 | 
            +
                sg: Clause
         | 
| 103 | 
            +
                pl: Clauses
         | 
| 104 | 
            +
              Annex:
         | 
| 105 | 
            +
                sg: Annex
         | 
| 106 | 
            +
                pl: Annexes
         | 
| 107 | 
            +
              Appendix:
         | 
| 108 | 
            +
                sg: Appendix
         | 
| 109 | 
            +
                pl: Appendixes
         | 
| 110 | 
            +
              Note:
         | 
| 111 | 
            +
                sg: Note
         | 
| 112 | 
            +
                pl: Notes
         | 
| 113 | 
            +
              "Note % to entry":
         | 
| 114 | 
            +
                sg: Note % to entry
         | 
| 115 | 
            +
                pl: Notes % to entry
         | 
| 116 | 
            +
              List:
         | 
| 117 | 
            +
                sg: List
         | 
| 118 | 
            +
                pl: Lists
         | 
| 119 | 
            +
              Figure:
         | 
| 120 | 
            +
                sg: Figure
         | 
| 121 | 
            +
                pl: Figures
         | 
| 122 | 
            +
              Formula:
         | 
| 123 | 
            +
                sg: Formula
         | 
| 124 | 
            +
                pl: Formulas
         | 
| 125 | 
            +
              Table:
         | 
| 126 | 
            +
                sg: Table
         | 
| 127 | 
            +
                pl: Tables
         | 
| 128 | 
            +
              Requirement:
         | 
| 129 | 
            +
                sg: Requirement
         | 
| 130 | 
            +
                pl: Requirements
         | 
| 131 | 
            +
              Recommendation:
         | 
| 132 | 
            +
                sg: Recommendation
         | 
| 133 | 
            +
                pl: Recommendations
         | 
| 134 | 
            +
              Permission:
         | 
| 135 | 
            +
                sg: Permission
         | 
| 136 | 
            +
                pl: Permissions
         | 
| 137 | 
            +
              Example:
         | 
| 138 | 
            +
                sg: Example
         | 
| 139 | 
            +
                pl: Examples
         | 
| 140 | 
            +
              Part:
         | 
| 141 | 
            +
                sg: Part
         | 
| 142 | 
            +
                pl: Parts
         | 
| 143 | 
            +
              Section:
         | 
| 144 | 
            +
                sg: Section
         | 
| 145 | 
            +
                pl: Sections
         | 
| 146 | 
            +
              Paragraph:
         | 
| 147 | 
            +
                sg: Paragraph
         | 
| 148 | 
            +
                pl: Paragraphs
         | 
| 149 | 
            +
              Chapter:
         | 
| 150 | 
            +
                sg: Chapter
         | 
| 151 | 
            +
                pl: Chapters
         | 
| 152 | 
            +
              Page:
         | 
| 153 | 
            +
                sg: Page
         | 
| 154 | 
            +
                pl: Pages
         | 
| @@ -90,3 +90,59 @@ locality: { | |
| 90 90 | 
             
                                  note: Note,
         | 
| 91 91 | 
             
                                  formula: Formule
         | 
| 92 92 | 
             
                                }
         | 
| 93 | 
            +
            inflection:
         | 
| 94 | 
            +
              Clause:
         | 
| 95 | 
            +
                sg: Article
         | 
| 96 | 
            +
                pl: Articles
         | 
| 97 | 
            +
              Annex:
         | 
| 98 | 
            +
                sg: Annexe
         | 
| 99 | 
            +
                pl: Annexes
         | 
| 100 | 
            +
              Appendix:
         | 
| 101 | 
            +
                sg: Appendice
         | 
| 102 | 
            +
                pl: Appendices
         | 
| 103 | 
            +
              Note:
         | 
| 104 | 
            +
                sg: Note
         | 
| 105 | 
            +
                pl: Notes
         | 
| 106 | 
            +
              "Note % à l’article":
         | 
| 107 | 
            +
                sg: Note % à l’article
         | 
| 108 | 
            +
                pl: Notes % à l’article
         | 
| 109 | 
            +
              List:
         | 
| 110 | 
            +
                sg: Liste
         | 
| 111 | 
            +
                pl: Listes
         | 
| 112 | 
            +
              Figure:
         | 
| 113 | 
            +
                sg: Figure
         | 
| 114 | 
            +
                pl: Figures
         | 
| 115 | 
            +
              Formula:
         | 
| 116 | 
            +
                sg: Formule
         | 
| 117 | 
            +
                pl: Formules
         | 
| 118 | 
            +
              Table:
         | 
| 119 | 
            +
                sg: Tableau
         | 
| 120 | 
            +
                pl: Tableaux
         | 
| 121 | 
            +
              Requirement:
         | 
| 122 | 
            +
                sg: Exigence
         | 
| 123 | 
            +
                pl: Exigences
         | 
| 124 | 
            +
              Recommendation:
         | 
| 125 | 
            +
                sg: Recommandation
         | 
| 126 | 
            +
                pl: Recommandations
         | 
| 127 | 
            +
              Permission:
         | 
| 128 | 
            +
                sg: Autorisation
         | 
| 129 | 
            +
                pl: Autorisations
         | 
| 130 | 
            +
              Example:
         | 
| 131 | 
            +
                sg: Exemple
         | 
| 132 | 
            +
                pl: Exemples
         | 
| 133 | 
            +
              Part:
         | 
| 134 | 
            +
                sg: Partie
         | 
| 135 | 
            +
                pl: Parties
         | 
| 136 | 
            +
              Section:
         | 
| 137 | 
            +
                sg: Section
         | 
| 138 | 
            +
                pl: Sections
         | 
| 139 | 
            +
              Paragraph:
         | 
| 140 | 
            +
                sg: Alinéa
         | 
| 141 | 
            +
                pl: Alinéas
         | 
| 142 | 
            +
              Chapter:
         | 
| 143 | 
            +
                sg: Chapitre
         | 
| 144 | 
            +
                pl: Chapitres
         | 
| 145 | 
            +
              Page:
         | 
| 146 | 
            +
                sg: Page
         | 
| 147 | 
            +
                pl: Pages
         | 
| 148 | 
            +
             | 
    
        data/lib/isodoc/convert.rb
    CHANGED
    
    
| @@ -56,7 +56,7 @@ module IsoDoc::Function | |
| 56 56 | 
             
                end
         | 
| 57 57 |  | 
| 58 58 | 
             
                def clause(isoxml, out)
         | 
| 59 | 
            -
                  isoxml.xpath(ns(middle_clause)).each do |c|
         | 
| 59 | 
            +
                  isoxml.xpath(ns(middle_clause(isoxml))).each do |c|
         | 
| 60 60 | 
             
                    out.div **attr_code(clause_attrs(c)) do |s|
         | 
| 61 61 | 
             
                      clause_name(nil, c&.at(ns("./title")), s, nil)
         | 
| 62 62 | 
             
                      c.elements.reject { |c1| c1.name == "title" }.each do |c1|
         | 
| @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            module IsoDoc
         | 
| 2 | 
            +
              module HtmlFunction
         | 
| 3 | 
            +
                # Class for recursively converting mathvariant text into plain text symbols
         | 
| 4 | 
            +
                class MathvariantToPlain
         | 
| 5 | 
            +
                  MATHML = { "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
         | 
| 6 | 
            +
                  MATHVARIANT_SPECIAL_CASE_MAPPINGS_1 = %w[bold italic sans-serif]
         | 
| 7 | 
            +
                    .permutation
         | 
| 8 | 
            +
                    .each_with_object(:sansbolditalic)
         | 
| 9 | 
            +
                    .map { |n, y| [n, y] }
         | 
| 10 | 
            +
                    .to_h
         | 
| 11 | 
            +
                    .freeze
         | 
| 12 | 
            +
                  MATHVARIANT_SPECIAL_CASE_MAPPINGS_2 = {
         | 
| 13 | 
            +
                    %w[bold fraktur] => :frakturbold,
         | 
| 14 | 
            +
                    %w[bold script] => :scriptbold,
         | 
| 15 | 
            +
                    %w[sans-serif bold] => :sansbold,
         | 
| 16 | 
            +
                    %w[sans-serif italic] => :sansitalic,
         | 
| 17 | 
            +
                    %w[sans-serif bold-italic] => :sansbolditalic,
         | 
| 18 | 
            +
                    %w[bold-sans-serif italic] => :sansbolditalic,
         | 
| 19 | 
            +
                    %w[sans-serif-italic bold] => :sansbolditalic,
         | 
| 20 | 
            +
                  }.freeze
         | 
| 21 | 
            +
                  MATHVARIANT_TO_PLANE_MAPPINGS = {
         | 
| 22 | 
            +
                    %w[double-struck] => :doublestruck,
         | 
| 23 | 
            +
                    %w[bold-fraktur] => :frakturbold,
         | 
| 24 | 
            +
                    %w[script] => :script,
         | 
| 25 | 
            +
                    %w[bold-script] => :scriptbold,
         | 
| 26 | 
            +
                    %w[fraktur] => :fraktur,
         | 
| 27 | 
            +
                    %w[sans-serif] => :sans,
         | 
| 28 | 
            +
                    %w[bold-sans-serif] => :sansbold,
         | 
| 29 | 
            +
                    %w[sans-serif-italic] => :sansitalic,
         | 
| 30 | 
            +
                    %w[sans-serif-bold-italic] => :sansbolditalic,
         | 
| 31 | 
            +
                    %w[monospace] => :monospace,
         | 
| 32 | 
            +
                  }.freeze
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  attr_reader :docxml
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  # @param [Nokogiri::Document] docxml
         | 
| 37 | 
            +
                  def initialize(docxml)
         | 
| 38 | 
            +
                    @docxml = docxml
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def convert
         | 
| 42 | 
            +
                    docxml.xpath("//m:math", MATHML).each do |elem|
         | 
| 43 | 
            +
                      next if nothing_to_style(elem)
         | 
| 44 | 
            +
                      mathml1(elem)
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
                    docxml
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  private
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  def nothing_to_style(elem)
         | 
| 52 | 
            +
                    !elem.at("./*[@mathvariant][not(@mathvariant = 'normal')][not(@mathvariant = 'italic')]")
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  def mathml1(base_elem)
         | 
| 56 | 
            +
                    MATHVARIANT_SPECIAL_CASE_MAPPINGS_1
         | 
| 57 | 
            +
                      .merge(MATHVARIANT_SPECIAL_CASE_MAPPINGS_2)
         | 
| 58 | 
            +
                      .merge(MATHVARIANT_TO_PLANE_MAPPINGS)
         | 
| 59 | 
            +
                      .each_pair do |mathvariant_list, plain_font|
         | 
| 60 | 
            +
                        base_elem.xpath(mathvariant_xpath(mathvariant_list)).each do |elem|
         | 
| 61 | 
            +
                          toPlane(elem, plain_font)
         | 
| 62 | 
            +
                        end
         | 
| 63 | 
            +
                      end
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  def mathvariant_xpath(list)
         | 
| 67 | 
            +
                    list
         | 
| 68 | 
            +
                      .map { |variant| "//*[@mathvariant = '#{variant}']" }
         | 
| 69 | 
            +
                      .join
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  def toPlane(elem, font)
         | 
| 73 | 
            +
                    elem.traverse do |n|
         | 
| 74 | 
            +
                      next unless n.text?
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                      n.replace(Plane1Converter.conv(HTMLEntities.new.decode(n.text), font))
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
                    elem
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
            end
         | 
| @@ -1,35 +1,47 @@ | |
| 1 | 
            +
            require "isodoc/html_function/mathvariant_to_plain"
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module IsoDoc::HtmlFunction
         | 
| 2 4 | 
             
              module Html
         | 
| 3 | 
            -
                def postprocess(result, filename,  | 
| 5 | 
            +
                def postprocess(result, filename, _dir)
         | 
| 4 6 | 
             
                  result = from_xhtml(cleanup(to_xhtml(textcleanup(result))))
         | 
| 5 7 | 
             
                  toHTML(result, filename)
         | 
| 6 8 | 
             
                  @files_to_delete.each { |f| FileUtils.rm_rf f }
         | 
| 7 9 | 
             
                end
         | 
| 8 10 |  | 
| 9 11 | 
             
                def script_cdata(result)
         | 
| 10 | 
            -
                  result.gsub(%r{<script([^>]*)>\s*<!\[CDATA\[}m, "<script\\1>") | 
| 11 | 
            -
                    gsub(%r{\]\]>\s*</script>}, "</script>") | 
| 12 | 
            -
                    gsub(%r{<!\[CDATA\[\s*<script([^>]*)>}m, "<script\\1>") | 
| 13 | 
            -
                    gsub(%r{</script>\s*\]\]>}, "</script>")
         | 
| 12 | 
            +
                  result.gsub(%r{<script([^>]*)>\s*<!\[CDATA\[}m, "<script\\1>")
         | 
| 13 | 
            +
                    .gsub(%r{\]\]>\s*</script>}, "</script>")
         | 
| 14 | 
            +
                    .gsub(%r{<!\[CDATA\[\s*<script([^>]*)>}m, "<script\\1>")
         | 
| 15 | 
            +
                    .gsub(%r{</script>\s*\]\]>}, "</script>")
         | 
| 14 16 | 
             
                end
         | 
| 15 17 |  | 
| 16 18 | 
             
                def toHTML(result, filename)
         | 
| 17 | 
            -
                  result =  | 
| 18 | 
            -
                  #result = populate_template(result, :html)
         | 
| 19 | 
            +
                  result = from_xhtml(html_cleanup(to_xhtml(result)))
         | 
| 20 | 
            +
                  # result = populate_template(result, :html)
         | 
| 19 21 | 
             
                  result = from_xhtml(move_images(to_xhtml(result)))
         | 
| 20 22 | 
             
                  result = html5(script_cdata(inject_script(result)))
         | 
| 21 23 | 
             
                  File.open(filename, "w:UTF-8") { |f| f.write(result) }
         | 
| 22 24 | 
             
                end
         | 
| 23 25 |  | 
| 24 26 | 
             
                def html5(doc)
         | 
| 25 | 
            -
                  doc.sub(%r{<!DOCTYPE html [^>]+>}, "<!DOCTYPE html>") | 
| 26 | 
            -
                    sub(%r{<\?xml[^>]+>}, "")
         | 
| 27 | 
            +
                  doc.sub(%r{<!DOCTYPE html [^>]+>}, "<!DOCTYPE html>")
         | 
| 28 | 
            +
                    .sub(%r{<\?xml[^>]+>}, "")
         | 
| 27 29 | 
             
                end
         | 
| 28 30 |  | 
| 29 31 | 
             
                def html_cleanup(x)
         | 
| 30 | 
            -
                   | 
| 31 | 
            -
                     | 
| 32 | 
            -
             | 
| 32 | 
            +
                  mathml(
         | 
| 33 | 
            +
                    footnote_format(
         | 
| 34 | 
            +
                      footnote_backlinks(
         | 
| 35 | 
            +
                        html_toc(
         | 
| 36 | 
            +
                          term_header(html_footnote_filter(html_preface(htmlstyle(x))))
         | 
| 37 | 
            +
                        )
         | 
| 38 | 
            +
                      )
         | 
| 39 | 
            +
                    )
         | 
| 40 | 
            +
                  )
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def mathml(docxml)
         | 
| 44 | 
            +
                  IsoDoc::HtmlFunction::MathvariantToPlain.new(docxml).convert
         | 
| 33 45 | 
             
                end
         | 
| 34 46 |  | 
| 35 47 | 
             
                def htmlstylesheet
         | 
| @@ -76,14 +88,14 @@ module IsoDoc::HtmlFunction | |
| 76 88 | 
             
                def html_cover(docxml)
         | 
| 77 89 | 
             
                  doc = to_xhtml_fragment(File.read(@htmlcoverpage, encoding: "UTF-8"))
         | 
| 78 90 | 
             
                  d = docxml.at('//div[@class="title-section"]')
         | 
| 79 | 
            -
                  #d.children.first.add_previous_sibling doc.to_xml(encoding: "US-ASCII")
         | 
| 91 | 
            +
                  # d.children.first.add_previous_sibling doc.to_xml(encoding: "US-ASCII")
         | 
| 80 92 | 
             
                  d.children.first.add_previous_sibling populate_template(doc.to_xml(encoding: "US-ASCII"), :html)
         | 
| 81 93 | 
             
                end
         | 
| 82 94 |  | 
| 83 95 | 
             
                def html_intro(docxml)
         | 
| 84 96 | 
             
                  doc = to_xhtml_fragment(File.read(@htmlintropage, encoding: "UTF-8"))
         | 
| 85 97 | 
             
                  d = docxml.at('//div[@class="prefatory-section"]')
         | 
| 86 | 
            -
                  #d.children.first.add_previous_sibling doc.to_xml(encoding: "US-ASCII")
         | 
| 98 | 
            +
                  # d.children.first.add_previous_sibling doc.to_xml(encoding: "US-ASCII")
         | 
| 87 99 | 
             
                  d.children.first.add_previous_sibling populate_template(doc.to_xml(encoding: "US-ASCII"), :html)
         | 
| 88 100 | 
             
                end
         | 
| 89 101 |  | 
| @@ -93,19 +105,19 @@ module IsoDoc::HtmlFunction | |
| 93 105 | 
             
                end
         | 
| 94 106 |  | 
| 95 107 | 
             
                def toclevel_classes
         | 
| 96 | 
            -
                  (1..@htmlToClevels). | 
| 108 | 
            +
                  (1..@htmlToClevels).reduce([]) { |m, i| m << "h#{i}" }
         | 
| 97 109 | 
             
                end
         | 
| 98 110 |  | 
| 99 111 | 
             
                def toclevel
         | 
| 100 112 | 
             
                  ret = toclevel_classes.map { |l| "#{l}:not(:empty):not(.TermNum):not(.noTOC)" }
         | 
| 101 113 | 
             
                  <<~HEAD.freeze
         | 
| 102 | 
            -
             | 
| 114 | 
            +
                    function toclevel() { return "#{ret.join(',')}";}
         | 
| 103 115 | 
             
                  HEAD
         | 
| 104 116 | 
             
                end
         | 
| 105 117 |  | 
| 106 118 | 
             
                # needs to be same output as toclevel
         | 
| 107 119 | 
             
                def html_toc(docxml)
         | 
| 108 | 
            -
                  idx = docxml.at("//div[@id = 'toc']") or return docxml
         | 
| 120 | 
            +
                  (idx = docxml.at("//div[@id = 'toc']")) or (return docxml)
         | 
| 109 121 | 
             
                  toc = "<ul>"
         | 
| 110 122 | 
             
                  path = toclevel_classes.map do |l|
         | 
| 111 123 | 
             
                    "//main//#{l}[not(@class = 'TermNum')][not(@class = 'noTOC')][text()]"
         | 
| @@ -17,9 +17,10 @@ module IsoDoc | |
| 17 17 | 
             
                def extract_person_affiliations(authors)
         | 
| 18 18 | 
             
                  authors.reduce([]) do |m, a|
         | 
| 19 19 | 
             
                    name = a&.at(ns('./affiliation/organization/name'))&.text
         | 
| 20 | 
            -
                     | 
| 21 | 
            -
             | 
| 22 | 
            -
                     | 
| 20 | 
            +
                    subdivs = a&.xpath(ns('./affiliation/organization/subdivision'))&.map(&:text)&.join(", ")
         | 
| 21 | 
            +
                    name and subdivs and !subdivs.empty? and name = l10n("#{name}, #{subdivs}", @lang, @script)
         | 
| 22 | 
            +
                    location = a&.at(ns('./affiliation/organization/address/formattedAddress'))&.text
         | 
| 23 | 
            +
                    m << (!name.nil? && !location.nil? ? l10n("#{name}, #{location}", @lang, @script) :
         | 
| 23 24 | 
             
                      (name || location || ''))
         | 
| 24 25 | 
             
                    m
         | 
| 25 26 | 
             
                  end
         | 
    
        data/lib/isodoc/version.rb
    CHANGED
    
    
| @@ -68,7 +68,7 @@ module IsoDoc::XrefGen | |
| 68 68 | 
             
                end
         | 
| 69 69 |  | 
| 70 70 | 
             
                def clause_names(docxml, sect_num)
         | 
| 71 | 
            -
                  docxml.xpath(ns(@klass.middle_clause)).each_with_index do |c, i|
         | 
| 71 | 
            +
                  docxml.xpath(ns(@klass.middle_clause(docxml))).each_with_index do |c, i|
         | 
| 72 72 | 
             
                    section_names(c, (i + sect_num), 1)
         | 
| 73 73 | 
             
                  end
         | 
| 74 74 | 
             
                end
         | 
    
        data/spec/isodoc/blocks_spec.rb
    CHANGED
    
    
| @@ -60,6 +60,8 @@ RSpec.describe IsoDoc do | |
| 60 60 | 
             
                  </name>
         | 
| 61 61 | 
             
                  <affiliation>
         | 
| 62 62 | 
             
                  <organization><name>Slate Inc.</name>
         | 
| 63 | 
            +
                  <subdivision>Hermeneutics Unit</subdivision>
         | 
| 64 | 
            +
                  <subdivision>Exegesis Subunit</subdivision>
         | 
| 63 65 | 
             
                  <address>
         | 
| 64 66 | 
             
                  <formattedAddress>Bedrock</formattedAddress>
         | 
| 65 67 | 
             
                  </address>
         | 
| @@ -106,7 +108,7 @@ INPUT | |
| 106 108 | 
             
            :activateddate=>"2013",
         | 
| 107 109 | 
             
            :agency=>"ISO",
         | 
| 108 110 | 
             
            :authors=>["Barney Rubble", "Fred Flintstone"],
         | 
| 109 | 
            -
            :authors_affiliations=>{"Slate Inc., Bedrock"=>["Barney Rubble"], ""=>["Fred Flintstone"]},
         | 
| 111 | 
            +
            :authors_affiliations=>{"Slate Inc., Hermeneutics Unit, Exegesis Subunit, Bedrock"=>["Barney Rubble"], ""=>["Fred Flintstone"]},
         | 
| 110 112 | 
             
            :circulateddate=>"2015",
         | 
| 111 113 | 
             
            :confirmeddate=>"2017",
         | 
| 112 114 | 
             
            :copieddate=>"2016",
         | 
| @@ -617,6 +617,169 @@ TOCLEVEL | |
| 617 617 |  | 
| 618 618 | 
             
              end
         | 
| 619 619 |  | 
| 620 | 
            +
              describe "mathvariant to plain" do
         | 
| 621 | 
            +
                context "when `mathvariant` attr equal to `script`" do
         | 
| 622 | 
            +
                  it "converts mathvariant text chars into associated plain chars" do
         | 
| 623 | 
            +
                    FileUtils.rm_f "test.html"
         | 
| 624 | 
            +
                    FileUtils.rm_rf "test_htmlimages"
         | 
| 625 | 
            +
                    input = <<~INPUT
         | 
| 626 | 
            +
                      <?xml version="1.0" encoding="UTF-8"?>
         | 
| 627 | 
            +
                      <iso-standard xmlns="https://www.metanorma.org/ns/iso" type="semantic" version="1.5.14">
         | 
| 628 | 
            +
                        <sections>
         | 
| 629 | 
            +
                          <clause id="_clause" inline-header="false" obligation="normative">
         | 
| 630 | 
            +
                            <title>Clause</title>
         | 
| 631 | 
            +
                            <p id="_20514f5a-9f86-454e-b6ce-927f65ba6441">
         | 
| 632 | 
            +
                              <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML">
         | 
| 633 | 
            +
                                  <mi>x</mi>
         | 
| 634 | 
            +
                                  <mo>=</mo>
         | 
| 635 | 
            +
                                  <mstyle mathvariant="script">
         | 
| 636 | 
            +
                                    <mi>l</mi>
         | 
| 637 | 
            +
                                  </mstyle>
         | 
| 638 | 
            +
                                  <mo>+</mo>
         | 
| 639 | 
            +
                                  <mn>1</mn>
         | 
| 640 | 
            +
                                </math></stem>
         | 
| 641 | 
            +
                            </p>
         | 
| 642 | 
            +
                          </clause>
         | 
| 643 | 
            +
                        </sections>
         | 
| 644 | 
            +
                      </iso-standard>
         | 
| 645 | 
            +
                    INPUT
         | 
| 646 | 
            +
                    output = <<~OUTPUT
         | 
| 647 | 
            +
                      <main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
         | 
| 648 | 
            +
                        <p class="zzSTDTitle1"></p>
         | 
| 649 | 
            +
                        <div id="_clause">
         | 
| 650 | 
            +
                          <h1>Clause</h1>
         | 
| 651 | 
            +
                          <p id="_20514f5a-9f86-454e-b6ce-927f65ba6441">
         | 
| 652 | 
            +
                          <span class="stem"><math xmlns="http://www.w3.org/1998/Math/MathML">
         | 
| 653 | 
            +
                              <mi>x</mi>
         | 
| 654 | 
            +
                              <mo>=</mo>
         | 
| 655 | 
            +
                              <mstyle mathvariant="script">
         | 
| 656 | 
            +
                                <mi>𝓁</mi>
         | 
| 657 | 
            +
                              </mstyle>
         | 
| 658 | 
            +
                              <mo>+</mo>
         | 
| 659 | 
            +
                              <mn>1</mn>
         | 
| 660 | 
            +
                            </math></span>
         | 
| 661 | 
            +
                        </p>
         | 
| 662 | 
            +
                        </div>
         | 
| 663 | 
            +
                      </main>
         | 
| 664 | 
            +
                    OUTPUT
         | 
| 665 | 
            +
                    IsoDoc::HtmlConvert.new({}).convert("test", input, false)
         | 
| 666 | 
            +
                    html = File.read("test.html")
         | 
| 667 | 
            +
                            .sub(/^.*<main class="main-section">/m, '<main class="main-section">')
         | 
| 668 | 
            +
                            .sub(%r{</main>.*$}m, "</main>")
         | 
| 669 | 
            +
                    expect(html).to(be_equivalent_to(output))
         | 
| 670 | 
            +
                  end
         | 
| 671 | 
            +
                end
         | 
| 672 | 
            +
             | 
| 673 | 
            +
                context "when complex `mathvariant` combinations" do
         | 
| 674 | 
            +
                  it "converts mathvariant text chars into associated plain chars" do
         | 
| 675 | 
            +
                    FileUtils.rm_f "test.html"
         | 
| 676 | 
            +
                    FileUtils.rm_rf "test_htmlimages"
         | 
| 677 | 
            +
                    input = <<~INPUT
         | 
| 678 | 
            +
                      <?xml version="1.0" encoding="UTF-8"?>
         | 
| 679 | 
            +
                      <iso-standard xmlns="https://www.metanorma.org/ns/iso" type="semantic" version="1.5.14">
         | 
| 680 | 
            +
                        <sections>
         | 
| 681 | 
            +
                          <clause id="_clause" inline-header="false" obligation="normative">
         | 
| 682 | 
            +
                            <title>Clause</title>
         | 
| 683 | 
            +
                            <p id="_20514f5a-9f86-454e-b6ce-927f65ba6441">
         | 
| 684 | 
            +
                              <stem type="MathML">
         | 
| 685 | 
            +
                                <math xmlns="http://www.w3.org/1998/Math/MathML">
         | 
| 686 | 
            +
                                  <mstyle mathvariant="sans-serif">
         | 
| 687 | 
            +
                                    <mfrac>
         | 
| 688 | 
            +
                                      <mrow>
         | 
| 689 | 
            +
                                        <mrow>
         | 
| 690 | 
            +
                                          <mi>n</mi>
         | 
| 691 | 
            +
                                          <mfenced open="(" close=")">
         | 
| 692 | 
            +
                                            <mrow>
         | 
| 693 | 
            +
                                              <mstyle mathvariant="bold">
         | 
| 694 | 
            +
                                                <mrow>
         | 
| 695 | 
            +
                                                  <mi>n</mi>
         | 
| 696 | 
            +
                                                  <mo>+</mo>
         | 
| 697 | 
            +
                                                  <mn>1</mn>
         | 
| 698 | 
            +
                                                  <mo>+</mo>
         | 
| 699 | 
            +
                                                  <mstyle mathvariant="italic">
         | 
| 700 | 
            +
                                                    <mi>x</mi>
         | 
| 701 | 
            +
                                                  </mstyle>
         | 
| 702 | 
            +
                                                </mrow>
         | 
| 703 | 
            +
                                              </mstyle>
         | 
| 704 | 
            +
                                            </mrow>
         | 
| 705 | 
            +
                                          </mfenced>
         | 
| 706 | 
            +
                                        </mrow>
         | 
| 707 | 
            +
                                      </mrow>
         | 
| 708 | 
            +
                                      <mrow>
         | 
| 709 | 
            +
                                        <mstyle mathvariant="bold">
         | 
| 710 | 
            +
                                          <mrow>
         | 
| 711 | 
            +
                                            <mi>y</mi>
         | 
| 712 | 
            +
                                            <mo>+</mo>
         | 
| 713 | 
            +
                                            <mstyle mathvariant="fraktur">
         | 
| 714 | 
            +
                                              <mi>z</mi>
         | 
| 715 | 
            +
                                            </mstyle>
         | 
| 716 | 
            +
                                          </mrow>
         | 
| 717 | 
            +
                                        </mstyle>
         | 
| 718 | 
            +
                                      </mrow>
         | 
| 719 | 
            +
                                    </mfrac>
         | 
| 720 | 
            +
                                  </mstyle>
         | 
| 721 | 
            +
                                </math>
         | 
| 722 | 
            +
                              </stem>
         | 
| 723 | 
            +
                            </p>
         | 
| 724 | 
            +
                          </clause>
         | 
| 725 | 
            +
                        </sections>
         | 
| 726 | 
            +
                      </iso-standard>
         | 
| 727 | 
            +
                    INPUT
         | 
| 728 | 
            +
                    output = <<~OUTPUT
         | 
| 729 | 
            +
                      <main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
         | 
| 730 | 
            +
                        <p class="zzSTDTitle1"></p>
         | 
| 731 | 
            +
                        <div id="_clause">
         | 
| 732 | 
            +
                          <h1>Clause</h1>
         | 
| 733 | 
            +
                          <p id="_20514f5a-9f86-454e-b6ce-927f65ba6441">
         | 
| 734 | 
            +
                          <span class="stem"><math xmlns="http://www.w3.org/1998/Math/MathML">
         | 
| 735 | 
            +
                              <mstyle mathvariant="sans-serif">
         | 
| 736 | 
            +
                                <mfrac>
         | 
| 737 | 
            +
                                  <mrow>
         | 
| 738 | 
            +
                                    <mrow>
         | 
| 739 | 
            +
                                      <mi>𝗇</mi>
         | 
| 740 | 
            +
                                      <mfenced open="(" close=")">
         | 
| 741 | 
            +
                                        <mrow>
         | 
| 742 | 
            +
                                          <mstyle mathvariant="bold">
         | 
| 743 | 
            +
                                            <mrow>
         | 
| 744 | 
            +
                                              <mi>𝗻</mi>
         | 
| 745 | 
            +
                                              <mo>+</mo>
         | 
| 746 | 
            +
                                              <mn>𝟭</mn>
         | 
| 747 | 
            +
                                              <mo>+</mo>
         | 
| 748 | 
            +
                                              <mstyle mathvariant="italic">
         | 
| 749 | 
            +
                                                <mi>𝙭</mi>
         | 
| 750 | 
            +
                                              </mstyle>
         | 
| 751 | 
            +
                                            </mrow>
         | 
| 752 | 
            +
                                          </mstyle>
         | 
| 753 | 
            +
                                        </mrow>
         | 
| 754 | 
            +
                                      </mfenced>
         | 
| 755 | 
            +
                                    </mrow>
         | 
| 756 | 
            +
                                  </mrow>
         | 
| 757 | 
            +
                                  <mrow>
         | 
| 758 | 
            +
                                    <mstyle mathvariant="bold">
         | 
| 759 | 
            +
                                      <mrow>
         | 
| 760 | 
            +
                                        <mi>𝘆</mi>
         | 
| 761 | 
            +
                                        <mo>+</mo>
         | 
| 762 | 
            +
                                        <mstyle mathvariant="fraktur">
         | 
| 763 | 
            +
                                          <mi>𝖟</mi>
         | 
| 764 | 
            +
                                        </mstyle>
         | 
| 765 | 
            +
                                      </mrow>
         | 
| 766 | 
            +
                                    </mstyle>
         | 
| 767 | 
            +
                                  </mrow>
         | 
| 768 | 
            +
                                </mfrac>
         | 
| 769 | 
            +
                              </mstyle>
         | 
| 770 | 
            +
                            </math></span>
         | 
| 771 | 
            +
                        </p>
         | 
| 772 | 
            +
                        </div>
         | 
| 773 | 
            +
                      </main>
         | 
| 774 | 
            +
                    OUTPUT
         | 
| 775 | 
            +
                    IsoDoc::HtmlConvert.new({}).convert("test", input, false)
         | 
| 776 | 
            +
                    html = File.read("test.html")
         | 
| 777 | 
            +
                            .sub(/^.*<main class="main-section">/m, '<main class="main-section">')
         | 
| 778 | 
            +
                            .sub(%r{</main>.*$}m, "</main>")
         | 
| 779 | 
            +
                    expect(html).to(be_equivalent_to(output))
         | 
| 780 | 
            +
                  end
         | 
| 781 | 
            +
                end
         | 
| 782 | 
            +
              end
         | 
| 620 783 |  | 
| 621 784 | 
             
              it "moves images in HTML with no file suffix" do
         | 
| 622 785 | 
             
                FileUtils.rm_f "test.html"
         | 
| @@ -1047,7 +1210,7 @@ TOCLEVEL | |
| 1047 1210 | 
             
                OUTPUT
         | 
| 1048 1211 | 
             
              end
         | 
| 1049 1212 |  | 
| 1050 | 
            -
              it "deals with image captions (Word)" do | 
| 1213 | 
            +
              it "deals with image captions (Word)" do
         | 
| 1051 1214 | 
             
            FileUtils.rm_f "test.doc"
         | 
| 1052 1215 | 
             
                FileUtils.rm_f "test.html"
         | 
| 1053 1216 | 
             
                IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss"}).convert("test", <<~"INPUT", false)
         | 
| @@ -1366,7 +1529,7 @@ expect(xmlpp(html.sub(/^.*<body /m, "<body ").sub(%r{</body>.*$}m, "</body>"))). | |
| 1366 1529 | 
             
                       <div class='Section3' id=''>
         | 
| 1367 1530 | 
             
                         <h1 class='IntroTitle'>Preface 1</h1>
         | 
| 1368 1531 | 
             
                         <p align='center' style='text-align:center;' class='MsoNormal'>
         | 
| 1369 | 
            -
                           This is a | 
| 1532 | 
            +
                           This is a
         | 
| 1370 1533 | 
             
                           <p class='MsoNormal'>
         | 
| 1371 1534 | 
             
                             <br clear='all' class='section'/>
         | 
| 1372 1535 | 
             
                           </p>
         | 
| @@ -1412,7 +1575,7 @@ expect(xmlpp(html.sub(/^.*<body /m, "<body ").sub(%r{</body>.*$}m, "</body>"))). | |
| 1412 1575 | 
             
                           <p class='Note'>
         | 
| 1413 1576 | 
             
                             <span class='note_label'/>
         | 
| 1414 1577 | 
             
                             <span style='mso-tab-count:1'>  </span>
         | 
| 1415 | 
            -
                             For further information on the Foreword, see | 
| 1578 | 
            +
                             For further information on the Foreword, see
         | 
| 1416 1579 | 
             
                             <b>ISO/IEC Directives, Part 2, 2016, Clause 12.</b>
         | 
| 1417 1580 | 
             
                           </p>
         | 
| 1418 1581 | 
             
                           <p class='Note'>
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: isodoc
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ribose Inc.
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-12- | 
| 11 | 
            +
            date: 2020-12-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: asciimath
         | 
| @@ -374,6 +374,7 @@ files: | |
| 374 374 | 
             
            - lib/isodoc/html_function/comments.rb
         | 
| 375 375 | 
             
            - lib/isodoc/html_function/footnotes.rb
         | 
| 376 376 | 
             
            - lib/isodoc/html_function/html.rb
         | 
| 377 | 
            +
            - lib/isodoc/html_function/mathvariant_to_plain.rb
         | 
| 377 378 | 
             
            - lib/isodoc/html_function/postprocess.rb
         | 
| 378 379 | 
             
            - lib/isodoc/i18n.rb
         | 
| 379 380 | 
             
            - lib/isodoc/metadata.rb
         |