metanorma-standoc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor/standoc/base.rb +13 -0
- data/lib/asciidoctor/standoc/cleanup.rb +0 -17
- data/lib/asciidoctor/standoc/cleanup_block.rb +17 -0
- data/lib/asciidoctor/standoc/converter.rb +6 -0
- data/lib/asciidoctor/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor-standoc/base_spec.rb +40 -46
- data/spec/asciidoctor-standoc/blocks_spec.rb +15 -2
- data/spec/asciidoctor-standoc/validate_spec.rb +8 -0
- data/spec/assets/html.css +12 -1
- data/spec/assets/word.css +12 -1
- data/spec/metanorma/processor_spec.rb +33 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db3428a1564b7f52dd275be33d22191aacec1c9de572bd355b2889e1da0f7acd
|
4
|
+
data.tar.gz: dadf1c955de197d23c37440b5d028793e9dff69e0e5dea566e214458ba3ff065
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b79bf52f01df9f3c02eb128d867cadaef60829b5c58adc64aad116a2a2654c0ea1b0a85580c370eeba1c87434fb5ff21dfb81e4fc827cec9f668adc18c21a5c
|
7
|
+
data.tar.gz: 0542ccaa5125ab49f192edbd29c21e33db9c560eb3eb1f327ec22d196de6acb22eff9be43d893f7e85e44a856c8000a564f88cbc10f09e8f2a6ca991551c43a3
|
@@ -37,6 +37,11 @@ module Asciidoctor
|
|
37
37
|
headerfont: node.attr("header-font"),
|
38
38
|
monospacefont: node.attr("monospace-font"),
|
39
39
|
i18nyaml: node.attr("i18nyaml"),
|
40
|
+
scope: node.attr("scope"),
|
41
|
+
htmlstylesheet: node.attr("htmlstylesheet"),
|
42
|
+
htmlcoverpage: node.attr("htmlcoverpage"),
|
43
|
+
htmlintropage: node.attr("htmlintropage"),
|
44
|
+
scripts: node.attr("scripts"),
|
40
45
|
)
|
41
46
|
end
|
42
47
|
|
@@ -47,6 +52,14 @@ module Asciidoctor
|
|
47
52
|
headerfont: node.attr("header-font"),
|
48
53
|
monospacefont: node.attr("monospace-font"),
|
49
54
|
i18nyaml: node.attr("i18nyaml"),
|
55
|
+
scope: node.attr("scope"),
|
56
|
+
wordstylesheet: node.attr("wordstylesheet"),
|
57
|
+
standardstylesheet: node.attr("standardstylesheet"),
|
58
|
+
header: node.attr("header"),
|
59
|
+
wordcoverpage: node.attr("wordcoverpage"),
|
60
|
+
wordintropage: node.attr("wordintropage"),
|
61
|
+
ulstyle: node.attr("ulstyle"),
|
62
|
+
olstyle: node.attr("olstyle"),
|
50
63
|
)
|
51
64
|
end
|
52
65
|
|
@@ -184,23 +184,6 @@ module Asciidoctor
|
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
ELEMS_ALLOW_NOTES =
|
188
|
-
# %w[p formula quote sourcecode example admonition ul ol dl figure]
|
189
|
-
%w[p formula ul ol dl figure].freeze
|
190
|
-
|
191
|
-
# if a note is at the end of a section, it is left alone
|
192
|
-
# if a note is followed by a non-note block,
|
193
|
-
# it is moved inside its preceding block if it is not delimited
|
194
|
-
# (so there was no way of making that block include the note)
|
195
|
-
def note_cleanup(xmldoc)
|
196
|
-
q = "//note[following-sibling::*[not(local-name() = 'note')]]"
|
197
|
-
xmldoc.xpath(q).each do |n|
|
198
|
-
next unless n.ancestors("table").empty?
|
199
|
-
prev = n.previous_element || next
|
200
|
-
n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
187
|
def empty_text_before_first_element(x)
|
205
188
|
x.children.each do |c|
|
206
189
|
if c.text?
|
@@ -129,6 +129,23 @@ module Asciidoctor
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
+
ELEMS_ALLOW_NOTES =
|
133
|
+
# %w[p formula quote sourcecode example admonition ul ol dl figure]
|
134
|
+
%w[p formula ul ol dl figure].freeze
|
135
|
+
|
136
|
+
# if a note is at the end of a section, it is left alone
|
137
|
+
# if a note is followed by a non-note block,
|
138
|
+
# it is moved inside its preceding block if it is not delimited
|
139
|
+
# (so there was no way of making that block include the note)
|
140
|
+
def note_cleanup(xmldoc)
|
141
|
+
q = "//note[following-sibling::*[not(local-name() = 'note')]]"
|
142
|
+
xmldoc.xpath(q).each do |n|
|
143
|
+
next unless n.ancestors("table").empty?
|
144
|
+
prev = n.previous_element || next
|
145
|
+
n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
132
149
|
def sections_order_cleanup(x)
|
133
150
|
s = x.at("//sections")
|
134
151
|
make_preface(x, s)
|
@@ -40,6 +40,12 @@ module Asciidoctor
|
|
40
40
|
super
|
41
41
|
basebackend "html"
|
42
42
|
outfilesuffix ".xml"
|
43
|
+
@libdir = File.dirname(__FILE__)
|
44
|
+
end
|
45
|
+
|
46
|
+
# path to isodoc assets in child gems
|
47
|
+
def html_doc_path(file)
|
48
|
+
File.join(@libdir, File.join("../../isodoc/html", file))
|
43
49
|
end
|
44
50
|
|
45
51
|
alias_method :embedded, :content
|
data/metanorma-standoc.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_dependency "asciidoctor", "~> 1.5.7"
|
30
30
|
spec.add_dependency "ruby-jing"
|
31
|
-
spec.add_dependency "isodoc", "
|
31
|
+
spec.add_dependency "isodoc", "~> 0.8.8"
|
32
32
|
spec.add_dependency "iev", "~> 0.2.0"
|
33
33
|
spec.add_dependency "relaton", "~> 0.1.3"
|
34
34
|
|
@@ -58,18 +58,13 @@ RSpec.describe Asciidoctor::Standoc do
|
|
58
58
|
:docsubstage: 20
|
59
59
|
:iteration: 3
|
60
60
|
:language: en
|
61
|
-
:title
|
62
|
-
:title-main-en: Main Title -- Title
|
63
|
-
:title-part-en: Title Part
|
64
|
-
:title-intro-fr: Introduction Française
|
65
|
-
:title-main-fr: Titre Principal
|
66
|
-
:title-part-fr: Part du Titre
|
61
|
+
:title: Main Title -- Title
|
67
62
|
:library-ics: 1,2,3
|
68
63
|
INPUT
|
69
64
|
<?xml version="1.0" encoding="UTF-8"?>
|
70
65
|
<standard-document xmlns="http://riboseinc.com/isoxml">
|
71
66
|
<bibdata type="article">
|
72
|
-
|
67
|
+
<title language="en" format="text/plain">Main Title — Title</title>
|
73
68
|
<docidentifier>
|
74
69
|
<project-number part="1"> 1000</project-number>
|
75
70
|
</docidentifier>
|
@@ -101,7 +96,6 @@ RSpec.describe Asciidoctor::Standoc do
|
|
101
96
|
OUTPUT
|
102
97
|
end
|
103
98
|
|
104
|
-
|
105
99
|
it "processes complex metadata" do
|
106
100
|
expect(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).to be_equivalent_to <<~'OUTPUT'
|
107
101
|
= Document title
|
@@ -202,40 +196,13 @@ RSpec.describe Asciidoctor::Standoc do
|
|
202
196
|
Author
|
203
197
|
:docfile: test.adoc
|
204
198
|
:novalid:
|
199
|
+
:scripts: spec/assets/scripts.html
|
205
200
|
INPUT
|
206
201
|
html = File.read("test.html", encoding: "utf-8")
|
207
202
|
expect(html).to match(%r{<script>})
|
208
203
|
end
|
209
204
|
|
210
|
-
it "uses
|
211
|
-
system "rm -f test.html"
|
212
|
-
Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
|
213
|
-
= Document title
|
214
|
-
Author
|
215
|
-
:docfile: test.adoc
|
216
|
-
:novalid:
|
217
|
-
INPUT
|
218
|
-
html = File.read("test.html", encoding: "utf-8")
|
219
|
-
expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
|
220
|
-
expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Cambria", serif;]m)
|
221
|
-
expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Cambria", serif;]m)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "uses default fonts for alt doc" do
|
225
|
-
system "rm -f test_alt.html"
|
226
|
-
Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
|
227
|
-
= Document title
|
228
|
-
Author
|
229
|
-
:docfile: test.adoc
|
230
|
-
:novalid:
|
231
|
-
INPUT
|
232
|
-
html = File.read("test_alt.html", encoding: "utf-8")
|
233
|
-
expect(html).to match(%r[\.Sourcecode[^{]+\{[^{]+font-family: "Space Mono", monospace;]m)
|
234
|
-
expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Lato", sans-serif;]m)
|
235
|
-
expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Lato", sans-serif;]m)
|
236
|
-
end
|
237
|
-
|
238
|
-
it "uses Chinese fonts" do
|
205
|
+
it "uses specified fonts and assets in HTML" do
|
239
206
|
system "rm -f test.html"
|
240
207
|
Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
|
241
208
|
= Document title
|
@@ -243,15 +210,25 @@ RSpec.describe Asciidoctor::Standoc do
|
|
243
210
|
:docfile: test.adoc
|
244
211
|
:novalid:
|
245
212
|
:script: Hans
|
213
|
+
:body-font: Zapf Chancery
|
214
|
+
:header-font: Comic Sans
|
215
|
+
:monospace-font: Andale Mono
|
216
|
+
:htmlstylesheet: spec/assets/html.css
|
217
|
+
:htmlcoverpage: spec/assets/htmlcover.html
|
218
|
+
:htmlintropage: spec/assets/htmlintro.html
|
219
|
+
:scripts: spec/assets/scripts.html
|
246
220
|
INPUT
|
247
221
|
html = File.read("test.html", encoding: "utf-8")
|
248
|
-
expect(html).to match(%r[
|
249
|
-
expect(html).to match(%r[
|
250
|
-
expect(html).to match(%r[
|
222
|
+
expect(html).to match(%r[pre[^{]+\{[^{]+font-family: Andale Mono;]m)
|
223
|
+
expect(html).to match(%r[p[^{]+\{[^{]+font-family: Zapf Chancery;]m)
|
224
|
+
expect(html).to match(%r[h1[^{]+\{[^{]+font-family: Comic Sans;]m)
|
225
|
+
expect(html).to match(%r[an empty html cover page])
|
226
|
+
expect(html).to match(%r[an empty html intro page])
|
227
|
+
expect(html).to match(%r[This is > a script])
|
251
228
|
end
|
252
229
|
|
253
|
-
it "uses specified fonts" do
|
254
|
-
system "rm -f test.
|
230
|
+
it "uses specified fonts and assets in Word" do
|
231
|
+
system "rm -f test.doc"
|
255
232
|
Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
|
256
233
|
= Document title
|
257
234
|
Author
|
@@ -261,11 +238,28 @@ RSpec.describe Asciidoctor::Standoc do
|
|
261
238
|
:body-font: Zapf Chancery
|
262
239
|
:header-font: Comic Sans
|
263
240
|
:monospace-font: Andale Mono
|
241
|
+
:wordstylesheet: spec/assets/word.css
|
242
|
+
:wordcoverpage: spec/assets/wordcover.html
|
243
|
+
:wordintropage: spec/assets/wordintro.html
|
244
|
+
:header: spec/assets/header.html
|
264
245
|
INPUT
|
265
|
-
html = File.read("test.
|
266
|
-
expect(html).to match(%r[
|
267
|
-
expect(html).to match(%r[
|
268
|
-
expect(html).to match(%r[
|
246
|
+
html = File.read("test.doc", encoding: "utf-8")
|
247
|
+
expect(html).to match(%r[pre[^{]+\{[^{]+font-family: Andale Mono;]m)
|
248
|
+
expect(html).to match(%r[p[^{]+\{[^{]+font-family: Zapf Chancery;]m)
|
249
|
+
expect(html).to match(%r[h1[^{]+\{[^{]+font-family: Comic Sans;]m)
|
250
|
+
expect(html).to match(%r[an empty word cover page])
|
251
|
+
expect(html).to match(%r[an empty word intro page])
|
252
|
+
expect(html).to match(%r[Content-Location: file:///C:/Doc/test_files/header.html
|
253
|
+
Content-Transfer-Encoding: base64
|
254
|
+
Content-Type: text/html charset="utf-8"
|
255
|
+
|
256
|
+
Ci8qIGFuIGVtcHR5IGhlYWRlciAqLwoKU1RBUlQgRE9DIElEOiAgOiBFTkQgRE9DIElECgpGSUxF
|
257
|
+
TkFNRTogdGVzdAoK
|
258
|
+
])
|
269
259
|
end
|
270
260
|
|
261
|
+
|
271
262
|
end
|
263
|
+
|
264
|
+
|
265
|
+
|
@@ -131,14 +131,27 @@ RSpec.describe Asciidoctor::Standoc do
|
|
131
131
|
it "processes notes" do
|
132
132
|
expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
|
133
133
|
#{ASCIIDOC_BLANK_HDR}
|
134
|
+
NOTE: This is a note
|
135
|
+
|
136
|
+
== Clause 1
|
137
|
+
|
138
|
+
|
134
139
|
NOTE: This is a note
|
135
140
|
INPUT
|
136
141
|
#{BLANK_HDR}
|
137
|
-
|
142
|
+
<preface><foreword obligation="informative">
|
143
|
+
<title>Foreword</title>
|
138
144
|
<note id="_">
|
139
145
|
<p id="_">This is a note</p>
|
140
146
|
</note>
|
141
|
-
</sections>
|
147
|
+
</foreword></preface><sections>
|
148
|
+
<clause id="_" inline-header="false" obligation="normative">
|
149
|
+
<title>Clause 1</title>
|
150
|
+
<note id="_">
|
151
|
+
<p id="_">This is a note</p>
|
152
|
+
</note>
|
153
|
+
</clause></sections>
|
154
|
+
|
142
155
|
</standard-document>
|
143
156
|
|
144
157
|
OUTPUT
|
@@ -2,6 +2,14 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
RSpec.describe Asciidoctor::Standoc do
|
4
4
|
|
5
|
+
it "warns that video is a skipped node" do
|
6
|
+
expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(/converter missing for video node/).to_stderr
|
7
|
+
#{VALIDATING_BLANK_HDR}
|
8
|
+
|
9
|
+
video::video_file.mp4[]
|
10
|
+
INPUT
|
11
|
+
end
|
12
|
+
|
5
13
|
it "warns that figure does not have title" do
|
6
14
|
expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(/Figure should have title/).to_stderr
|
7
15
|
#{VALIDATING_BLANK_HDR}
|
data/spec/assets/html.css
CHANGED
data/spec/assets/word.css
CHANGED
@@ -67,4 +67,37 @@ RSpec.describe Metanorma::Standoc::Processor do
|
|
67
67
|
OUTPUT
|
68
68
|
end
|
69
69
|
|
70
|
+
it "generates HTML from IsoDoc XML" do
|
71
|
+
system "rm -f test.doc"
|
72
|
+
processor.output(<<~"INPUT", "test.doc", :doc)
|
73
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
74
|
+
<sections>
|
75
|
+
<terms id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title>
|
76
|
+
<term id="J">
|
77
|
+
<preferred>Term2</preferred>
|
78
|
+
</term>
|
79
|
+
</terms>
|
80
|
+
</sections>
|
81
|
+
</iso-standard>
|
82
|
+
INPUT
|
83
|
+
expect(File.read("test.doc", encoding: "utf-8")).to match(/Electropedia/)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "generates XML from IsoDoc XML" do
|
87
|
+
system "rm -f test.xml"
|
88
|
+
processor.output(<<~"INPUT", "test.xml", :xml)
|
89
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
90
|
+
<sections>
|
91
|
+
<terms id="H" obligation="normative"><title>Terms, Definitions, Symbols and Abbreviated Terms</title>
|
92
|
+
<term id="J">
|
93
|
+
<preferred>Term2</preferred>
|
94
|
+
</term>
|
95
|
+
</terms>
|
96
|
+
</sections>
|
97
|
+
</iso-standard>
|
98
|
+
INPUT
|
99
|
+
expect(File.exist?("test.xml")).to be true
|
100
|
+
|
101
|
+
end
|
102
|
+
|
70
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma-standoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: isodoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.8.8
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.8.8
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: iev
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|