isodoc 1.7.5 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +8 -7
- data/lib/isodoc/class_utils.rb +25 -2
- data/lib/isodoc/convert.rb +2 -0
- data/lib/isodoc/function/cleanup.rb +4 -0
- data/lib/isodoc/function/to_word_html.rb +2 -1
- data/lib/isodoc/function/utils.rb +34 -14
- data/lib/isodoc/html_function/comments.rb +107 -111
- data/lib/isodoc/html_function/footnotes.rb +68 -67
- data/lib/isodoc/html_function/html.rb +113 -103
- data/lib/isodoc/presentation_function/block.rb +1 -69
- data/lib/isodoc/presentation_function/image.rb +112 -0
- data/lib/isodoc/presentation_function/inline.rb +16 -78
- data/lib/isodoc/presentation_function/terms.rb +179 -0
- data/lib/isodoc/presentation_xml_convert.rb +11 -4
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +176 -174
- data/lib/isodoc/word_function/comments.rb +117 -112
- data/lib/isodoc/word_function/footnotes.rb +88 -86
- data/lib/isodoc/word_function/inline.rb +42 -67
- data/lib/isodoc/word_function/postprocess.rb +184 -176
- data/lib/isodoc/word_function/postprocess_cover.rb +121 -110
- data/lib/isodoc/xref/xref_gen.rb +153 -150
- data/lib/isodoc/xref/xref_sect_gen.rb +134 -129
- data/lib/isodoc/xslfo_convert.rb +11 -7
- data/lib/isodoc-yaml/i18n-ar.yaml +22 -0
- data/lib/isodoc-yaml/i18n-de.yaml +20 -0
- data/lib/isodoc-yaml/i18n-en.yaml +20 -0
- data/lib/isodoc-yaml/i18n-es.yaml +20 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +20 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +21 -1
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +21 -0
- data/lib/metanorma/output/xslfo.rb +4 -11
- data/spec/assets/i18n.yaml +3 -1
- data/spec/assets/odf.svg +1 -4
- data/spec/isodoc/blocks_spec.rb +229 -157
- data/spec/isodoc/i18n_spec.rb +8 -8
- data/spec/isodoc/inline_spec.rb +285 -32
- data/spec/isodoc/postproc_spec.rb +38 -0
- data/spec/isodoc/presentation_xml_spec.rb +60 -0
- data/spec/isodoc/section_spec.rb +11 -10
- data/spec/isodoc/terms_spec.rb +354 -34
- data/spec/isodoc/xref_spec.rb +4 -4
- data/spec/isodoc/xslfo_convert_spec.rb +34 -9
- metadata +49 -33
@@ -1,129 +1,139 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "base64"
|
3
3
|
|
4
|
-
module IsoDoc
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
module IsoDoc
|
5
|
+
module HtmlFunction
|
6
|
+
module Html
|
7
|
+
def convert1(docxml, filename, dir)
|
8
|
+
noko do |xml|
|
9
|
+
xml.html **{ lang: @lang.to_s } do |html|
|
10
|
+
info docxml, nil
|
11
|
+
populate_css
|
12
|
+
html.head { |head| define_head head, filename, dir }
|
13
|
+
make_body(html, docxml)
|
14
|
+
end
|
15
|
+
end.join("\n")
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
def make_body1(body, _docxml)
|
19
|
+
return if @bare
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
body.div **{ class: "title-section" } do |div1|
|
22
|
+
div1.p { |p| p << " " } # placeholder
|
23
|
+
end
|
24
|
+
section_break(body)
|
22
25
|
end
|
23
|
-
section_break(body)
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
def make_body2(body, _docxml)
|
28
|
+
return if @bare
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
body.div **{ class: "prefatory-section" } do |div2|
|
31
|
+
div2.p { |p| p << " " } # placeholder
|
32
|
+
end
|
33
|
+
section_break(body)
|
31
34
|
end
|
32
|
-
section_break(body)
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
def make_body3(body, docxml)
|
37
|
+
body.div **{ class: "main-section" } do |div3|
|
38
|
+
boilerplate docxml, div3
|
39
|
+
preface_block docxml, div3
|
40
|
+
abstract docxml, div3
|
41
|
+
foreword docxml, div3
|
42
|
+
introduction docxml, div3
|
43
|
+
preface docxml, div3
|
44
|
+
acknowledgements docxml, div3
|
45
|
+
middle docxml, div3
|
46
|
+
footnotes div3
|
47
|
+
comments div3
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def googlefonts
|
52
|
+
<<~HEAD.freeze
|
53
|
+
<link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
|
54
|
+
<link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
|
55
|
+
HEAD
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
58
|
+
def html_head
|
59
|
+
<<~HEAD.freeze
|
60
|
+
<title>#{@meta&.get&.dig(:doctitle)}</title>
|
61
|
+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
62
|
+
|
63
|
+
<!--TOC script import-->
|
64
|
+
<script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
|
65
|
+
<script type="text/javascript">#{toclevel}</script>
|
66
|
+
|
67
|
+
<!--Google fonts-->
|
68
|
+
<link rel="preconnect" href="https://fonts.gstatic.com">#{' '}
|
69
|
+
#{googlefonts}
|
70
|
+
<!--Font awesome import for the link icon-->
|
71
|
+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
|
72
|
+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
|
73
|
+
<style class="anchorjs"></style>
|
74
|
+
HEAD
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
def html_button
|
78
|
+
return "" if @bare
|
78
79
|
|
79
|
-
|
80
|
+
'<button onclick="topFunction()" id="myBtn" '\
|
80
81
|
'title="Go to top">Top</button>'.freeze
|
81
|
-
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
def html_main(docxml)
|
85
|
+
docxml.at("//head").add_child(html_head)
|
86
|
+
d = docxml.at('//div[@class="main-section"]')
|
87
|
+
d.name = "main"
|
88
|
+
d.children.empty? or d.children.first.previous = html_button
|
89
|
+
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
91
|
+
def sourcecodelang(lang)
|
92
|
+
return unless lang
|
93
|
+
|
94
|
+
case lang.downcase
|
95
|
+
when "javascript" then "lang-js"
|
96
|
+
when "c" then "lang-c"
|
97
|
+
when "c+" then "lang-cpp"
|
98
|
+
when "console" then "lang-bsh"
|
99
|
+
when "ruby" then "lang-rb"
|
100
|
+
when "html" then "lang-html"
|
101
|
+
when "java" then "lang-java"
|
102
|
+
when "xml" then "lang-xml"
|
103
|
+
when "perl" then "lang-perl"
|
104
|
+
when "python" then "lang-py"
|
105
|
+
when "xsl" then "lang-xsl"
|
106
|
+
else
|
107
|
+
""
|
108
|
+
end
|
107
109
|
end
|
108
|
-
end
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
111
|
+
def sourcecode_parse(node, out)
|
112
|
+
name = node.at(ns("./name"))
|
113
|
+
class1 = "prettyprint #{sourcecodelang(node&.at(ns('./@lang'))&.value)}"
|
114
|
+
out.pre **sourcecode_attrs(node).merge(class: class1) do |div|
|
115
|
+
@sourcecode = true
|
116
|
+
node.children.each { |n| parse(n, div) unless n.name == "name" }
|
117
|
+
@sourcecode = false
|
118
|
+
end
|
119
|
+
sourcecode_name_parse(node, out, name)
|
117
120
|
end
|
118
|
-
sourcecode_name_parse(node, out, name)
|
119
|
-
end
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
122
|
+
def underline_parse(node, out)
|
123
|
+
out.span **{ style: "text-decoration: underline;" } do |e|
|
124
|
+
node.children.each { |n| parse(n, e) }
|
125
|
+
end
|
124
126
|
end
|
125
|
-
end
|
126
127
|
|
127
|
-
|
128
|
+
def table_long_strings_cleanup(docxml); end
|
129
|
+
|
130
|
+
def image_parse(node, out, caption)
|
131
|
+
if svg = node.at("./m:svg", "m" => "http://www.w3.org/2000/svg")
|
132
|
+
svg_parse(svg, out)
|
133
|
+
return
|
134
|
+
end
|
135
|
+
super
|
136
|
+
end
|
137
|
+
end
|
128
138
|
end
|
129
139
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "./image"
|
2
2
|
|
3
3
|
module IsoDoc
|
4
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
@@ -8,38 +8,6 @@ module IsoDoc
|
|
8
8
|
text.capitalize
|
9
9
|
end
|
10
10
|
|
11
|
-
def figure(docxml)
|
12
|
-
docxml.xpath(ns("//image")).each { |f| svg_extract(f) }
|
13
|
-
docxml.xpath(ns("//figure")).each { |f| figure1(f) }
|
14
|
-
docxml.xpath(ns("//svgmap")).each do |s|
|
15
|
-
if f = s.at(ns("./figure")) then s.replace(f)
|
16
|
-
else s.remove
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def svg_extract(elem)
|
22
|
-
return unless %r{^data:image/svg\+xml;base64,}.match?(elem["src"])
|
23
|
-
|
24
|
-
svg = Base64.strict_decode64(elem["src"]
|
25
|
-
.sub(%r{^data:image/svg\+xml;base64,}, ""))
|
26
|
-
x = Nokogiri::XML.fragment(svg.sub(/<\?xml[^>]*>/, "")) do |config|
|
27
|
-
config.huge
|
28
|
-
end
|
29
|
-
elem.replace(x)
|
30
|
-
end
|
31
|
-
|
32
|
-
def figure1(elem)
|
33
|
-
return sourcecode1(elem) if elem["class"] == "pseudocode" ||
|
34
|
-
elem["type"] == "pseudocode"
|
35
|
-
return if labelled_ancestor(elem) && elem.ancestors("figure").empty? ||
|
36
|
-
elem.at(ns("./figure")) && !elem.at(ns("./name"))
|
37
|
-
|
38
|
-
lbl = @xrefs.anchor(elem["id"], :label, false) or return
|
39
|
-
prefix_name(elem, " — ",
|
40
|
-
l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
41
|
-
end
|
42
|
-
|
43
11
|
def prefix_name(node, delim, number, elem)
|
44
12
|
return if number.nil? || number.empty?
|
45
13
|
|
@@ -86,12 +54,6 @@ module IsoDoc
|
|
86
54
|
end
|
87
55
|
end
|
88
56
|
|
89
|
-
def termexample(docxml)
|
90
|
-
docxml.xpath(ns("//termexample")).each do |f|
|
91
|
-
example1(f)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
57
|
def example1(elem)
|
96
58
|
n = @xrefs.get[elem["id"]]
|
97
59
|
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
|
@@ -121,36 +83,6 @@ module IsoDoc
|
|
121
83
|
prefix_name(elem, "", lbl, "name")
|
122
84
|
end
|
123
85
|
|
124
|
-
def termnote(docxml)
|
125
|
-
docxml.xpath(ns("//termnote")).each do |f|
|
126
|
-
termnote1(f)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
# introduce name element
|
131
|
-
def termnote1(elem)
|
132
|
-
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
|
133
|
-
prefix_name(elem, "", lower2cap(lbl), "name")
|
134
|
-
end
|
135
|
-
|
136
|
-
def termdefinition(docxml)
|
137
|
-
docxml.xpath(ns("//term[definition]")).each do |f|
|
138
|
-
termdefinition1(f)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def termdefinition1(elem)
|
143
|
-
return unless elem.xpath(ns("./definition")).size > 1
|
144
|
-
|
145
|
-
d = elem.at(ns("./definition"))
|
146
|
-
d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
|
147
|
-
elem.xpath(ns("./definition")).each do |f|
|
148
|
-
f = f.replace("<li>#{f.children.to_xml}</li>").first
|
149
|
-
d << f
|
150
|
-
end
|
151
|
-
d.wrap("<definition></definition>")
|
152
|
-
end
|
153
|
-
|
154
86
|
def recommendation(docxml)
|
155
87
|
docxml.xpath(ns("//recommendation")).each do |f|
|
156
88
|
recommendation1(f, lower2cap(@i18n.recommendation))
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "emf2svg"
|
3
|
+
|
4
|
+
module IsoDoc
|
5
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
6
|
+
def figure(docxml)
|
7
|
+
docxml.xpath(ns("//image")).each { |f| svg_extract(f) }
|
8
|
+
docxml.xpath(ns("//figure")).each { |f| figure1(f) }
|
9
|
+
docxml.xpath(ns("//svgmap")).each do |s|
|
10
|
+
if f = s.at(ns("./figure")) then s.replace(f)
|
11
|
+
else s.remove
|
12
|
+
end
|
13
|
+
end
|
14
|
+
docxml.xpath(ns("//image")).each { |f| svg_emf_double(f) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def svg_extract(elem)
|
18
|
+
return unless %r{^data:image/svg\+xml;}.match?(elem["src"])
|
19
|
+
|
20
|
+
svg = Base64.strict_decode64(elem["src"]
|
21
|
+
.sub(%r{^data:image/svg\+xml;(charset=[^;]+;)?base64,}, ""))
|
22
|
+
x = Nokogiri::XML.fragment(svg.sub(/<\?xml[^>]*>/, "")) do |config|
|
23
|
+
config.huge
|
24
|
+
end
|
25
|
+
elem["src"] = ""
|
26
|
+
elem.children = x
|
27
|
+
end
|
28
|
+
|
29
|
+
def figure1(elem)
|
30
|
+
return sourcecode1(elem) if elem["class"] == "pseudocode" ||
|
31
|
+
elem["type"] == "pseudocode"
|
32
|
+
return if labelled_ancestor(elem) && elem.ancestors("figure").empty? ||
|
33
|
+
elem.at(ns("./figure")) && !elem.at(ns("./name"))
|
34
|
+
|
35
|
+
lbl = @xrefs.anchor(elem["id"], :label, false) or return
|
36
|
+
prefix_name(elem, " — ",
|
37
|
+
l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
38
|
+
end
|
39
|
+
|
40
|
+
def svg_emf_double(img)
|
41
|
+
if emf?(img["mimetype"])
|
42
|
+
img = emf_encode(img)
|
43
|
+
img.children.first.previous = emf_to_svg(img)
|
44
|
+
elsif img["mimetype"] == "image/svg+xml"
|
45
|
+
src = svg_to_emf(img) and img << "<emf src='#{src}'/>"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def emf_encode(img)
|
50
|
+
img["mimetype"] = "image/svg+xml"
|
51
|
+
unless %r{^data:image}.match?(img["src"])
|
52
|
+
img["src"] = Metanorma::Utils::datauri(img["src"])
|
53
|
+
end
|
54
|
+
img.children = "<emf src='#{img['src']}'/>"
|
55
|
+
img["src"] = ""
|
56
|
+
img
|
57
|
+
end
|
58
|
+
|
59
|
+
def emf_to_svg(img)
|
60
|
+
emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
|
61
|
+
Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
|
62
|
+
end
|
63
|
+
|
64
|
+
def svg_to_emf(node)
|
65
|
+
uri = svg_to_emf_uri(node)
|
66
|
+
ret = svg_to_emf_filename(uri)
|
67
|
+
File.exists?(ret) and return ret
|
68
|
+
exe = inkscape_installed? or return nil
|
69
|
+
uri = Metanorma::Utils::external_path uri
|
70
|
+
exe = Metanorma::Utils::external_path exe
|
71
|
+
system(%(#{exe} --export-type="emf" #{uri})) and
|
72
|
+
return Metanorma::Utils::datauri(ret)
|
73
|
+
|
74
|
+
warn %(Fail on #{exe} --export-type="emf" #{uri})
|
75
|
+
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def svg_to_emf_uri(node)
|
80
|
+
uri = if node&.elements&.first&.name == "svg"
|
81
|
+
a = Base64.strict_encode64(node.children.to_xml)
|
82
|
+
"data:image/svg+xml;base64,#{a}"
|
83
|
+
else node["src"]
|
84
|
+
end
|
85
|
+
if %r{^data:}.match?(uri)
|
86
|
+
uri = save_dataimage(uri)
|
87
|
+
@tempfile_cache << uri
|
88
|
+
end
|
89
|
+
uri
|
90
|
+
end
|
91
|
+
|
92
|
+
def svg_to_emf_filename(uri)
|
93
|
+
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.emf"
|
94
|
+
end
|
95
|
+
|
96
|
+
def emf_to_svgfilename(uri)
|
97
|
+
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.svg"
|
98
|
+
end
|
99
|
+
|
100
|
+
def inkscape_installed?
|
101
|
+
cmd = "inkscape"
|
102
|
+
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
|
103
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
104
|
+
exts.each do |ext|
|
105
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
106
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -6,13 +6,16 @@ module IsoDoc
|
|
6
6
|
l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
|
7
7
|
end
|
8
8
|
|
9
|
+
def anchor_value(id)
|
10
|
+
@xrefs.anchor(id, :value) || @xrefs.anchor(id, :label) ||
|
11
|
+
@xrefs.anchor(id, :xref)
|
12
|
+
end
|
13
|
+
|
9
14
|
def anchor_linkend(node, linkend)
|
10
15
|
if node["citeas"].nil? && node["bibitemid"]
|
11
16
|
return @xrefs.anchor(node["bibitemid"], :xref) || "???"
|
12
17
|
elsif node["target"] && node["droploc"]
|
13
|
-
return
|
14
|
-
@xrefs.anchor(node["target"], :label) ||
|
15
|
-
@xrefs.anchor(node["target"], :xref) || "???"
|
18
|
+
return anchor_value(node["target"]) || "???"
|
16
19
|
elsif node["target"] && !/.#./.match(node["target"])
|
17
20
|
linkend = anchor_linkend1(node)
|
18
21
|
end
|
@@ -26,14 +29,15 @@ module IsoDoc
|
|
26
29
|
(container && get_note_container_id(node) != container &&
|
27
30
|
@xrefs.get[node["target"]]) and
|
28
31
|
linkend = prefix_container(container, linkend, node["target"])
|
29
|
-
capitalise_xref(node, linkend)
|
32
|
+
capitalise_xref(node, linkend, anchor_value(node["target"]))
|
30
33
|
end
|
31
34
|
|
32
|
-
def capitalise_xref(node, linkend)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def capitalise_xref(node, linkend, label)
|
36
|
+
linktext = linkend.gsub(/<[^>]+>/, "")
|
37
|
+
(label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
|
38
|
+
linktext[0, 1].match?(/\p{Upper}/) and return linkend
|
39
|
+
node["case"] and
|
40
|
+
return Common::case_with_markup(linkend, node["case"], @script)
|
37
41
|
|
38
42
|
capitalise_xref1(node, linkend)
|
39
43
|
end
|
@@ -42,7 +46,7 @@ module IsoDoc
|
|
42
46
|
prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
|
43
47
|
node.xpath("./preceding::text()")
|
44
48
|
if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
|
45
|
-
linkend
|
49
|
+
Common::case_with_markup(linkend, "capital", @script)
|
46
50
|
else linkend
|
47
51
|
end
|
48
52
|
end
|
@@ -69,7 +73,7 @@ module IsoDoc
|
|
69
73
|
link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
|
70
74
|
link, node)
|
71
75
|
non_locality_elems(node).each(&:remove)
|
72
|
-
node.add_child(link)
|
76
|
+
node.add_child(cleanup_entities(link))
|
73
77
|
end
|
74
78
|
# so not <origin bibitemid="ISO7301" citeas="ISO 7301">
|
75
79
|
# <locality type="section"><reference>3.1</reference></locality></origin>
|
@@ -90,8 +94,7 @@ module IsoDoc
|
|
90
94
|
ret += eref_localities0(rr, j, target, delim, node)
|
91
95
|
delim = ","
|
92
96
|
end
|
93
|
-
else
|
94
|
-
ret += eref_localities0(ref, idx, target, delim, node)
|
97
|
+
else ret += eref_localities0(ref, idx, target, delim, node)
|
95
98
|
end
|
96
99
|
ret
|
97
100
|
end
|
@@ -157,71 +160,6 @@ module IsoDoc
|
|
157
160
|
get_linkend(node)
|
158
161
|
end
|
159
162
|
|
160
|
-
def concept(docxml)
|
161
|
-
docxml.xpath(ns("//concept")).each { |f| concept1(f) }
|
162
|
-
end
|
163
|
-
|
164
|
-
def concept1(node)
|
165
|
-
xref = node&.at(ns("./xref/@target"))&.text or
|
166
|
-
return concept_render(node, ital: node["ital"] || "true",
|
167
|
-
ref: node["ref"] || "true",
|
168
|
-
linkref: node["linkref"] || "true",
|
169
|
-
linkmention: node["linkmention"] || "false")
|
170
|
-
if node.at(ns("//definitions//dt[@id = '#{xref}']"))
|
171
|
-
concept_render(node, ital: node["ital"] || "false",
|
172
|
-
ref: node["ref"] || "false",
|
173
|
-
linkref: node["linkref"] || "true",
|
174
|
-
linkmention: node["linkmention"] || "false")
|
175
|
-
else concept_render(node, ital: node["ital"] || "true",
|
176
|
-
ref: node["ref"] || "true",
|
177
|
-
linkref: node["linkref"] || "true",
|
178
|
-
linkmention: node["linkmention"] || "false")
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def concept_render(node, opts)
|
183
|
-
node&.at(ns("./refterm"))&.remove
|
184
|
-
r = node.at(ns("./renderterm"))
|
185
|
-
ref = node.at(ns("./xref | ./eref | ./termref"))
|
186
|
-
ref && opts[:ref] != "false" and r&.next = " "
|
187
|
-
opts[:ital] == "true" and r&.name = "em"
|
188
|
-
if opts[:linkmention] == "true" && !r.nil? && !ref.nil?
|
189
|
-
ref2 = ref.clone
|
190
|
-
r2 = r.clone
|
191
|
-
r.replace(ref2).children = r2
|
192
|
-
end
|
193
|
-
concept1_ref(node, ref, opts)
|
194
|
-
if opts[:ital] == "false"
|
195
|
-
r = node.at(ns(".//renderterm"))
|
196
|
-
r&.replace(r&.children)
|
197
|
-
end
|
198
|
-
node.replace(node.children)
|
199
|
-
end
|
200
|
-
|
201
|
-
def concept1_ref(_node, ref, opts)
|
202
|
-
ref.nil? and return
|
203
|
-
return ref.remove if opts[:ref] == "false"
|
204
|
-
|
205
|
-
r = concept1_ref_content(ref)
|
206
|
-
ref = r.at("./descendant-or-self::xmlns:xref | "\
|
207
|
-
"./descendant-or-self::xmlns:eref | "\
|
208
|
-
"./descendant-or-self::xmlns:termref")
|
209
|
-
%w(xref eref).include? ref&.name and get_linkend(ref)
|
210
|
-
if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
|
211
|
-
ref.replace(ref.children)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
def concept1_ref_content(ref)
|
216
|
-
if non_locality_elems(ref).select do |c|
|
217
|
-
!c.text? || /\S/.match(c)
|
218
|
-
end.empty?
|
219
|
-
ref.replace(@i18n.term_defined_in.sub(/%/,
|
220
|
-
ref.to_xml))
|
221
|
-
else ref.replace("[#{ref.to_xml}]")
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
163
|
def variant(docxml)
|
226
164
|
docxml.xpath(ns("//variant")).each { |f| variant1(f) }
|
227
165
|
docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove)
|