isodoc 1.0.26 → 1.1.1

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +12 -8
  3. data/.github/workflows/ubuntu.yml +26 -16
  4. data/.github/workflows/windows.yml +12 -8
  5. data/isodoc.gemspec +2 -2
  6. data/lib/isodoc.rb +2 -0
  7. data/lib/isodoc/common.rb +0 -4
  8. data/lib/isodoc/convert.rb +18 -8
  9. data/lib/isodoc/function/blocks.rb +43 -54
  10. data/lib/isodoc/function/blocks_example_note.rb +108 -0
  11. data/lib/isodoc/function/cleanup.rb +14 -2
  12. data/lib/isodoc/function/i18n.rb +1 -0
  13. data/lib/isodoc/function/inline.rb +76 -82
  14. data/lib/isodoc/function/inline_simple.rb +72 -0
  15. data/lib/isodoc/function/lists.rb +12 -6
  16. data/lib/isodoc/function/references.rb +65 -57
  17. data/lib/isodoc/function/reqt.rb +14 -5
  18. data/lib/isodoc/function/section.rb +8 -11
  19. data/lib/isodoc/function/table.rb +4 -5
  20. data/lib/isodoc/function/terms.rb +3 -3
  21. data/lib/isodoc/function/to_word_html.rb +22 -13
  22. data/lib/isodoc/function/utils.rb +9 -3
  23. data/lib/isodoc/headlesshtml_convert.rb +7 -6
  24. data/lib/isodoc/html_convert.rb +2 -1
  25. data/lib/isodoc/html_function/footnotes.rb +1 -1
  26. data/lib/isodoc/html_function/html.rb +16 -1
  27. data/lib/isodoc/html_function/postprocess.rb +6 -5
  28. data/lib/isodoc/metadata.rb +6 -0
  29. data/lib/isodoc/pdf_convert.rb +8 -6
  30. data/lib/isodoc/presentation_xml_convert.rb +29 -0
  31. data/lib/isodoc/version.rb +1 -1
  32. data/lib/isodoc/word_convert.rb +2 -1
  33. data/lib/isodoc/word_function/body.rb +14 -48
  34. data/lib/isodoc/word_function/footnotes.rb +1 -1
  35. data/lib/isodoc/word_function/inline.rb +75 -0
  36. data/lib/isodoc/word_function/postprocess.rb +1 -0
  37. data/lib/isodoc/word_function/table.rb +3 -3
  38. data/lib/isodoc/xref.rb +59 -0
  39. data/lib/isodoc/{function → xref}/xref_anchor.rb +10 -21
  40. data/lib/isodoc/xref/xref_counter.rb +74 -0
  41. data/lib/isodoc/{function → xref}/xref_gen.rb +9 -22
  42. data/lib/isodoc/{function → xref}/xref_gen_seq.rb +41 -32
  43. data/lib/isodoc/{function → xref}/xref_sect_gen.rb +33 -23
  44. data/lib/isodoc/xslfo_convert.rb +16 -4
  45. data/spec/assets/i18n.yaml +4 -1
  46. data/spec/assets/odf.emf +0 -0
  47. data/spec/assets/odf.svg +4 -0
  48. data/spec/assets/odf1.svg +4 -0
  49. data/spec/isodoc/blocks_spec.rb +240 -59
  50. data/spec/isodoc/cleanup_spec.rb +139 -17
  51. data/spec/isodoc/footnotes_spec.rb +20 -5
  52. data/spec/isodoc/inline_spec.rb +296 -1
  53. data/spec/isodoc/lists_spec.rb +8 -8
  54. data/spec/isodoc/metadata_spec.rb +110 -3
  55. data/spec/isodoc/postproc_spec.rb +10 -14
  56. data/spec/isodoc/presentation_xml_spec.rb +20 -0
  57. data/spec/isodoc/ref_spec.rb +119 -50
  58. data/spec/isodoc/section_spec.rb +84 -18
  59. data/spec/isodoc/table_spec.rb +28 -28
  60. data/spec/isodoc/terms_spec.rb +7 -7
  61. data/spec/isodoc/xref_spec.rb +177 -57
  62. metadata +24 -17
  63. data/lib/isodoc/function/blocks_example.rb +0 -53
  64. data/lib/isodoc/function/xref_counter.rb +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c880a51deba0cb3638cae9563b05e1216c34b631225bd1fecb28c8b070a2affb
4
- data.tar.gz: f64deeac458969b8f9c396b3f72bea106fb50da295132092ea13dcc2daf38d4e
3
+ metadata.gz: 0fe7dc7a4c361573ce166000c4b747853185889ed1385f6219da5ecd9bf33b73
4
+ data.tar.gz: 2da4bf7a5c8a282bdfee95b96b99322c246712405b429404d5accf3385f9b360
5
5
  SHA512:
6
- metadata.gz: 184392c1f9e0b216a32f80309e031f5ee9cf85679af2975dfa24ca58807094da25445f8a2068da7032f16484ccf91e83eae9dbb1f9d26b08856b2893f117ea58
7
- data.tar.gz: b8cfd29ad7920acb05e192197d6332189cfcec4412980665a3251bae5c32a235fff257fffc0726195826b79a3405135409259aff3020eabf8949f8aa0cc85c55
6
+ metadata.gz: 62e7510c6f20ac7d8773d112bc25957c543097164e3b794dcc05d9b241be70317ea37295e9da8d3fcf61aec5597471091af2912277977db1fa266dd3f5351cae
7
+ data.tar.gz: 6c09ae0a60b767cd4d3dd4ce22a6df2609ea8d1a21f29863a5c5ca27283ebe5897f0d530bf89212dc7b8cd4788641f66d04d646a04189f9c3c379e058d3c50c7
@@ -6,33 +6,37 @@ on:
6
6
  push:
7
7
  branches: [ master ]
8
8
  pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/ubuntu.yml
11
+ - .github/workflows/windows.yml
9
12
 
10
13
  jobs:
11
14
  test-macos:
12
15
  name: Test on Ruby ${{ matrix.ruby }} macOS
13
16
  runs-on: macos-latest
17
+ continue-on-error: ${{ matrix.experimental }}
14
18
  strategy:
15
19
  fail-fast: false
16
20
  matrix:
17
21
  ruby: [ '2.6', '2.5', '2.4' ]
22
+ experimental: [false]
23
+ include:
24
+ - ruby: '2.7'
25
+ experimental: true
18
26
  steps:
19
27
  - uses: actions/checkout@master
20
28
  - name: Use Ruby
21
29
  uses: actions/setup-ruby@v1
22
30
  with:
23
31
  ruby-version: ${{ matrix.ruby }}
24
- architecture: 'x64'
32
+ - name: Install Inkscape
33
+ run: |
34
+ brew cask install inkscape
35
+ inkscape --version
25
36
  - name: Update gems
26
37
  run: |
27
38
  sudo gem install bundler --force
28
39
  bundle install --jobs 4 --retry 3
29
- - name: Use Node
30
- uses: actions/setup-node@v1
31
- with:
32
- node-version: '12'
33
- - name: Install Puppeteer
34
- run: |
35
- npm install -g puppeteer@3.0.1
36
40
  - name: Run specs
37
41
  run: |
38
42
  bundle exec rake
@@ -5,48 +5,58 @@ name: ubuntu
5
5
  on:
6
6
  push:
7
7
  branches: [ master ]
8
+ tags:
9
+ - '*'
8
10
  pull_request:
11
+ paths-ignore:
12
+ - .github/workflows/macos.yml
13
+ - .github/workflows/windows.yml
9
14
 
10
15
  jobs:
11
16
  test-linux:
12
17
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
13
18
  runs-on: ubuntu-latest
19
+ continue-on-error: ${{ matrix.experimental }}
14
20
  strategy:
15
21
  fail-fast: false
16
22
  matrix:
17
23
  ruby: [ '2.6', '2.5', '2.4' ]
24
+ experimental: [false]
25
+ include:
26
+ - ruby: '2.7'
27
+ experimental: true
18
28
  steps:
19
29
  - uses: actions/checkout@master
20
30
  - name: Use Ruby
21
31
  uses: actions/setup-ruby@v1
22
32
  with:
23
33
  ruby-version: ${{ matrix.ruby }}
24
- architecture: 'x64'
34
+ - name: Install Inkscape
35
+ run: |
36
+ sudo add-apt-repository ppa:inkscape.dev/stable
37
+ sudo apt update
38
+ sudo apt install inkscape
39
+ inkscape --version
25
40
  - name: Update gems
26
41
  run: |
27
42
  gem install bundler
28
43
  bundle install --jobs 4 --retry 3
29
- - name: Use Node
30
- uses: actions/setup-node@v1
31
- with:
32
- node-version: '12'
33
- - name: Install Puppeteer
34
- run: |
35
- sudo apt-get update
36
- sudo apt-get install libgbm1
37
- npm install -g puppeteer@3.0.1
38
44
  - name: Run specs
39
45
  run: |
40
46
  bundle exec rake
41
- - name: Trigger dependent repositories
42
- if: github.ref == 'refs/heads/master'
47
+ - name: Trigger repositories
48
+ if: matrix.ruby == '2.6'
43
49
  env:
44
- GH_USERNAME: ${{ secrets.PAT_USERNAME }}
45
- GH_ACCESS_TOKEN: ${{ secrets.PAT_TOKEN }}
50
+ GH_USERNAME: metanorma-ci
51
+ GH_ACCESS_TOKEN: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
46
52
  run: |
47
53
  curl -LO --retry 3 https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/trigger-gh-actions.sh
48
54
  [[ -f ".github/workflows/dependent_repos.env" ]] && source .github/workflows/dependent_repos.env
49
- for repo in $DEPENDENT_REPOS
55
+ CLIENT_PAYLOAD=$(cat <<EOF
56
+ "{ "ref": "${GITHUB_REF}", "repo": "${GITHUB_REPOSITORY}" }"
57
+ EOF
58
+ )
59
+ for repo in $REPOS
50
60
  do
51
- sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY
61
+ sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY "$CLIENT_PAYLOAD"
52
62
  done
@@ -6,35 +6,39 @@ on:
6
6
  push:
7
7
  branches: [ master ]
8
8
  pull_request:
9
+ paths-ignore:
10
+ - .github/workflows/macos.yml
11
+ - .github/workflows/ubuntu.yml
9
12
 
10
13
  jobs:
11
14
  test-windows:
12
15
  name: Test on Ruby ${{ matrix.ruby }} Windows
13
16
  runs-on: windows-latest
17
+ continue-on-error: ${{ matrix.experimental }}
14
18
  strategy:
15
19
  fail-fast: false
16
20
  matrix:
17
21
  ruby: [ '2.6', '2.5', '2.4' ]
22
+ experimental: [false]
23
+ include:
24
+ - ruby: '2.7'
25
+ experimental: true
18
26
  steps:
19
27
  - uses: actions/checkout@master
20
28
  - name: Use Ruby
21
29
  uses: actions/setup-ruby@v1
22
30
  with:
23
31
  ruby-version: ${{ matrix.ruby }}
24
- architecture: 'x64'
32
+ - name: Install Inkscape
33
+ run: |
34
+ choco install --no-progress -y inkscape
35
+ inkscape --version
25
36
  - name: Update gems
26
37
  shell: pwsh
27
38
  run: |
28
39
  gem install bundler
29
40
  bundle config --local path vendor/bundle
30
41
  bundle install --jobs 4 --retry 3
31
- - name: Use Node
32
- uses: actions/setup-node@v1
33
- with:
34
- node-version: '12'
35
- - name: Install Puppeteer
36
- run: |
37
- npm install -g puppeteer@3.0.1
38
42
  - name: Run specs
39
43
  run: |
40
44
  bundle exec rake
@@ -36,8 +36,8 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "html2doc", "~> 1.0.0"
37
37
  spec.add_dependency "liquid"
38
38
  spec.add_dependency "roman-numerals"
39
- spec.add_dependency "sassc", "~> 2.2.1"
40
- spec.add_dependency "metanorma", "~> 1.0.0"
39
+ spec.add_dependency "sassc", "~> 2.4.0"
40
+ spec.add_dependency "metanorma", "~> 1.1.0"
41
41
  spec.add_dependency "rake", "~> 12.0"
42
42
 
43
43
  spec.add_development_dependency "byebug", "~> 9.1"
@@ -21,6 +21,8 @@ require "isodoc/word_convert"
21
21
  require "isodoc/pdf_convert"
22
22
  require "isodoc/xslfo_convert"
23
23
  require "isodoc/headlesshtml_convert"
24
+ require "isodoc/presentation_xml_convert"
25
+ require "isodoc/xref"
24
26
 
25
27
  module IsoDoc
26
28
 
@@ -9,8 +9,6 @@ require_relative "./function/table"
9
9
  require_relative "./function/terms"
10
10
  require_relative "./function/to_word_html"
11
11
  require_relative "./function/utils"
12
- require_relative "./function/xref_gen"
13
- require_relative "./function/xref_sect_gen"
14
12
  require_relative "./function/reqt"
15
13
  require_relative "./class_utils"
16
14
 
@@ -27,8 +25,6 @@ module IsoDoc
27
25
  include Function::Terms
28
26
  include Function::ToWordHtml
29
27
  include Function::Utils
30
- include Function::XrefGen
31
- include Function::XrefSectGen
32
28
 
33
29
  extend ::IsoDoc::ClassUtils
34
30
  end
@@ -53,7 +53,6 @@ module IsoDoc
53
53
  @termexample = false
54
54
  @note = false
55
55
  @sourcecode = false
56
- @anchors = {}
57
56
  @footnotes = []
58
57
  @comments = []
59
58
  @in_footnote = false
@@ -142,7 +141,7 @@ module IsoDoc
142
141
  end
143
142
 
144
143
  def convert1(docxml, filename, dir)
145
- anchor_names docxml
144
+ @xrefs.parse docxml
146
145
  noko do |xml|
147
146
  xml.html **{ lang: "#{@lang}" } do |html|
148
147
  html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
@@ -158,25 +157,36 @@ module IsoDoc
158
157
  @meta = Metadata.new(lang, script, labels)
159
158
  end
160
159
 
161
- def convert_init(file, filename, debug)
160
+ def xref_init(lang, script, klass, labels, options)
161
+ @xrefs = Xref.new(lang, script, klass, labels, options)
162
+ end
163
+
164
+ def convert_init(file, input_filename, debug)
162
165
  docxml = Nokogiri::XML(file)
163
- filename, dir = init_file(filename, debug)
166
+ filename, dir = init_file(input_filename, debug)
164
167
  docxml.root.default_namespace = ""
165
168
  lang = docxml&.at(ns("//bibdata/language"))&.text || @lang
166
169
  script = docxml&.at(ns("//bibdata/script"))&.text || @script
167
170
  i18n_init(lang, script)
168
171
  metadata_init(lang, script, @labels)
172
+ xref_init(lang, script, self, @labels, {})
169
173
  [docxml, filename, dir]
170
174
  end
171
175
 
172
- def convert(filename, file = nil, debug = false)
173
- file = File.read(filename, encoding: "utf-8") if file.nil?
176
+ def convert(input_filename, file = nil, debug = false, output_filename = nil)
177
+ file = File.read(input_filename, encoding: "utf-8") if file.nil?
174
178
  @openmathdelim, @closemathdelim = extract_delims(file)
175
- docxml, filename, dir = convert_init(file, filename, debug)
179
+ docxml, filename, dir = convert_init(file, input_filename, debug)
176
180
  result = convert1(docxml, filename, dir)
177
181
  return result if debug
178
- postprocess(result, filename, dir)
182
+ output_filename ||= "#{filename}.#{@suffix}"
183
+ postprocess(result, output_filename, dir)
179
184
  FileUtils.rm_rf dir
180
185
  end
186
+
187
+ def middle_clause
188
+ "//clause[parent::sections][not(xmlns:title = 'Scope')]"\
189
+ "[not(descendant::terms)]".freeze
190
+ end
181
191
  end
182
192
  end
@@ -1,48 +1,12 @@
1
- require_relative "blocks_example"
1
+ require_relative "blocks_example_note"
2
2
 
3
3
  module IsoDoc::Function
4
4
  module Blocks
5
5
  @annotation = false
6
6
 
7
- def note_label(node)
8
- n = get_anchors[node["id"]]
9
- return @note_lbl if n.nil? || n[:label].nil? || n[:label].empty?
10
- l10n("#{@note_lbl} #{n[:label]}")
11
- end
12
-
13
- def note_p_parse(node, div)
14
- div.p do |p|
15
- p.span **{ class: "note_label" } do |s|
16
- s << note_label(node)
17
- end
18
- insert_tab(p, 1)
19
- node.first_element_child.children.each { |n| parse(n, p) }
20
- end
21
- node.element_children[1..-1].each { |n| parse(n, div) }
22
- end
23
-
24
- def note_parse1(node, div)
25
- div.p do |p|
26
- p.span **{ class: "note_label" } do |s|
27
- s << note_label(node)
28
- end
29
- insert_tab(p, 1)
30
- end
31
- node.children.each { |n| parse(n, div) }
32
- end
33
-
34
- def note_parse(node, out)
35
- @note = true
36
- out.div **{ id: node["id"], class: "Note" } do |div|
37
- node.first_element_child.name == "p" ?
38
- note_p_parse(node, div) : note_parse1(node, div)
39
- end
40
- @note = false
41
- end
42
-
43
7
  def figure_name_parse(node, div, name)
44
8
  return if name.nil? && node.at(ns("./figure"))
45
- lbl = anchor(node['id'], :label, false)
9
+ lbl = @xrefs.anchor(node['id'], :label, false)
46
10
  lbl = nil if labelled_ancestor(node) && node.ancestors("figure").empty?
47
11
  return if lbl.nil? && name.nil?
48
12
  div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
@@ -58,11 +22,15 @@ module IsoDoc::Function
58
22
  end
59
23
  end
60
24
 
25
+ def figure_attrs(node)
26
+ attr_code(id: node["id"], class: "figure", style: keep_style(node))
27
+ end
28
+
61
29
  def figure_parse(node, out)
62
30
  return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
63
31
  node["type"] == "pseudocode"
64
32
  @in_figure = true
65
- out.div **attr_code(id: node["id"], class: "figure") do |div|
33
+ out.div **figure_attrs(node) do |div|
66
34
  node.children.each do |n|
67
35
  figure_key(out) if n.name == "dl"
68
36
  parse(n, div) unless n.name == "name"
@@ -72,10 +40,14 @@ module IsoDoc::Function
72
40
  @in_figure = false
73
41
  end
74
42
 
43
+ def pseudocode_attrs(node)
44
+ attr_code(id: node["id"], class: "pseudocode", style: keep_style(node))
45
+ end
46
+
75
47
  def pseudocode_parse(node, out)
76
48
  @in_figure = true
77
49
  name = node.at(ns("./name"))
78
- out.div **attr_code(id: node["id"], class: "pseudocode") do |div|
50
+ out.div **pseudocode_attrs(node) do |div|
79
51
  node.children.each { |n| parse(n, div) unless n.name == "name" }
80
52
  sourcecode_name_parse(node, div, name)
81
53
  end
@@ -83,7 +55,7 @@ module IsoDoc::Function
83
55
  end
84
56
 
85
57
  def sourcecode_name_parse(node, div, name)
86
- lbl = anchor(node['id'], :label, false)
58
+ lbl = @xrefs.anchor(node['id'], :label, false)
87
59
  lbl = nil if labelled_ancestor(node)
88
60
  return if lbl.nil? && name.nil?
89
61
  div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
@@ -101,9 +73,13 @@ module IsoDoc::Function
101
73
  end
102
74
  end
103
75
 
76
+ def sourcecode_attrs(node)
77
+ attr_code(id: node["id"], class: "Sourcecode", style: keep_style(node))
78
+ end
79
+
104
80
  def sourcecode_parse(node, out)
105
81
  name = node.at(ns("./name"))
106
- out.p **attr_code(id: node["id"], class: "Sourcecode") do |div|
82
+ out.p **sourcecode_attrs(node) do |div|
107
83
  @sourcecode = true
108
84
  node.children.each { |n| parse(n, div) unless n.name == "name" }
109
85
  @sourcecode = false
@@ -138,10 +114,15 @@ module IsoDoc::Function
138
114
  name
139
115
  end
140
116
 
117
+ def admonition_attrs(node)
118
+ attr_code(id: node["id"], class: admonition_class(node),
119
+ style: keep_style(node))
120
+ end
121
+
141
122
  def admonition_parse(node, out)
142
123
  type = node["type"]
143
124
  name = admonition_name(node, type)
144
- out.div **{ class: admonition_class(node) } do |t|
125
+ out.div **admonition_attrs(node) do |t|
145
126
  admonition_name_parse(node, t, name) if name
146
127
  node.children.each { |n| parse(n, t) unless n.name == "name" }
147
128
  end
@@ -157,10 +138,10 @@ module IsoDoc::Function
157
138
  end
158
139
 
159
140
  def formula_parse1(node, out)
160
- out.div **attr_code(id: node["id"], class: "formula") do |div|
141
+ out.div **attr_code(class: "formula") do |div|
161
142
  div.p do |p|
162
143
  parse(node.at(ns("./stem")), div)
163
- lbl = anchor(node['id'], :label, false)
144
+ lbl = @xrefs.anchor(node['id'], :label, false)
164
145
  unless lbl.nil?
165
146
  insert_tab(div, 1)
166
147
  div << "(#{lbl})"
@@ -169,12 +150,18 @@ module IsoDoc::Function
169
150
  end
170
151
  end
171
152
 
153
+ def formula_attrs(node)
154
+ attr_code(id: node["id"], style: keep_style(node))
155
+ end
156
+
172
157
  def formula_parse(node, out)
173
- formula_parse1(node, out)
174
- formula_where(node.at(ns("./dl")), out)
175
- node.children.each do |n|
176
- next if %w(stem dl).include? n.name
177
- parse(n, out)
158
+ out.div **formula_attrs(node) do |div|
159
+ formula_parse1(node, div)
160
+ formula_where(node.at(ns("./dl")), div)
161
+ node.children.each do |n|
162
+ next if %w(stem dl).include? n.name
163
+ parse(n, div)
164
+ end
178
165
  end
179
166
  end
180
167
 
@@ -187,8 +174,9 @@ module IsoDoc::Function
187
174
 
188
175
  def para_attrs(node)
189
176
  attrs = { class: para_class(node), id: node["id"] }
190
- node["align"].nil? or
191
- attrs[:style] = "text-align:#{node['align']};"
177
+ s = node["align"].nil? ? "" : "text-align:#{node['align']};"
178
+ s = "#{s}#{keep_style(node)}"
179
+ attrs[:style] = s unless s.empty?
192
180
  attrs
193
181
  end
194
182
 
@@ -224,8 +212,9 @@ module IsoDoc::Function
224
212
  end
225
213
 
226
214
  def passthrough_parse(node, out)
227
- return if node["format"] and !(node["format"].split(/,/).include? @format.to_s)
228
- out << HTMLEntities.new.decode(node.content)
215
+ return if node["format"] and
216
+ !(node["format"].split(/,/).include? @format.to_s)
217
+ out.passthrough node.text
229
218
  end
230
219
  end
231
220
  end