metanorma-standoc 1.4.0 → 1.5.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +0 -7
  3. data/.github/workflows/ubuntu.yml +6 -11
  4. data/.github/workflows/windows.yml +0 -8
  5. data/.rubocop.yml +1 -1
  6. data/Rakefile +2 -0
  7. data/lib/asciidoctor/standoc/base.rb +28 -27
  8. data/lib/asciidoctor/standoc/biblio.rng +1 -1
  9. data/lib/asciidoctor/standoc/blocks.rb +25 -95
  10. data/lib/asciidoctor/standoc/blocks_notes.rb +89 -0
  11. data/lib/asciidoctor/standoc/cleanup.rb +10 -6
  12. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +11 -24
  13. data/lib/asciidoctor/standoc/cleanup_inline.rb +1 -1
  14. data/lib/asciidoctor/standoc/cleanup_ref.rb +47 -1
  15. data/lib/asciidoctor/standoc/cleanup_section.rb +72 -5
  16. data/lib/asciidoctor/standoc/cleanup_terms.rb +10 -0
  17. data/lib/asciidoctor/standoc/converter.rb +16 -2
  18. data/lib/asciidoctor/standoc/inline.rb +1 -1
  19. data/lib/asciidoctor/standoc/isodoc.rng +439 -6
  20. data/lib/asciidoctor/standoc/lists.rb +12 -12
  21. data/lib/asciidoctor/standoc/macros_yaml2text.rb +32 -15
  22. data/lib/asciidoctor/standoc/ref.rb +75 -34
  23. data/lib/asciidoctor/standoc/reqt.rb +11 -6
  24. data/lib/asciidoctor/standoc/reqt.rng +23 -0
  25. data/lib/asciidoctor/standoc/section.rb +27 -25
  26. data/lib/asciidoctor/standoc/table.rb +3 -2
  27. data/lib/asciidoctor/standoc/utils.rb +16 -0
  28. data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +1 -1
  29. data/lib/metanorma/standoc/processor.rb +5 -7
  30. data/lib/metanorma/standoc/version.rb +1 -1
  31. data/metanorma-standoc.gemspec +3 -2
  32. data/spec/asciidoctor-standoc/base_spec.rb +3 -2
  33. data/spec/asciidoctor-standoc/blocks_spec.rb +68 -32
  34. data/spec/asciidoctor-standoc/cleanup_spec.rb +1221 -17
  35. data/spec/asciidoctor-standoc/datamodel/attributes_table_preprocessor_spec.rb +35 -0
  36. data/spec/asciidoctor-standoc/inline_spec.rb +3 -3
  37. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -4
  38. data/spec/asciidoctor-standoc/lists_spec.rb +7 -5
  39. data/spec/asciidoctor-standoc/macros_spec.rb +4 -3
  40. data/spec/asciidoctor-standoc/refs_dl_spec.rb +8 -6
  41. data/spec/asciidoctor-standoc/refs_spec.rb +275 -30
  42. data/spec/asciidoctor-standoc/section_spec.rb +42 -38
  43. data/spec/asciidoctor-standoc/table_spec.rb +3 -3
  44. data/spec/asciidoctor-standoc/validate_spec.rb +56 -0
  45. data/spec/assets/{html.css → html.scss} +0 -0
  46. data/spec/assets/i18n.yaml +17 -2
  47. data/spec/assets/iso123.rxl +107 -0
  48. data/spec/assets/{word.css → word.scss} +0 -0
  49. data/spec/examples/datamodel/blank_definition_profile.adoc +4 -0
  50. data/spec/examples/datamodel/models/models/{Signature copy.yml → SignatureBlankDefinition.yml} +2 -2
  51. data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +51 -0
  52. data/spec/metanorma/processor_spec.rb +5 -6
  53. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +83 -83
  54. data/spec/vcr_cassettes/isobib_get_123.yml +19 -198
  55. data/spec/vcr_cassettes/isobib_get_123_1.yml +361 -0
  56. data/spec/vcr_cassettes/isobib_get_123_2001.yml +19 -19
  57. data/spec/vcr_cassettes/isobib_get_124.yml +21 -21
  58. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +10 -10
  59. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +42 -42
  60. metadata +32 -18
  61. data/lib/asciidoctor-yaml/i18n-en.yaml +0 -20
  62. data/lib/asciidoctor-yaml/i18n-fr.yaml +0 -13
  63. data/lib/asciidoctor-yaml/i18n-zh-Hans.yaml +0 -15
  64. data/lib/asciidoctor/standoc/i18n.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e86d9135fffb1f112db82f9d052632aa36f134a76b03ff48e65dcb841c7cbb4
4
- data.tar.gz: ea05dff988ebaf6b51c029d99cbadd195300c3c524acd301157a335257436c01
3
+ metadata.gz: 76c3b117ea592275339f9ee8103f17645d9675f45635abfbc8e5333fc512af1c
4
+ data.tar.gz: a345b19a2657f356225f2087e17a7dba7bd4720389cf44487892d3f1e1bc5345
5
5
  SHA512:
6
- metadata.gz: beead161e217dba5841732200aa8cb897900ea90b1a449f092fe63ffe40ca59a6b904b098affd1a475723ac4663ba5dadd09fdab48b661376c4fe659360c79a4
7
- data.tar.gz: 43b697f04165938864eab22a1d4d49613adef7ae1703995a5541018fe438f09ff21dd43e37e25ebeab9a0d514b50f64b64d2a8a47c8836b924d4578b9f076d19
6
+ metadata.gz: 630d1159cc78920d3bab3e73a2577b54d00bb966b0faa15166ff1af832656ab985e55f8fa830d40a2fbec96a8cf8555880f89f0e73d749dc73540e6cd8303469
7
+ data.tar.gz: f3c46604bb69f1e34eb8b2af182e198e99a6f2cae3bce808a9547e096b1852b4868c00a8522370a52c92ad5f263ab2f7e5ee348196fffbe1084ef1c666900080
@@ -29,10 +29,6 @@ jobs:
29
29
  uses: actions/setup-ruby@v1
30
30
  with:
31
31
  ruby-version: ${{ matrix.ruby }}
32
- architecture: 'x64'
33
- - uses: actions/setup-node@v1
34
- with:
35
- node-version: '10.x'
36
32
  - name: Install LaTeXML
37
33
  run: |
38
34
  brew install libxml2 cpanminus
@@ -41,9 +37,6 @@ jobs:
41
37
  - name: Install PlantUML
42
38
  run: |
43
39
  brew install plantuml
44
- - name: Install puppeteer
45
- run: |
46
- npm -g i puppeteer
47
40
  - name: Update gems
48
41
  run: |
49
42
  sudo gem install bundler --force
@@ -29,10 +29,6 @@ jobs:
29
29
  uses: actions/setup-ruby@v1
30
30
  with:
31
31
  ruby-version: ${{ matrix.ruby }}
32
- architecture: 'x64'
33
- - uses: actions/setup-node@v1
34
- with:
35
- node-version: '10.x'
36
32
  - name: Update gems
37
33
  run: |
38
34
  gem install bundler
@@ -42,13 +38,12 @@ jobs:
42
38
  sudo snap install latexml --edge
43
39
  echo "::add-path::/snap/bin"
44
40
  - name: Install PlantUML
45
- run: |
46
- curl -L https://raw.githubusercontent.com/metanorma/plantuml-install/master/ubuntu.sh | sudo bash
47
- - name: Install puppeteer
48
- run: |
49
- sudo apt-get update
50
- sudo apt-get install -y libgbm1
51
- npm install -g puppeteer@3.0.1
41
+ uses: nick-invision/retry@v1
42
+ with:
43
+ polling_interval_seconds: 5
44
+ timeout_minutes: 5
45
+ max_attempts: 3
46
+ command: sudo bash -c "curl -L https://github.com/metanorma/plantuml-install/raw/master/ubuntu.sh | bash"
52
47
  - name: Run specs
53
48
  run: |
54
49
  bundle exec rake
@@ -29,10 +29,6 @@ jobs:
29
29
  uses: actions/setup-ruby@v1
30
30
  with:
31
31
  ruby-version: ${{ matrix.ruby }}
32
- architecture: 'x64'
33
- - uses: actions/setup-node@v1
34
- with:
35
- node-version: '10.x'
36
32
  - name: Install MN Windows dependencies
37
33
  shell: pwsh
38
34
  run: |
@@ -50,10 +46,6 @@ jobs:
50
46
  refreshenv
51
47
  set PATH=C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;%PATH%
52
48
  where latexmlmath
53
- - name: Install puppeteer
54
- shell: pwsh
55
- run: |
56
- npm -g i puppeteer
57
49
  - name: Run specs
58
50
  shell: pwsh
59
51
  run: |
@@ -5,6 +5,6 @@
5
5
  inherit_from:
6
6
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
7
7
  AllCops:
8
- TargetRubyVersion: 2.3
8
+ TargetRubyVersion: 2.6
9
9
  Rails:
10
10
  Enabled: true
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'isodoc/gem_tasks'
3
4
 
5
+ IsoDoc::GemTasks.install
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
8
  task default: :spec
@@ -14,22 +14,6 @@ module Asciidoctor
14
14
  XML_ROOT_TAG = "standard-document".freeze
15
15
  XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
16
16
 
17
- Asciidoctor::Extensions.register do
18
- preprocessor Asciidoctor::Standoc::Datamodel::AttributesTablePreprocessor
19
- preprocessor Asciidoctor::Standoc::Datamodel::DiagramPreprocessor
20
- preprocessor Asciidoctor::Standoc::Yaml2TextPreprocessor
21
- inline_macro Asciidoctor::Standoc::AltTermInlineMacro
22
- inline_macro Asciidoctor::Standoc::DeprecatedTermInlineMacro
23
- inline_macro Asciidoctor::Standoc::DomainTermInlineMacro
24
- inline_macro Asciidoctor::Standoc::InheritInlineMacro
25
- inline_macro Asciidoctor::Standoc::HTML5RubyMacro
26
- inline_macro Asciidoctor::Standoc::ConceptInlineMacro
27
- block Asciidoctor::Standoc::ToDoAdmonitionBlock
28
- treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
29
- block Asciidoctor::Standoc::PlantUMLBlockMacro
30
- block Asciidoctor::Standoc::PseudocodeBlockMacro
31
- end
32
-
33
17
  def xml_root_tag
34
18
  self.class::XML_ROOT_TAG
35
19
  end
@@ -98,6 +82,10 @@ module Asciidoctor
98
82
  IsoDoc::WordConvert.new(doc_extract_attributes(node))
99
83
  end
100
84
 
85
+ def presentation_xml_converter(node)
86
+ IsoDoc::PresentationXMLConvert.new(html_extract_attributes(node))
87
+ end
88
+
101
89
  def init(node)
102
90
  @fn_number ||= 0
103
91
  @draft = false
@@ -113,6 +101,7 @@ module Asciidoctor
113
101
  @filename = node.attr("docfile") ?
114
102
  File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
115
103
  @localdir = Utils::localdir(node)
104
+ @output_dir = outputdir node
116
105
  @no_isobib_cache = node.attr("no-isobib-cache")
117
106
  @no_isobib = node.attr("no-isobib")
118
107
  @bibdb = nil
@@ -122,9 +111,10 @@ module Asciidoctor
122
111
  @log = Asciidoctor::Standoc::Log.new
123
112
  init_bib_caches(node)
124
113
  init_iev_caches(node)
125
- lang = (node.attr("language") || "en")
126
- script = (node.attr("script") || "en")
127
- i18n_init(lang, script)
114
+ @lang = (node.attr("language") || "en")
115
+ @script = (node.attr("script") || "Latn")
116
+ @isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
117
+ @i18n = @isodoc.i18n
128
118
  end
129
119
 
130
120
  def default_fonts(node)
@@ -138,20 +128,23 @@ module Asciidoctor
138
128
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
139
129
  end
140
130
 
131
+ def outputs(node, ret)
132
+ File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
133
+ presentation_xml_converter(node).convert(@filename + ".xml")
134
+ html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
135
+ doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
136
+ end
137
+
141
138
  def document(node)
142
139
  init(node)
143
140
  ret = makexml(node).to_xml(indent: 2)
144
- unless node.attr("nodoc") || !node.attr("docfile")
145
- File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
146
- html_converter(node).convert(@filename + ".xml")
147
- doc_converter(node).convert(@filename + ".xml")
148
- end
141
+ outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
149
142
  clean_exit
150
143
  ret
151
144
  end
152
145
 
153
146
  def clean_exit
154
- @log.write(@localdir + @filename + ".err") unless @novalid
147
+ @log.write(@output_dir + @filename + ".err") unless @novalid
155
148
  @files_to_delete.each { |f| FileUtils.rm f }
156
149
  end
157
150
 
@@ -192,7 +185,7 @@ module Asciidoctor
192
185
  end
193
186
  end
194
187
 
195
- def term_source_attr(seen_xref)
188
+ def term_source_attrs(seen_xref)
196
189
  { bibitemid: seen_xref.children[0]["target"],
197
190
  format: seen_xref.children[0]["format"],
198
191
  type: "inline" }
@@ -203,7 +196,7 @@ module Asciidoctor
203
196
  xml_t.origin { |o| o << seen_xref.children[0].to_xml }
204
197
  else
205
198
  xml_t.origin seen_xref.children[0].content,
206
- **attr_code(term_source_attr(seen_xref))
199
+ **attr_code(term_source_attrs(seen_xref))
207
200
  end
208
201
  m[:text] && xml_t.modification do |mod|
209
202
  mod.p { |p| p << m[:text].sub(/^\s+/, "") }
@@ -236,6 +229,14 @@ module Asciidoctor
236
229
  end
237
230
  end.join("\n")
238
231
  end
232
+
233
+ private
234
+
235
+ def outputdir(node)
236
+ if node.attr("output_dir").nil_or_empty? then Utils::localdir(node)
237
+ else File.join(node.attr("output_dir"), "")
238
+ end
239
+ end
239
240
  end
240
241
  end
241
242
  end
@@ -532,7 +532,7 @@
532
532
  </define>
533
533
  <define name="LocalityType">
534
534
  <data type="string">
535
- <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|locality:[a-zA-Z0-9_]+</param>
535
+ <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
536
536
  </data>
537
537
  </define>
538
538
  <define name="referenceFrom">
@@ -1,5 +1,6 @@
1
1
  require "htmlentities"
2
2
  require "uri"
3
+ require_relative "./blocks_notes"
3
4
 
4
5
  module Asciidoctor
5
6
  module Standoc
@@ -8,28 +9,21 @@ module Asciidoctor
8
9
  { id: Utils::anchor_or_uuid(node) }
9
10
  end
10
11
 
11
- def id_unnum_attr(node)
12
+ def id_unnum_attrs(node)
12
13
  attr_code( id: Utils::anchor_or_uuid(node),
13
14
  unnumbered: node.option?("unnumbered") ? "true" : nil,
15
+ number: node.attr("number"),
14
16
  subsequence: node.attr("subsequence") )
15
17
  end
16
18
 
17
- def formula_attr(node)
18
- attr_code( id: Utils::anchor_or_uuid(node),
19
- inequality: node.option?("inequality") ? "true" : nil,
20
- unnumbered: node.option?("unnumbered") ? "true" : nil,
21
- subsequence: node.attr("subsequence") )
22
- end
23
-
24
- def termnote_attr(node)
25
- attr_code(id_attr(node).merge(
26
- "keep-separate": node.attr("keep-separate")))
19
+ def formula_attrs(node)
20
+ attr_code(id_unnum_attrs(node).merge(keep_attrs(node).merge(
21
+ inequality: node.option?("inequality") ? "true" : nil)))
27
22
  end
28
23
 
29
- def note_attr(node)
30
- attr_code(id_attr(node).merge(
31
- "keep-separate": node.attr("keep-separate"),
32
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
24
+ def keep_attrs(node)
25
+ { "keep-with-next": node.attr("keep-with-next"),
26
+ "keep-lines-together": node.attr("keep-lines-together") }
33
27
  end
34
28
 
35
29
  # We append each contained block to its parent
@@ -44,7 +38,7 @@ module Asciidoctor
44
38
  end
45
39
 
46
40
  def literal_attrs(node)
47
- attr_code(id_attr(node))
41
+ attr_code(id_attr(node).merge(keep_attrs(node)))
48
42
  end
49
43
 
50
44
  def literal(node)
@@ -60,80 +54,12 @@ module Asciidoctor
60
54
  # NOTE: html escaping is performed by Nokogiri
61
55
  def stem(node)
62
56
  noko do |xml|
63
- xml.formula **formula_attr(node) do |s|
57
+ xml.formula **formula_attrs(node) do |s|
64
58
  stem_parse(node.lines.join("\n"), s, node.style.to_sym)
65
59
  end
66
60
  end
67
61
  end
68
62
 
69
- def sidebar_attrs(node)
70
- todo_attrs(node).merge(attr_code(
71
- from: node.attr("from"), to: node.attr("to") || node.attr("from") ))
72
- end
73
-
74
- def sidebar(node)
75
- return unless draft?
76
- noko do |xml|
77
- xml.review **(sidebar_attrs(node)) do |r|
78
- wrap_in_para(node, r)
79
- end
80
- end
81
- end
82
-
83
- def todo_attrs(node)
84
- date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
85
- date += "T00:00:00Z" unless /T/.match date
86
- attr_code(
87
- id: Utils::anchor_or_uuid(node),
88
- reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
89
- date: date )
90
- end
91
-
92
- def todo(node)
93
- noko do |xml|
94
- xml.review **(todo_attrs(node)) do |r|
95
- wrap_in_para(node, r)
96
- end
97
- end
98
- end
99
-
100
- def termnote(n)
101
- noko do |xml|
102
- xml.termnote **termnote_attr(n) do |ex|
103
- wrap_in_para(n, ex)
104
- end
105
- end.join("\n")
106
- end
107
-
108
- def note(n)
109
- noko do |xml|
110
- xml.note **note_attr(n) do |c|
111
- wrap_in_para(n, c)
112
- end
113
- end.join("\n")
114
- end
115
-
116
- def admonition_attrs(node)
117
- name = node.attr("name")
118
- a = node.attr("type") and ["danger", "safety precautions"].each do |t|
119
- name = t if a.casecmp(t).zero?
120
- end
121
- attr_code(id: Utils::anchor_or_uuid(node), type: name,
122
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil)
123
- end
124
-
125
- def admonition(node)
126
- return termnote(node) if in_terms?
127
- return note(node) if node.attr("name") == "note"
128
- return todo(node) if node.attr("name") == "todo"
129
- noko do |xml|
130
- xml.admonition **admonition_attrs(node) do |a|
131
- node.title.nil? or a.name { |name| name << node.title }
132
- wrap_in_para(node, a)
133
- end
134
- end.join("\n")
135
- end
136
-
137
63
  def term_example(node)
138
64
  noko do |xml|
139
65
  xml.termexample **id_attr(node) do |ex|
@@ -155,7 +81,7 @@ module Asciidoctor
155
81
  # prevent A's and other subs inappropriate for pseudocode
156
82
  node.blocks.each { |b| b.remove_sub(:replacements) }
157
83
  noko do |xml|
158
- xml.figure **id_unnum_attr(node).merge(class: "pseudocode") do |ex|
84
+ xml.figure **example_attrs(node).merge(class: "pseudocode") do |ex|
159
85
  figure_title(node, ex)
160
86
  wrap_in_para(node, ex)
161
87
  end
@@ -163,7 +89,7 @@ module Asciidoctor
163
89
  end
164
90
 
165
91
  def example_attrs(node)
166
- attr_code(id_unnum_attr(node))
92
+ attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
167
93
  end
168
94
 
169
95
  def example_proper(node)
@@ -181,7 +107,7 @@ module Asciidoctor
181
107
  end
182
108
 
183
109
  def figure_attrs(node)
184
- attr_code(id_unnum_attr(node))
110
+ attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
185
111
  end
186
112
 
187
113
  def image(node)
@@ -194,7 +120,8 @@ module Asciidoctor
194
120
  end
195
121
 
196
122
  def para_attrs(node)
197
- attr_code(align: node.attr("align"), id: Utils::anchor_or_uuid(node))
123
+ attr_code(keep_attrs(node).merge(align: node.attr("align"),
124
+ id: Utils::anchor_or_uuid(node)))
198
125
  end
199
126
 
200
127
  def paragraph(node)
@@ -207,7 +134,8 @@ module Asciidoctor
207
134
  end
208
135
 
209
136
  def quote_attrs(node)
210
- attr_code(id: Utils::anchor_or_uuid(node), align: node.attr("align"))
137
+ attr_code(keep_attrs(node).merge(align: node.attr("align"),
138
+ id: Utils::anchor_or_uuid(node)))
211
139
  end
212
140
 
213
141
  def quote_attribution(node, out)
@@ -231,10 +159,11 @@ module Asciidoctor
231
159
  end
232
160
 
233
161
  def listing_attrs(node)
234
- attr_code(lang: node.attr("language"),
235
- id: Utils::anchor_or_uuid(node),
236
- unnumbered: node.option?("unnumbered") ? "true" : nil,
237
- filename: node.attr("filename"))
162
+ attr_code(keep_attrs(node).merge(lang: node.attr("language"),
163
+ id: Utils::anchor_or_uuid(node),
164
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
165
+ number: node.attr("number"),
166
+ filename: node.attr("filename")))
238
167
  end
239
168
 
240
169
  # NOTE: html escaping is performed by Nokogiri
@@ -251,7 +180,8 @@ module Asciidoctor
251
180
 
252
181
  def pass(node)
253
182
  noko do |xml|
254
- xml.passthrough **attr_code(formats: node.attr("format")) do |p|
183
+ xml.passthrough **attr_code(formats:
184
+ node.attr("format") || "metanorma") do |p|
255
185
  p << HTMLEntities.new.encode(node.content, :basic, :hexadecimal)
256
186
  end
257
187
  end
@@ -0,0 +1,89 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ module Blocks
4
+ def termnote_attrs(node)
5
+ attr_code(id_attr(node).merge(
6
+ unnumbered: node.attr("unnumbered"),
7
+ number: node.attr("number"),
8
+ subsequence: node.attr("subsequence"),
9
+ "keep-with-next": node.attr("keep-with-next"),
10
+ "keep-lines-together": node.attr("keep-with-next"),
11
+ "keep-separate": node.attr("keep-separate")))
12
+ end
13
+
14
+ def note_attrs(node)
15
+ attr_code(termnote_attrs(node).merge(
16
+ type: node.attr("type"),
17
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
18
+ end
19
+
20
+ def sidebar_attrs(node)
21
+ todo_attrs(node).merge(attr_code(
22
+ from: node.attr("from"), to: node.attr("to") || node.attr("from") ))
23
+ end
24
+
25
+ def sidebar(node)
26
+ return unless draft?
27
+ noko do |xml|
28
+ xml.review **(sidebar_attrs(node)) do |r|
29
+ wrap_in_para(node, r)
30
+ end
31
+ end
32
+ end
33
+
34
+ def todo_attrs(node)
35
+ date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
36
+ date += "T00:00:00Z" unless /T/.match date
37
+ attr_code(
38
+ id: Utils::anchor_or_uuid(node),
39
+ reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
40
+ date: date )
41
+ end
42
+
43
+ def todo(node)
44
+ noko do |xml|
45
+ xml.review **(todo_attrs(node)) do |r|
46
+ wrap_in_para(node, r)
47
+ end
48
+ end
49
+ end
50
+
51
+ def termnote(n)
52
+ noko do |xml|
53
+ xml.termnote **termnote_attrs(n) do |ex|
54
+ wrap_in_para(n, ex)
55
+ end
56
+ end.join("\n")
57
+ end
58
+
59
+ def note(n)
60
+ noko do |xml|
61
+ xml.note **note_attrs(n) do |c|
62
+ wrap_in_para(n, c)
63
+ end
64
+ end.join("\n")
65
+ end
66
+
67
+ def admonition_attrs(node)
68
+ name = node.attr("name")
69
+ a = node.attr("type") and ["danger", "safety precautions"].each do |t|
70
+ name = t if a.casecmp(t).zero?
71
+ end
72
+ attr_code(keep_attrs(node).merge(id: Utils::anchor_or_uuid(node), type: name,
73
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
74
+ end
75
+
76
+ def admonition(node)
77
+ return termnote(node) if in_terms?
78
+ return note(node) if node.attr("name") == "note"
79
+ return todo(node) if node.attr("name") == "todo"
80
+ noko do |xml|
81
+ xml.admonition **admonition_attrs(node) do |a|
82
+ node.title.nil? or a.name { |name| name << node.title }
83
+ wrap_in_para(node, a)
84
+ end
85
+ end.join("\n")
86
+ end
87
+ end
88
+ end
89
+ end