metanorma-standoc 3.0.8 → 3.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/isodoc/html/htmlstyle.css +0 -2
- data/lib/metanorma/standoc/anchor.rb +1 -1
- data/lib/metanorma/standoc/blocks.rb +12 -5
- data/lib/metanorma/standoc/blocks_image.rb +3 -8
- data/lib/metanorma/standoc/blocks_notes.rb +1 -1
- data/lib/metanorma/standoc/cleanup.rb +5 -1
- data/lib/metanorma/standoc/cleanup_bibdata.rb +1 -1
- data/lib/metanorma/standoc/cleanup_bibitem.rb +3 -2
- data/lib/metanorma/standoc/cleanup_footnotes.rb +1 -0
- data/lib/metanorma/standoc/cleanup_inline.rb +13 -12
- data/lib/metanorma/standoc/cleanup_section.rb +25 -3
- data/lib/metanorma/standoc/cleanup_section_names.rb +3 -2
- data/lib/metanorma/standoc/cleanup_terms.rb +14 -3
- data/lib/metanorma/standoc/cleanup_text.rb +5 -3
- data/lib/metanorma/standoc/converter.rb +17 -8
- data/lib/metanorma/standoc/init.rb +9 -3
- data/lib/metanorma/standoc/inline.rb +5 -0
- data/lib/metanorma/standoc/isodoc.rng +32 -2
- data/lib/metanorma/standoc/lists.rb +2 -2
- data/lib/metanorma/standoc/macros.rb +46 -2
- data/lib/metanorma/standoc/macros_inline.rb +44 -4
- data/lib/metanorma/standoc/macros_link.rb +9 -0
- data/lib/metanorma/standoc/macros_plantuml.rb +28 -14
- data/lib/metanorma/standoc/ref_sect.rb +2 -2
- data/lib/metanorma/standoc/render.rb +22 -13
- data/lib/metanorma/standoc/section.rb +20 -15
- data/lib/metanorma/standoc/sectiontype.rb +28 -20
- data/lib/metanorma/standoc/table.rb +2 -6
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +0 -9
- data/lib/metanorma/standoc/terms.rb +4 -3
- data/lib/metanorma/standoc/utils.rb +4 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -2
- metadata +4 -18
@@ -10,7 +10,6 @@ require_relative "macros_embed"
|
|
10
10
|
require_relative "macros_link"
|
11
11
|
require_relative "datamodel/attributes_table_preprocessor"
|
12
12
|
require_relative "datamodel/diagram_preprocessor"
|
13
|
-
require "metanorma-plugin-datastruct"
|
14
13
|
require "metanorma-plugin-glossarist"
|
15
14
|
require "metanorma-plugin-lutaml"
|
16
15
|
|
@@ -58,6 +57,7 @@ module Metanorma
|
|
58
57
|
p.process(l)
|
59
58
|
p.pass ? l : convert(l, c)
|
60
59
|
end
|
60
|
+
log(document, lines)
|
61
61
|
::Asciidoctor::PreprocessorReader.new document, lines
|
62
62
|
end
|
63
63
|
|
@@ -66,6 +66,18 @@ module Metanorma
|
|
66
66
|
/^&[A-Za-z]/.match?(s) ? esc.encode(esc.decode(s), :hexadecimal) : s
|
67
67
|
end.join
|
68
68
|
end
|
69
|
+
|
70
|
+
# debugging output of results of all preprocessing,
|
71
|
+
# including include files concatenation and Lutaml/Liquid processing
|
72
|
+
def log(doc, text)
|
73
|
+
source = doc.attr("docfile") || "metanorma"
|
74
|
+
dirname = File.dirname(source)
|
75
|
+
basename = File.basename(source, ".*")
|
76
|
+
fname = File.join(dirname, "#{basename}.asciidoc.log.txt")
|
77
|
+
File.open(fname, "w:UTF-8") do |f|
|
78
|
+
f.write(text.join("\n"))
|
79
|
+
end
|
80
|
+
end
|
69
81
|
end
|
70
82
|
|
71
83
|
class ColumnBreakBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
@@ -108,10 +120,14 @@ module Metanorma
|
|
108
120
|
|
109
121
|
def pass_inline_split(text)
|
110
122
|
text.split(PASS_INLINE_MACRO_RX).each.map do |x|
|
111
|
-
PASS_INLINE_MACRO_RX.match?(x) ? x : yield(x)
|
123
|
+
PASS_INLINE_MACRO_RX.match?(x) ? pass_convert(x) : yield(x)
|
112
124
|
end
|
113
125
|
end
|
114
126
|
|
127
|
+
def pass_convert(text)
|
128
|
+
text.sub(/^pass:\[(.+)$/, "pass-format:metanorma[\\1")
|
129
|
+
end
|
130
|
+
|
115
131
|
# InlineLinkRx = %r((^|link:|#{CG_BLANK}|<|[>\(\)\[\];"'])(\\?(?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)\[(|#{CC_ALL}*?[^\\])\]|([^\s\[\]<]*([^\s,.?!\[\]<\)]))))m
|
116
132
|
#
|
117
133
|
InlineLinkRx = %r((^|(?<![-\\])\blink:(?!\+)|\p{Blank}|<|[<>\(\)\[\];"'])((?:https?|file|ftp|irc)://)(?:([^\s\[\]]+)(?:(\[(|.*?[^\\])\])|([^\s\[\]<]*([^\s,.?!\[\]<\)])))))m
|
@@ -186,5 +202,33 @@ module Metanorma
|
|
186
202
|
end.join
|
187
203
|
end
|
188
204
|
end
|
205
|
+
|
206
|
+
# convert pass:[] to pass-format:metanorma[]
|
207
|
+
class PassProtectPreprocessor < LinkProtectPreprocessor
|
208
|
+
def process(document, reader)
|
209
|
+
p = Metanorma::Utils::LineStatus.new
|
210
|
+
lines = reader.lines.map do |t|
|
211
|
+
p.process(t)
|
212
|
+
!p.pass && t.include?("pass:") and t = inlinelink(t)
|
213
|
+
t
|
214
|
+
end
|
215
|
+
::Asciidoctor::PreprocessorReader.new document, lines
|
216
|
+
end
|
217
|
+
|
218
|
+
def pass_inline_split(text)
|
219
|
+
text.split(PASS_INLINE_MACRO_RX).each.map do |x|
|
220
|
+
PASS_INLINE_MACRO_RX.match?(x) ? pass_convert(x) : x
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def pass_convert(text)
|
225
|
+
text.sub(/^pass:\[(.+)$/, "pass-format:metanorma[\\1")
|
226
|
+
end
|
227
|
+
|
228
|
+
def inlinelink(text)
|
229
|
+
/^\[.*\]\s*$/.match?(text) and return text
|
230
|
+
pass_inline_split(text).join
|
231
|
+
end
|
232
|
+
end
|
189
233
|
end
|
190
234
|
end
|
@@ -58,6 +58,30 @@ module Metanorma
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
class AnchorInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
62
|
+
use_dsl
|
63
|
+
named :anchor
|
64
|
+
parse_content_as :text
|
65
|
+
|
66
|
+
def process(parent, target, attrs)
|
67
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
68
|
+
id = "_#{UUIDTools::UUID.random_create}"
|
69
|
+
%{<span id='#{id}' anchor='#{target}'>#{out}</span>}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class SourceIdInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
74
|
+
use_dsl
|
75
|
+
named :"source-id"
|
76
|
+
parse_content_as :text
|
77
|
+
|
78
|
+
def process(parent, target, attrs)
|
79
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
80
|
+
id = "_#{UUIDTools::UUID.random_create}"
|
81
|
+
%{<span id='#{id}' source='#{target}'>#{out}</span>}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
61
85
|
class VariantInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
62
86
|
use_dsl
|
63
87
|
named :lang
|
@@ -111,17 +135,33 @@ module Metanorma
|
|
111
135
|
end
|
112
136
|
|
113
137
|
# inject ZWNJ to prevent Asciidoctor from attempting regex substitutions
|
114
|
-
class
|
138
|
+
class PassFormatInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
115
139
|
use_dsl
|
116
140
|
named :"pass-format"
|
117
141
|
parse_content_as :text
|
118
142
|
|
119
143
|
def process(parent, target, attrs)
|
120
|
-
#require "debug"; binding.b
|
121
144
|
format = target || "metanorma"
|
122
145
|
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
123
|
-
|
124
|
-
|
146
|
+
<<~XML
|
147
|
+
<passthrough-inline formats="#{format}">#{xml_process(out)}</passthrough-inline>
|
148
|
+
XML
|
149
|
+
end
|
150
|
+
|
151
|
+
# Split content into XML tags (including XML-escaped instances),
|
152
|
+
# XML escapes, and text segments
|
153
|
+
# Then only apply ZWNJ to punctuation in text segments
|
154
|
+
def xml_process(out)
|
155
|
+
processed_out = ""
|
156
|
+
segments = out.split(/(<[^>]*>|<[^&]*>|&[^;]*;)/)
|
157
|
+
segments.each_with_index do |segment, index|
|
158
|
+
processed_out += if index.even? # Text segment (not a tag or escape)
|
159
|
+
segment.gsub(/([[:punct:]])/, "\\1‌")
|
160
|
+
else # XML tag or escape
|
161
|
+
segment
|
162
|
+
end
|
163
|
+
end
|
164
|
+
processed_out
|
125
165
|
end
|
126
166
|
end
|
127
167
|
|
@@ -76,5 +76,14 @@ module Metanorma
|
|
76
76
|
create_anchor(parent, "hidden=#{t}", type: :xref, target: target)
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
class SourceIncludeInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
81
|
+
use_dsl
|
82
|
+
named :source_include
|
83
|
+
|
84
|
+
def process(_parent, target, _attrs)
|
85
|
+
"<source-include path='#{target}'/>"
|
86
|
+
end
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
@@ -15,8 +15,13 @@ module Metanorma
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.run(umlfile, outfile)
|
19
|
-
|
18
|
+
def self.run(umlfile, outfile, fmt)
|
19
|
+
valid_formats = %w[png svg eps]
|
20
|
+
unless valid_formats.include?(fmt)
|
21
|
+
raise ArgumentError, "Invalid format: #{fmt}. Allowed formats are: #{valid_formats.join(', ')}"
|
22
|
+
end
|
23
|
+
system(plantuml_bin, umlfile.path, "-t#{fmt}") or
|
24
|
+
(warn $? and return false)
|
20
25
|
i = 0
|
21
26
|
until !Gem.win_platform? || File.exist?(outfile) || i == 15
|
22
27
|
sleep(1)
|
@@ -34,16 +39,24 @@ module Metanorma
|
|
34
39
|
# Windows Ruby 2.4 will crash if a Tempfile is "mv"ed.
|
35
40
|
# This is why we need to copy and then unlink.
|
36
41
|
def self.generate_file(parent, reader)
|
37
|
-
ldir =
|
38
|
-
|
39
|
-
umlfile, outfile
|
40
|
-
run(umlfile, outfile) or
|
42
|
+
ldir, imagesdir, fmt = generate_file_prep(parent)
|
43
|
+
umlfile, outfile = save_plantuml parent, reader, ldir, fmt
|
44
|
+
run(umlfile, outfile, fmt) or
|
41
45
|
raise "No image output from PlantUML (#{umlfile}, #{outfile})!"
|
42
46
|
umlfile.unlink
|
43
|
-
|
47
|
+
absolute_path, relative_path = path_prep(ldir, imagesdir)
|
44
48
|
filename = File.basename(outfile.to_s)
|
45
|
-
FileUtils.cp(outfile,
|
46
|
-
imagesdir ? filename : File.join(path, filename)
|
49
|
+
FileUtils.cp(outfile, absolute_path) and outfile.unlink
|
50
|
+
#imagesdir ? filename : File.join(path, filename)
|
51
|
+
File.join(relative_path, filename)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.generate_file_prep(parent)
|
55
|
+
ldir = localdir(parent)
|
56
|
+
imagesdir = parent.document.attr("imagesdir")
|
57
|
+
fmt = parent.document.attr("plantuml-image-format")&.strip&.downcase ||
|
58
|
+
"png"
|
59
|
+
[ldir, imagesdir, fmt]
|
47
60
|
end
|
48
61
|
|
49
62
|
def self.localdir(parent)
|
@@ -54,21 +67,22 @@ module Metanorma
|
|
54
67
|
end
|
55
68
|
|
56
69
|
def self.path_prep(localdir, imagesdir)
|
57
|
-
path = Pathname.new(localdir) + (imagesdir || "plantuml")
|
70
|
+
#path = Pathname.new(localdir) + (imagesdir || "plantuml")
|
71
|
+
path = Pathname.new(File.join(localdir, "_plantuml_images"))
|
72
|
+
sourcepath = imagesdir ? File.join(localdir, imagesdir) : localdir
|
58
73
|
path.mkpath
|
59
74
|
File.writable?(path) or
|
60
75
|
raise "Destination path #{path} not writable for PlantUML!"
|
61
|
-
|
62
|
-
path
|
76
|
+
[path, Pathname.new(path).relative_path_from(Pathname.new(sourcepath)).to_s]
|
63
77
|
end
|
64
78
|
|
65
|
-
def self.save_plantuml(_parent, reader, _localdir)
|
79
|
+
def self.save_plantuml(_parent, reader, _localdir, fmt)
|
66
80
|
src = prep_source(reader)
|
67
81
|
/^@startuml (?<fn>[^\n]+)\n/ =~ src
|
68
82
|
Tempfile.open(["plantuml", ".pml"], encoding: "utf-8") do |f|
|
69
83
|
f.write(src)
|
70
84
|
[f, File.join(File.dirname(f.path),
|
71
|
-
"#{fn || File.basename(f.path, '.pml')}
|
85
|
+
"#{fn || File.basename(f.path, '.pml')}.#{fmt}")]
|
72
86
|
end
|
73
87
|
end
|
74
88
|
|
@@ -14,7 +14,7 @@ module Metanorma
|
|
14
14
|
@biblio = true
|
15
15
|
attrs = attrs.merge(normative: node.attr("normative") || false)
|
16
16
|
xml.references **attr_code(attrs) do |xml_section|
|
17
|
-
xml_section
|
17
|
+
section_title(xml_section, node.title)
|
18
18
|
xml_section << node.content
|
19
19
|
end
|
20
20
|
@biblio = false
|
@@ -36,7 +36,7 @@ module Metanorma
|
|
36
36
|
@norm_ref = true
|
37
37
|
attrs = attrs.merge(normative: node.attr("normative") || true)
|
38
38
|
xml.references **attr_code(attrs) do |xml_section|
|
39
|
-
xml_section
|
39
|
+
section_title(xml_section, node.title)
|
40
40
|
xml_section << node.content
|
41
41
|
end
|
42
42
|
@norm_ref = false
|
@@ -2,8 +2,7 @@ module Metanorma
|
|
2
2
|
module Standoc
|
3
3
|
module Base
|
4
4
|
def html_extract_attributes(node)
|
5
|
-
i18nyaml = node
|
6
|
-
i18nyaml &&= File.join(@localdir, i18nyaml)
|
5
|
+
i18nyaml = i18nyaml_path(node)
|
7
6
|
{
|
8
7
|
script: node.attr("script"),
|
9
8
|
bodyfont: node.attr("body-font"),
|
@@ -11,10 +10,10 @@ module Metanorma
|
|
11
10
|
monospacefont: node.attr("monospace-font"),
|
12
11
|
i18nyaml: i18nyaml,
|
13
12
|
scope: node.attr("scope"),
|
14
|
-
htmlstylesheet: node.attr("htmlstylesheet"),
|
15
|
-
htmlstylesheet_override: node.attr("htmlstylesheet-override"),
|
16
|
-
htmlcoverpage: node.attr("htmlcoverpage"),
|
17
|
-
htmlintropage: node.attr("htmlintropage"),
|
13
|
+
htmlstylesheet: node.attr("htmlstylesheet") || node.attr("html-stylesheet"),
|
14
|
+
htmlstylesheet_override: node.attr("htmlstylesheet-override") || node.attr("html-stylesheet-override"),
|
15
|
+
htmlcoverpage: node.attr("htmlcoverpage") || node.attr("htmlcoverpage"),
|
16
|
+
htmlintropage: node.attr("htmlintropage") || node.attr("html-intropage"),
|
18
17
|
scripts: node.attr("scripts"),
|
19
18
|
scripts_override: node.attr("scripts-override"),
|
20
19
|
scripts_pdf: node.attr("scripts-pdf"),
|
@@ -50,8 +49,7 @@ module Metanorma
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def doc_extract_attributes(node)
|
53
|
-
i18nyaml = node
|
54
|
-
i18nyaml &&= File.join(@localdir, i18nyaml)
|
52
|
+
i18nyaml = i18nyaml_path(node)
|
55
53
|
attrs = {
|
56
54
|
script: node.attr("script"),
|
57
55
|
bodyfont: node.attr("body-font"),
|
@@ -59,9 +57,9 @@ module Metanorma
|
|
59
57
|
monospacefont: node.attr("monospace-font"),
|
60
58
|
i18nyaml: i18nyaml,
|
61
59
|
scope: node.attr("scope"),
|
62
|
-
wordstylesheet: node.attr("wordstylesheet"),
|
63
|
-
wordstylesheet_override: node.attr("wordstylesheet-override"),
|
64
|
-
standardstylesheet: node.attr("standardstylesheet"),
|
60
|
+
wordstylesheet: node.attr("wordstylesheet") || node.attr("word-stylesheet"),
|
61
|
+
wordstylesheet_override: node.attr("wordstylesheet-override") || node.attr("word-stylesheet-override"),
|
62
|
+
standardstylesheet: node.attr("standardstylesheet") || node.attr("standard-stylesheet"),
|
65
63
|
header: node.attr("header"),
|
66
64
|
wordcoverpage: node.attr("wordcoverpage"),
|
67
65
|
wordintropage: node.attr("wordintropage"),
|
@@ -96,13 +94,24 @@ module Metanorma
|
|
96
94
|
pdf-allow-assemble-document pdf-allow-edit-annotations
|
97
95
|
pdf-allow-print pdf-allow-print-hq
|
98
96
|
pdf-allow-access-content pdf-encrypt-metadata fonts
|
97
|
+
pdf-stylesheet pdf-stylesheet-override
|
99
98
|
font-license-agreement).each_with_object({}) do |x, m|
|
100
|
-
m[x.delete("-").
|
99
|
+
m[x.delete("-").sub(/override$/, "_override").to_sym] =
|
100
|
+
node.attr(x) || node.attr(x.sub("pdf-", "pdf"))
|
101
101
|
end
|
102
|
-
|
102
|
+
absolute_path_pdf_attributes(pdf_options)
|
103
103
|
pdf_options.merge(fonts_manifest_option(node) || {})
|
104
104
|
end
|
105
105
|
|
106
|
+
def absolute_path_pdf_attributes(pdf_options)
|
107
|
+
%i(pdfstylesheet pdfstylesheet_override).each do |x|
|
108
|
+
pdf_options[x] or next
|
109
|
+
(Pathname.new pdf_options[x]).absolute? or
|
110
|
+
pdf_options[x] =
|
111
|
+
File.join(File.expand_path(@localdir), pdf_options[x])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
106
115
|
def doc_converter(node)
|
107
116
|
IsoDoc::WordConvert.new(doc_extract_attributes(node))
|
108
117
|
end
|
@@ -35,8 +35,8 @@ module Metanorma
|
|
35
35
|
a = section_attributes(node)
|
36
36
|
noko do |xml|
|
37
37
|
case sectiontype(node)
|
38
|
-
when "
|
39
|
-
|
38
|
+
when "metanorma-extension"
|
39
|
+
metanorma_extension_parse(a, xml, node)
|
40
40
|
when "introduction" then introduction_parse(a, xml, node)
|
41
41
|
when "foreword" then foreword_parse(a, xml, node)
|
42
42
|
when "scope" then scope_parse(a, xml, node)
|
@@ -85,26 +85,31 @@ module Metanorma
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
def section_title(xml, title)
|
89
|
+
title.nil? and return
|
90
|
+
xml.title **attr_code(id_attr(nil)) do |t|
|
91
|
+
t << title
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
88
95
|
def preamble(node)
|
89
96
|
noko do |xml|
|
90
97
|
xml.foreword **attr_code(section_attributes(node)) do |xml_abstract|
|
91
|
-
xml_abstract.title
|
92
|
-
t << (node.blocks[0].title || @i18n.foreword)
|
93
|
-
end
|
98
|
+
section_title(xml_abstract, node.blocks[0].title || @i18n.foreword)
|
94
99
|
xml_abstract << node.content
|
95
100
|
end
|
96
101
|
end
|
97
102
|
end
|
98
103
|
|
99
|
-
def
|
100
|
-
xml.send :"
|
104
|
+
def metanorma_extension_parse(_attrs, xml, node)
|
105
|
+
xml.send :"metanorma-extension-clause" do |xml_section|
|
101
106
|
xml_section << node.content
|
102
107
|
end
|
103
108
|
end
|
104
109
|
|
105
110
|
def indexsect_parse(attrs, xml, node)
|
106
111
|
xml.indexsect **attr_code(attrs) do |xml_section|
|
107
|
-
xml_section
|
112
|
+
section_title(xml_section, node.title)
|
108
113
|
xml_section << node.content
|
109
114
|
end
|
110
115
|
end
|
@@ -131,7 +136,7 @@ module Metanorma
|
|
131
136
|
node.option?("appendix") && support_appendix?(node) and
|
132
137
|
return appendix_parse(attrs, xml, node)
|
133
138
|
xml.send :clause, **attr_code(attrs) do |xml_section|
|
134
|
-
xml_section
|
139
|
+
section_title(xml_section, node.title)
|
135
140
|
xml_section << node.content
|
136
141
|
end
|
137
142
|
end
|
@@ -144,7 +149,7 @@ module Metanorma
|
|
144
149
|
def annex_parse(attrs, xml, node)
|
145
150
|
annex_attrs_preprocess(attrs, node)
|
146
151
|
xml.annex **attr_code(attrs) do |xml_section|
|
147
|
-
xml_section
|
152
|
+
section_title(xml_section, node.title)
|
148
153
|
xml_section << node.content
|
149
154
|
end
|
150
155
|
end
|
@@ -157,35 +162,35 @@ module Metanorma
|
|
157
162
|
attrs[:"inline-header"] = node.option? "inline-header"
|
158
163
|
set_obligation(attrs, node)
|
159
164
|
xml.appendix **attr_code(attrs) do |xml_section|
|
160
|
-
xml_section
|
165
|
+
section_title(xml_section, node.title)
|
161
166
|
xml_section << node.content
|
162
167
|
end
|
163
168
|
end
|
164
169
|
|
165
170
|
def introduction_parse(attrs, xml, node)
|
166
171
|
xml.introduction **attr_code(attrs) do |xml_section|
|
167
|
-
xml_section
|
172
|
+
section_title(xml_section, @i18n.introduction)
|
168
173
|
xml_section << node.content
|
169
174
|
end
|
170
175
|
end
|
171
176
|
|
172
177
|
def foreword_parse(attrs, xml, node)
|
173
178
|
xml.foreword **attr_code(attrs) do |xml_section|
|
174
|
-
xml_section
|
179
|
+
section_title(xml_section, node.title)
|
175
180
|
xml_section << node.content
|
176
181
|
end
|
177
182
|
end
|
178
183
|
|
179
184
|
def acknowledgements_parse(attrs, xml, node)
|
180
185
|
xml.acknowledgements **attr_code(attrs) do |xml_section|
|
181
|
-
xml_section
|
186
|
+
section_title(xml_section, node.title || @i18n.acknowledgements)
|
182
187
|
xml_section << node.content
|
183
188
|
end
|
184
189
|
end
|
185
190
|
|
186
191
|
def executivesummary_parse(attrs, xml, node)
|
187
192
|
xml.executivesummary **attr_code(attrs) do |xml_section|
|
188
|
-
xml_section
|
193
|
+
section_title(xml_section, node.title || @i18n.executivesummary)
|
189
194
|
xml_section << node.content
|
190
195
|
end
|
191
196
|
end
|
@@ -14,7 +14,9 @@ module Metanorma
|
|
14
14
|
def sectiontype(node, level = true)
|
15
15
|
ret = sectiontype1(node)
|
16
16
|
ret1 = preface_main_filter(sectiontype_streamline(ret), node)
|
17
|
-
|
17
|
+
# permit multiple instances
|
18
|
+
["symbols and abbreviated terms",
|
19
|
+
"metanorma-extension"].include?(ret1) and return ret1
|
18
20
|
!level || node.level == 1 || node.attr("heading") or return nil
|
19
21
|
!node.attr("heading") && @seen_headers.include?(ret) and return nil
|
20
22
|
@seen_headers << ret unless ret1.nil?
|
@@ -22,31 +24,37 @@ module Metanorma
|
|
22
24
|
ret1
|
23
25
|
end
|
24
26
|
|
27
|
+
SECTIONTYPE_STREAMLINE =
|
28
|
+
{ "terms and definitions":
|
29
|
+
["terms, definitions, symbols and abbreviated terms",
|
30
|
+
"terms, definitions, symbols and abbreviations",
|
31
|
+
"terms, definitions and symbols",
|
32
|
+
"terms, definitions and abbreviations",
|
33
|
+
"terms, definitions and abbreviated terms",
|
34
|
+
"terms and definitions"],
|
35
|
+
"symbols and abbreviated terms":
|
36
|
+
["symbols and abbreviated terms",
|
37
|
+
"symbols", "abbreviated terms", "abbreviations",
|
38
|
+
"symbols and abbreviations",
|
39
|
+
"symbols and abbreviated terms"],
|
40
|
+
"acknowledgements":
|
41
|
+
["acknowledgements", "acknowledgments"],
|
42
|
+
"executivesummary":
|
43
|
+
["executive summary", "executive-summary",
|
44
|
+
"executive_summary"],
|
45
|
+
"metanorma-extension":
|
46
|
+
["misc-container", "metanorma-extension"] }.freeze
|
47
|
+
|
25
48
|
def sectiontype_streamline(ret)
|
26
|
-
|
27
|
-
|
28
|
-
"terms, definitions, symbols and abbreviated terms",
|
29
|
-
"terms, definitions, symbols and abbreviations",
|
30
|
-
"terms, definitions and symbols",
|
31
|
-
"terms, definitions and abbreviations",
|
32
|
-
"terms, definitions and abbreviated terms"
|
33
|
-
"terms and definitions"
|
34
|
-
when "symbols and abbreviated terms",
|
35
|
-
"symbols", "abbreviated terms", "abbreviations",
|
36
|
-
"symbols and abbreviations"
|
37
|
-
"symbols and abbreviated terms"
|
38
|
-
when "acknowledgements", "acknowledgments"
|
39
|
-
"acknowledgements"
|
40
|
-
when "executive summary", "executive-summary", "executive_summary"
|
41
|
-
"executivesummary"
|
42
|
-
else
|
43
|
-
ret
|
49
|
+
SECTIONTYPE_STREAMLINE.each do |k, v|
|
50
|
+
v.include?(ret) and return k.to_s
|
44
51
|
end
|
52
|
+
ret
|
45
53
|
end
|
46
54
|
|
47
55
|
PREFACE_CLAUSE_NAMES =
|
48
56
|
%w(abstract foreword introduction metanorma-extension termdocsource
|
49
|
-
|
57
|
+
metanorma-extension acknowledgements executivesummary)
|
50
58
|
.freeze
|
51
59
|
|
52
60
|
MAIN_CLAUSE_NAMES =
|
@@ -36,11 +36,7 @@ module Metanorma
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def table_name(node, xml_table)
|
39
|
-
|
40
|
-
xml_table.name do |n|
|
41
|
-
n << node.title
|
42
|
-
end
|
43
|
-
end
|
39
|
+
block_title(node, xml_table)
|
44
40
|
end
|
45
41
|
|
46
42
|
def table_cell1(cell)
|
@@ -67,7 +63,7 @@ module Metanorma
|
|
67
63
|
%i(head body foot).reject { |s| node.rows[s].empty? }.each do |s|
|
68
64
|
xml.send "t#{s}" do |xml_tblsec|
|
69
65
|
node.rows[s].each do |row|
|
70
|
-
xml_tblsec.tr do |xml_tr|
|
66
|
+
xml_tblsec.tr **attr_code(id_attr(nil)) do |xml_tr|
|
71
67
|
row.each { |cell| table_cell(cell, xml_tr, s) }
|
72
68
|
end
|
73
69
|
end
|
@@ -16,13 +16,11 @@ module Metanorma
|
|
16
16
|
@unique_designs = {}
|
17
17
|
@c = HTMLEntities.new
|
18
18
|
@terms_tags = xmldoc.xpath("//terms").each_with_object({}) do |t, m|
|
19
|
-
#m[t["id"]] = true
|
20
19
|
m[t["anchor"]] = true
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
23
|
def call
|
25
|
-
#require "debug"; binding.b
|
26
24
|
@idhash = populate_idhash
|
27
25
|
@unique_designs = unique_designators
|
28
26
|
@lookup = replace_automatic_generated_ids_terms
|
@@ -72,11 +70,8 @@ module Metanorma
|
|
72
70
|
end
|
73
71
|
|
74
72
|
def populate_idhash
|
75
|
-
#xmldoc.xpath("//*[@id]").each_with_object({}) do |n, mem|
|
76
73
|
xmldoc.xpath("//*[@anchor]").each_with_object({}) do |n, mem|
|
77
|
-
#/^(term|symbol)-/.match?(n["id"]) or next
|
78
74
|
/^(term|symbol)-/.match?(n["anchor"]) or next
|
79
|
-
#mem[n["id"]] = true
|
80
75
|
mem[n["anchor"]] = true
|
81
76
|
end
|
82
77
|
end
|
@@ -213,21 +208,17 @@ module Metanorma
|
|
213
208
|
|
214
209
|
def norm_id_memorize_init(node, res_table, selector, prefix, use_domain)
|
215
210
|
term_text = norm_ref_id(node, selector, use_domain) or return
|
216
|
-
#unless AUTO_GEN_ID_REGEXP.match(node["id"]).nil? && !node["id"].nil?
|
217
211
|
unless AUTO_GEN_ID_REGEXP.match(node["anchor"]).nil? && !node["anchor"].nil?
|
218
212
|
id = unique_text_id(term_text, prefix)
|
219
|
-
#node["id"] = id
|
220
213
|
node["anchor"] = id
|
221
214
|
@idhash[id] = true
|
222
215
|
end
|
223
|
-
#res_table[term_text] = node["id"]
|
224
216
|
res_table[term_text] = node["anchor"]
|
225
217
|
end
|
226
218
|
|
227
219
|
def memorize_other_pref_terms(node, res_table, text_selector, use_domain)
|
228
220
|
node.xpath(text_selector).each_with_index do |p, i|
|
229
221
|
i.positive? or next
|
230
|
-
#res_table[norm_ref_id1(p, use_domain ? node : nil)] = node["id"]
|
231
222
|
res_table[norm_ref_id1(p, use_domain ? node : nil)] = node["anchor"]
|
232
223
|
end
|
233
224
|
end
|
@@ -24,7 +24,7 @@ module Metanorma
|
|
24
24
|
def symbols_parse(attr, xml, node)
|
25
25
|
node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
|
26
26
|
xml.definitions **attr_code(attr) do |xml_section|
|
27
|
-
xml_section
|
27
|
+
section_title(xml_section, node.title)
|
28
28
|
stash_symbols
|
29
29
|
@definitions = true
|
30
30
|
stash_term_def
|
@@ -98,7 +98,7 @@ module Metanorma
|
|
98
98
|
|
99
99
|
def term_def_parse(attrs, xml, node, _toplevel)
|
100
100
|
xml.terms **attr_code(attrs) do |section|
|
101
|
-
section
|
101
|
+
section_title(section, node.title)
|
102
102
|
(s = node.attr("source")) && s.split(",").each do |s1|
|
103
103
|
section.termdocsource(nil, **attr_code(bibitemid: s1))
|
104
104
|
end
|
@@ -166,7 +166,8 @@ module Metanorma
|
|
166
166
|
|
167
167
|
def termdefinition(node)
|
168
168
|
noko do |xml|
|
169
|
-
xml.definition **attr_code(
|
169
|
+
xml.definition **attr_code(id_attr(nil)
|
170
|
+
.merge(type: node.attr("type"))) do |d|
|
170
171
|
d << node.content
|
171
172
|
end
|
172
173
|
end
|
@@ -39,6 +39,10 @@ module Metanorma
|
|
39
39
|
node["id"] = "_#{UUIDTools::UUID.random_create}"
|
40
40
|
end
|
41
41
|
|
42
|
+
def add_id_text
|
43
|
+
%(id = "_#{UUIDTools::UUID.random_create}")
|
44
|
+
end
|
45
|
+
|
42
46
|
def csv_split(text, delim = ";")
|
43
47
|
Metanorma::Utils::csv_split(@c.decode(text), delim)
|
44
48
|
.map { |x| @c.encode(x, :basic, :hexadecimal) }
|
data/metanorma-standoc.gemspec
CHANGED
@@ -34,9 +34,8 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_dependency "iev", "~> 0.3.5"
|
35
35
|
spec.add_dependency "isodoc", "~> 3.1.4"
|
36
36
|
spec.add_dependency "metanorma", ">= 1.6.0"
|
37
|
-
spec.add_dependency "metanorma-plugin-datastruct", "~> 0.3.0"
|
38
37
|
spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.3"
|
39
|
-
spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.
|
38
|
+
spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.31"
|
40
39
|
spec.add_dependency "metanorma-utils", "~> 1.11.0"
|
41
40
|
spec.add_dependency "ruby-jing"
|
42
41
|
# relaton-cli not just relaton, to avoid circular reference in metanorma
|