isodoc 0.9.16 → 0.9.17
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/Gemfile.lock +3 -2
- data/lib/isodoc/function/blocks.rb +21 -5
- data/lib/isodoc/function/table.rb +1 -1
- data/lib/isodoc/function/utils.rb +2 -1
- data/lib/isodoc/html_function/html.rb +37 -0
- data/lib/isodoc/version.rb +1 -1
- data/spec/isodoc/blocks_spec.rb +74 -6
- data/spec/isodoc/footnotes_spec.rb +1 -0
- data/spec/isodoc/postproc_spec.rb +58 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3db2fc3806a2953f1cd51c3edc7a3f8abe930e7a85562f1e3786452a987eb427
|
4
|
+
data.tar.gz: 92247d33287542fec1bc39186ba8670dd2570e797895a49cfe3257156840099a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a59a21657f9148c4ce184b4429aa1583b096b7ad2925c23be8b0744522efbd74e63aba7d958a9fdcb16ba6bf1d0165ef8e8ffeb059f0406c0068dbdad589188
|
7
|
+
data.tar.gz: 4c3dcacbc1e711db4618070f17f6b9e8d1b97c72745ed959b620e705fe4eb878a54c3f2ccdf17ff3fea6e3d510e0faf36afa1a7a2d87b2de1c979f3dfc2fee0b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
isodoc (0.9.
|
4
|
+
isodoc (0.9.17)
|
5
5
|
asciimath
|
6
6
|
html2doc (~> 0.8.6)
|
7
7
|
htmlentities (~> 4.3.4)
|
@@ -61,8 +61,9 @@ GEM
|
|
61
61
|
rb-inotify (~> 0.9, >= 0.9.7)
|
62
62
|
ruby_dep (~> 1.2)
|
63
63
|
lumberjack (1.0.13)
|
64
|
-
metanorma (0.3.
|
64
|
+
metanorma (0.3.8)
|
65
65
|
asciidoctor
|
66
|
+
htmlentities
|
66
67
|
method_source (0.9.2)
|
67
68
|
mime-types (3.2.2)
|
68
69
|
mime-types-data (~> 3.2015)
|
@@ -116,11 +116,17 @@ module IsoDoc::Function
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def sourcecode_name_parse(_node, div, name)
|
119
|
-
div.p **{ class: "
|
119
|
+
div.p **{ class: "SourceTitle", align: "center" } do |p|
|
120
120
|
name.children.each { |n| parse(n, p) }
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
def admonition_name_parse(_node, div, name)
|
125
|
+
div.p **{ class: "AdmonitionTitle", align: "center" } do |p|
|
126
|
+
name.children.each { |n| parse(n, p) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
124
130
|
def sourcecode_parse(node, out)
|
125
131
|
name = node.at(ns("./name"))
|
126
132
|
out.p **attr_code(id: node["id"], class: "Sourcecode") do |div|
|
@@ -151,12 +157,21 @@ module IsoDoc::Function
|
|
151
157
|
"Admonition"
|
152
158
|
end
|
153
159
|
|
160
|
+
def admonition_name(node, type)
|
161
|
+
name = node&.at(ns("./name")) and return name
|
162
|
+
name = Nokogiri::XML::Node.new('name', node.document)
|
163
|
+
return unless type && @admonition[type]
|
164
|
+
name << @admonition[type]&.upcase
|
165
|
+
name
|
166
|
+
end
|
167
|
+
|
154
168
|
def admonition_parse(node, out)
|
155
|
-
|
169
|
+
type = node["type"]
|
170
|
+
name = admonition_name(node, type)
|
156
171
|
out.div **{ class: admonition_class(node) } do |t|
|
157
|
-
t
|
172
|
+
admonition_name_parse(node, t, name) if name
|
158
173
|
node.children.each do |n|
|
159
|
-
parse(n, t)
|
174
|
+
parse(n, t) unless n.name == "name"
|
160
175
|
end
|
161
176
|
end
|
162
177
|
end
|
@@ -212,7 +227,8 @@ module IsoDoc::Function
|
|
212
227
|
author = node.at(ns("./author"))
|
213
228
|
source = node.at(ns("./source"))
|
214
229
|
out.p **{ class: "QuoteAttribution" } do |p|
|
215
|
-
p << "— #{author.text}
|
230
|
+
p << "— #{author.text}" if author
|
231
|
+
p << ", " if author && source
|
216
232
|
eref_parse(source, p) if source
|
217
233
|
end
|
218
234
|
end
|
@@ -24,7 +24,7 @@ module IsoDoc::Function
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def tbody_parse(node, t)
|
27
|
-
tbody = node.at(ns("./tbody"))
|
27
|
+
tbody = node.at(ns("./tbody")) || return
|
28
28
|
t.tbody do |h|
|
29
29
|
tbody.element_children.each_with_index do |n, i|
|
30
30
|
tr_parse(n, h, i, tbody.element_children.size, false)
|
@@ -140,7 +140,8 @@ module IsoDoc::Function
|
|
140
140
|
gsub(/\s*\[\/TERMREF\]\s*/, l10n("]")).
|
141
141
|
gsub(/\s*\[MODIFICATION\]/, l10n(", #{@modified_lbl} — "))
|
142
142
|
template = liquid(docxml)
|
143
|
-
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
|
143
|
+
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h).
|
144
|
+
gsub('<', '<').gsub('>', '>').gsub('&', '&')
|
144
145
|
end
|
145
146
|
end
|
146
147
|
end
|
@@ -112,10 +112,47 @@ module IsoDoc::HtmlFunction
|
|
112
112
|
d.children.empty? or d.children.first.previous = html_button()
|
113
113
|
end
|
114
114
|
|
115
|
+
def sourcecode_highlighter
|
116
|
+
'<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>'
|
117
|
+
end
|
118
|
+
|
119
|
+
def sourcecodelang(lang)
|
120
|
+
return unless lang
|
121
|
+
case lang.downcase
|
122
|
+
when "javascript" then "lang-js"
|
123
|
+
when "c" then "lang-c"
|
124
|
+
when "c+" then "lang-cpp"
|
125
|
+
when "console" then "lang-bsh"
|
126
|
+
when "ruby" then "lang-rb"
|
127
|
+
when "html" then "lang-html"
|
128
|
+
when "java" then "lang-java"
|
129
|
+
when "xml" then "lang-xml"
|
130
|
+
when "perl" then "lang-perl"
|
131
|
+
when "python" then "lang-py"
|
132
|
+
when "xsl" then "lang-xsl"
|
133
|
+
else
|
134
|
+
""
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def sourcecode_parse(node, out)
|
139
|
+
name = node.at(ns("./name"))
|
140
|
+
out.pre **attr_code(id: node["id"],
|
141
|
+
class: "prettyprint #{sourcecodelang(node&.at(ns('./@lang'))&.value)}") do |div|
|
142
|
+
@sourcecode = true
|
143
|
+
node.children.each do |n|
|
144
|
+
parse(n, div) unless n.name == "name"
|
145
|
+
end
|
146
|
+
@sourcecode = false
|
147
|
+
sourcecode_name_parse(node, div, name) if name
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
115
151
|
def html_preface(docxml)
|
116
152
|
html_cover(docxml) if @htmlcoverpage
|
117
153
|
html_intro(docxml) if @htmlintropage
|
118
154
|
docxml.at("//body") << mathjax(@openmathdelim, @closemathdelim)
|
155
|
+
docxml.at("//body") << sourcecode_highlighter
|
119
156
|
if @scripts
|
120
157
|
scripts = File.read(@scripts, encoding: "UTF-8")
|
121
158
|
a = docxml.at("//body").add_child docxml.create_cdata(scripts)
|
data/lib/isodoc/version.rb
CHANGED
data/spec/isodoc/blocks_spec.rb
CHANGED
@@ -397,7 +397,7 @@ B</pre>
|
|
397
397
|
expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
|
398
398
|
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
399
399
|
<preface><foreword>
|
400
|
-
<sourcecode id="samplecode">
|
400
|
+
<sourcecode lang="ruby" id="samplecode">
|
401
401
|
<name>Ruby <em>code</em></name>
|
402
402
|
puts x
|
403
403
|
</sourcecode>
|
@@ -408,7 +408,7 @@ B</pre>
|
|
408
408
|
<br/>
|
409
409
|
<div>
|
410
410
|
<h1 class="ForewordTitle">Foreword</h1>
|
411
|
-
<
|
411
|
+
<pre id="samplecode" class="prettyprint lang-rb"><br/>    <br/>  puts x<br/><p class="SourceTitle" align="center">Ruby <i>code</i></p></pre>
|
412
412
|
</div>
|
413
413
|
<p class="zzSTDTitle1"/>
|
414
414
|
</div>
|
@@ -417,6 +417,47 @@ B</pre>
|
|
417
417
|
OUTPUT
|
418
418
|
end
|
419
419
|
|
420
|
+
it "processes sourcecode (Word)" do
|
421
|
+
expect(IsoDoc::WordConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
|
422
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
423
|
+
<preface><foreword>
|
424
|
+
<sourcecode lang="ruby" id="samplecode">
|
425
|
+
<name>Ruby <em>code</em></name>
|
426
|
+
puts x
|
427
|
+
</sourcecode>
|
428
|
+
</foreword></preface>
|
429
|
+
</iso-standard>
|
430
|
+
INPUT
|
431
|
+
<html xmlns:epub="http://www.idpf.org/2007/ops">
|
432
|
+
<head/>
|
433
|
+
<body lang="EN-US" link="blue" vlink="#954F72">
|
434
|
+
<div class="WordSection1">
|
435
|
+
<p> </p>
|
436
|
+
</div>
|
437
|
+
<p>
|
438
|
+
<br clear="all" class="section"/>
|
439
|
+
</p>
|
440
|
+
<div class="WordSection2">
|
441
|
+
<p>
|
442
|
+
<br clear="all" style="mso-special-character:line-break;page-break-before:always"/>
|
443
|
+
</p>
|
444
|
+
<div>
|
445
|
+
<h1 class="ForewordTitle">Foreword</h1>
|
446
|
+
<p id="samplecode" class="Sourcecode"><br/>    <br/>  puts x<br/><p class="SourceTitle" align="center">Ruby <i>code</i></p></p>
|
447
|
+
</div>
|
448
|
+
<p> </p>
|
449
|
+
</div>
|
450
|
+
<p>
|
451
|
+
<br clear="all" class="section"/>
|
452
|
+
</p>
|
453
|
+
<div class="WordSection3">
|
454
|
+
<p class="zzSTDTitle1"/>
|
455
|
+
</div>
|
456
|
+
</body>
|
457
|
+
</html>
|
458
|
+
OUTPUT
|
459
|
+
end
|
460
|
+
|
420
461
|
it "processes sourcecode with escapes preserved" do
|
421
462
|
expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
|
422
463
|
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
@@ -432,7 +473,7 @@ B</pre>
|
|
432
473
|
<br/>
|
433
474
|
<div>
|
434
475
|
<h1 class="ForewordTitle">Foreword</h1>
|
435
|
-
<
|
476
|
+
<pre id="samplecode" class="prettyprint "><br/>    <br/>  <xml><br/><p class="SourceTitle" align="center">XML code</p></pre>
|
436
477
|
</div>
|
437
478
|
<p class="zzSTDTitle1"/>
|
438
479
|
</div>
|
@@ -460,11 +501,11 @@ B</pre>
|
|
460
501
|
<br/>
|
461
502
|
<div>
|
462
503
|
<h1 class="ForewordTitle">Foreword</h1>
|
463
|
-
<
|
504
|
+
<pre id="_" class="prettyprint ">puts "Hello, world." <1><br/>   %w{a b c}.each do |x|<br/>     puts x <2><br/>   end<span class="zzMoveToFollowing"><1> </span>
|
464
505
|
<p class="Sourcecode" id="_">This is one callout</p>
|
465
506
|
<span class="zzMoveToFollowing"><2> </span>
|
466
507
|
<p class="Sourcecode" id="_">This is another callout</p>
|
467
|
-
</
|
508
|
+
</pre>
|
468
509
|
</div>
|
469
510
|
<p class="zzSTDTitle1"/>
|
470
511
|
</div>
|
@@ -487,7 +528,7 @@ B</pre>
|
|
487
528
|
<br/>
|
488
529
|
<div>
|
489
530
|
<h1 class="ForewordTitle">Foreword</h1>
|
490
|
-
<div class="Admonition"><
|
531
|
+
<div class="Admonition"><p class="AdmonitionTitle" align="center">CAUTION</p>
|
491
532
|
<p id="_e94663cc-2473-4ccc-9a72-983a74d989f2">Only use paddy or parboiled rice for the determination of husked rice yield.</p>
|
492
533
|
</div>
|
493
534
|
</div>
|
@@ -498,6 +539,33 @@ B</pre>
|
|
498
539
|
OUTPUT
|
499
540
|
end
|
500
541
|
|
542
|
+
it "processes admonitions with titles" do
|
543
|
+
expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
|
544
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
545
|
+
<preface><foreword>
|
546
|
+
<admonition id="_70234f78-64e5-4dfc-8b6f-f3f037348b6a" type="caution">
|
547
|
+
<name>Title</name>
|
548
|
+
<p id="_e94663cc-2473-4ccc-9a72-983a74d989f2">Only use paddy or parboiled rice for the determination of husked rice yield.</p>
|
549
|
+
</admonition>
|
550
|
+
</foreword></preface>
|
551
|
+
</iso-standard>
|
552
|
+
INPUT
|
553
|
+
#{HTML_HDR}
|
554
|
+
<br/>
|
555
|
+
<div>
|
556
|
+
<h1 class="ForewordTitle">Foreword</h1>
|
557
|
+
<div class="Admonition"><p class="AdmonitionTitle" align="center">Title</p>
|
558
|
+
<p id="_e94663cc-2473-4ccc-9a72-983a74d989f2">Only use paddy or parboiled rice for the determination of husked rice yield.</p>
|
559
|
+
</div>
|
560
|
+
</div>
|
561
|
+
<p class="zzSTDTitle1"/>
|
562
|
+
</div>
|
563
|
+
</body>
|
564
|
+
</html>
|
565
|
+
OUTPUT
|
566
|
+
end
|
567
|
+
|
568
|
+
|
501
569
|
it "processes formulae" do
|
502
570
|
expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
|
503
571
|
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
@@ -153,6 +153,7 @@ RSpec.describe IsoDoc do
|
|
153
153
|
});
|
154
154
|
</script>
|
155
155
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=AM_HTMLorMML"></script>
|
156
|
+
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
|
156
157
|
</body>
|
157
158
|
OUTPUT
|
158
159
|
end
|
@@ -683,4 +683,62 @@ ICAgICAgIDogRU5EIERPQyBJRAoKRklMRU5BTUU6IHRlc3QKCg==
|
|
683
683
|
OUTPUT
|
684
684
|
end
|
685
685
|
|
686
|
+
it "does not lose HTML escapes in postprocessing" do
|
687
|
+
FileUtils.rm_f "test.doc"
|
688
|
+
FileUtils.rm_f "test.html"
|
689
|
+
IsoDoc::HtmlConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
|
690
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
691
|
+
<preface><foreword>
|
692
|
+
<sourcecode id="samplecode">
|
693
|
+
<name>XML code</name>
|
694
|
+
<xml> &
|
695
|
+
</sourcecode>
|
696
|
+
</foreword></preface>
|
697
|
+
</iso-standard>
|
698
|
+
INPUT
|
699
|
+
html = File.read("test.html").sub(/^.*<main class="main-section">/m, '<main class="main-section">').
|
700
|
+
sub(%r{</main>.*$}m, "</main>")
|
701
|
+
expect(html).to be_equivalent_to <<~"OUTPUT"
|
702
|
+
<main class="main-section"><button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
|
703
|
+
<br />
|
704
|
+
<div>
|
705
|
+
<h1 class="ForewordTitle">Foreword</h1>
|
706
|
+
<pre id="samplecode" class="prettyprint "><br />    <br />  <xml> &<br /><p class="SourceTitle" align="center">XML code</p></pre>
|
707
|
+
</div>
|
708
|
+
<p class="zzSTDTitle1"></p>
|
709
|
+
</main>
|
710
|
+
OUTPUT
|
711
|
+
end
|
712
|
+
|
713
|
+
|
714
|
+
it "does not lose HTML escapes in postprocessing (Word)" do
|
715
|
+
FileUtils.rm_f "test.doc"
|
716
|
+
FileUtils.rm_f "test.html"
|
717
|
+
IsoDoc::WordConvert.new({wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.css"}).convert("test", <<~"INPUT", false)
|
718
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
719
|
+
<preface><foreword>
|
720
|
+
<sourcecode id="samplecode">
|
721
|
+
<name>XML code</name>
|
722
|
+
<xml> &
|
723
|
+
</sourcecode>
|
724
|
+
</foreword></preface>
|
725
|
+
</iso-standard>
|
726
|
+
INPUT
|
727
|
+
word = File.read("test.doc").sub(/^.*<div class="WordSection2">/m, '<div class="WordSection2">').
|
728
|
+
sub(%r{<p class="MsoNormal">\s*<br clear="all" class="section"/>\s*</p>\s*<div class="WordSection3">.*$}m, "")
|
729
|
+
expect(word).to be_equivalent_to <<~"OUTPUT"
|
730
|
+
<div class="WordSection2">
|
731
|
+
<p class="MsoNormal">
|
732
|
+
<br clear="all" style="mso-special-character:line-break;page-break-before:always"/>
|
733
|
+
</p>
|
734
|
+
<div>
|
735
|
+
<h1 class="ForewordTitle">Foreword</h1>
|
736
|
+
<p class="Sourcecode"><a name="samplecode" id="samplecode"></a><br/>    <br/>  <xml> &<br/><p class="SourceTitle" align="center">XML code</p></p>
|
737
|
+
</div>
|
738
|
+
<p class="MsoNormal"> </p>
|
739
|
+
</div>
|
740
|
+
|
741
|
+
OUTPUT
|
742
|
+
end
|
743
|
+
|
686
744
|
end
|
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: 0.9.
|
4
|
+
version: 0.9.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|