isodoc 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.adoc +34 -22
- data/isodoc.gemspec +1 -1
- data/lib/isodoc.rb +3 -1
- data/lib/isodoc/blocks.rb +1 -1
- data/lib/isodoc/cleanup.rb +1 -1
- data/lib/isodoc/convert.rb +9 -8
- data/lib/isodoc/{comments.rb → htmlconvert/comments.rb} +1 -1
- data/lib/isodoc/htmlconvert/convert.rb +13 -0
- data/lib/isodoc/{footnotes.rb → htmlconvert/footnotes.rb} +1 -1
- data/lib/isodoc/{html.rb → htmlconvert/html.rb} +29 -4
- data/lib/isodoc/i18n-en.yaml +5 -5
- data/lib/isodoc/i18n.rb +6 -2
- data/lib/isodoc/inline.rb +8 -8
- data/lib/isodoc/iso/convert.rb +4 -0
- data/lib/isodoc/iso/html/style-human.scss +3 -3
- data/lib/isodoc/iso/html/style-iso.scss +2 -2
- data/lib/isodoc/iso/html/wordstyle.scss +27 -0
- data/lib/isodoc/iso/wordconvert.rb +5 -2
- data/lib/isodoc/iso2wordhtml.rb +15 -16
- data/lib/isodoc/lists.rb +1 -1
- data/lib/isodoc/metadata.rb +66 -49
- data/lib/isodoc/references.rb +21 -11
- data/lib/isodoc/section.rb +3 -3
- data/lib/isodoc/table.rb +1 -1
- data/lib/isodoc/terms.rb +1 -1
- data/lib/isodoc/utils.rb +20 -21
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/wordconvert/comments.rb +122 -117
- data/lib/isodoc/wordconvert/convert.rb +5 -2
- data/lib/isodoc/wordconvert/footnotes.rb +14 -1
- data/lib/isodoc/wordconvert/postprocess.rb +7 -2
- data/lib/isodoc/wordconvert/wordconvertmodule.rb +12 -1
- data/lib/isodoc/xref_gen.rb +12 -2
- data/lib/isodoc/xref_sect_gen.rb +5 -4
- data/spec/isodoc/blocks_spec.rb +1 -1
- data/spec/isodoc/footnotes_spec.rb +3 -3
- data/spec/isodoc/i18n_spec.rb +10 -10
- data/spec/isodoc/inline_spec.rb +2 -2
- data/spec/isodoc/iso_spec.rb +79 -0
- data/spec/isodoc/metadata_spec.rb +12 -4
- data/spec/isodoc/postproc_spec.rb +7 -7
- data/spec/isodoc/ref_spec.rb +7 -19
- data/spec/isodoc/section_spec.rb +19 -84
- data/spec/isodoc/terms_spec.rb +1 -1
- data/spec/isodoc/xref_spec.rb +14 -14
- data/spec/spec_helper.rb +3 -3
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2307d0897bc261ade077a3550818f09a5d008640f2711809d0daf173f57e40c
|
4
|
+
data.tar.gz: 1a26f9322f6277cbc7534b8161d5798777a2e7683b782c402a5c1c8a4825cd6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 322b6d4ea3fbc7aedb90fddbeeae80347058e1a78b55e0b4fb7fea4fbbd4a26251cdd72fb664eb8bd36a082ca70e8bc39ad0e34eaec2143ed6b6ce9b9eed5af9
|
7
|
+
data.tar.gz: cf491aa85b5b08741027d50379be5c1be9a0ad252c20a56380429b828a2a6a6a899747830aaf1cf20bddb6a19ca5fabc7944fde58f11a1c908f9181d2feb095f
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
GIT
|
2
2
|
remote: https://github.com/riboseinc/html2doc.git
|
3
|
-
revision:
|
3
|
+
revision: f8bd693d8748c622bbe8f24ab30ac142b2543a0a
|
4
4
|
specs:
|
5
|
-
html2doc (0.
|
5
|
+
html2doc (0.8.0)
|
6
6
|
asciimath
|
7
7
|
htmlentities (~> 4.3.4)
|
8
8
|
image_size
|
@@ -15,9 +15,9 @@ GIT
|
|
15
15
|
PATH
|
16
16
|
remote: .
|
17
17
|
specs:
|
18
|
-
isodoc (0.
|
18
|
+
isodoc (0.7.0)
|
19
19
|
asciimath
|
20
|
-
html2doc
|
20
|
+
html2doc (>= 0.7.1)
|
21
21
|
htmlentities (~> 4.3.4)
|
22
22
|
image_size
|
23
23
|
liquid
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
docile (1.3.1)
|
41
41
|
equivalent-xml (0.6.0)
|
42
42
|
nokogiri (>= 1.4.3)
|
43
|
-
ffi (1.9.
|
43
|
+
ffi (1.9.25)
|
44
44
|
formatador (0.2.5)
|
45
45
|
guard (2.14.2)
|
46
46
|
formatador (>= 0.2.4)
|
data/README.adoc
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
= isodoc
|
2
|
-
|
1
|
+
= isodoc: Ruby gem for converting ISODoc documents into HTML/Word
|
3
2
|
|
4
3
|
image:https://img.shields.io/gem/v/isodoc.svg["Gem Version", link="https://rubygems.org/gems/isodoc"]
|
5
4
|
image:https://img.shields.io/travis/riboseinc/asciidoctor-iso/master.svg["Build Status", link="https://travis-ci.org/riboseinc/isodoc"]
|
6
5
|
image:https://codeclimate.com/github/riboseinc/isodoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/riboseinc/isodoc"]
|
7
6
|
|
7
|
+
== Purpose
|
8
|
+
|
8
9
|
This Gem converts documents in the https://github.com/riboseinc/isodoc-models[ISODoc document model] into HTML and Microsoft Word.
|
9
10
|
|
11
|
+
== Usage
|
12
|
+
|
10
13
|
The Gem contains two classes, `IsoDoc::Convert` (for HTML output) and `IsoDoc::WordConvert` (for Word output). They are initialised with the following rendering parameters:
|
11
14
|
|
12
15
|
i18nyaml:: YAML file giving internationalisation equivalents for keywords in rendering output; see https://github.com/riboseinc/asciidoctor-iso#document-attributes for further documentation
|
@@ -22,38 +25,47 @@ The IsoDoc gem classes themselves are abstract (though their current implementat
|
|
22
25
|
e.g.
|
23
26
|
|
24
27
|
[source,ruby]
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
----
|
29
|
+
IsoDoc::Convert::Iso.new(
|
30
|
+
bodyfont: "Zapf Chancery",
|
31
|
+
headerfont: "Comic Sans",
|
32
|
+
monospacefont: "Andale Mono",
|
33
|
+
alt: true,
|
34
|
+
script: "Hans",
|
35
|
+
i18nyaml: "i18n-en.yaml"
|
36
|
+
)
|
37
|
+
----
|
35
38
|
|
36
39
|
The conversion takes place with a `convert` method, with three arguments: the filename to be used for the output (once its file type suffix is stripped), the XML document string to be converted (optional), and a "debug" argument (optional), which stops execution before the output file is generated. If the document string is nil, its contents are read in from the filename provided. So:
|
37
40
|
|
38
41
|
[source,ruby]
|
39
|
-
|
40
|
-
|
42
|
+
----
|
43
|
+
# generates test.html
|
44
|
+
IsoDoc::Iso::Convert.new({}).convert("test.xml")
|
41
45
|
|
42
|
-
|
46
|
+
# generates test.doc, with Chinese font defaults rather than Roman
|
47
|
+
IsoDoc::Iso::WordConvert.new({script: "Hans"}).convert("test.xml")
|
43
48
|
|
44
|
-
|
49
|
+
# generates test.html, based on file1.xml
|
50
|
+
IsoDoc::Iso::Convert.new({}).convert("test", File.read("file1.xml"))
|
45
51
|
|
52
|
+
# generates HTML output for the given input string, but does not save it to disk.
|
46
53
|
IsoDoc::Iso::Convert.new({}).convert("test", <<~"INPUT", true)
|
47
|
-
|
54
|
+
<iso-standard xmlns="http://riboseinc.com/isoxml">
|
48
55
|
<preface><foreword>
|
49
56
|
<note>
|
50
|
-
|
57
|
+
<p id="_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f">These results are based on a
|
51
58
|
study carried out on three different types of kernel.</p>
|
52
59
|
</note>
|
53
60
|
</foreword></preface>
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
--
|
61
|
+
</iso-standard>
|
62
|
+
INPUT
|
63
|
+
----
|
58
64
|
|
59
65
|
NOTE: In the HTML stylesheets specific to standards, the Cover page and Intro page must be XHTML fragments, not HTML fragments. In particular, unlike Word HTML, all HTML attributes need to be quoted: `<p class="MsoToc2">`, not `<p class=MsoToc2>`.
|
66
|
+
|
67
|
+
== Converting Word output into "`Native Word`" (`.docx`)
|
68
|
+
|
69
|
+
This gem relies on https://github.com/riboseinc/html2doc[html2doc] to generate Microsoft Word documents.
|
70
|
+
|
71
|
+
Please see https://github.com/riboseinc/html2doc#converting-document-output-to-native-word-docx[this post-processing procedure] to convert output into a native-`docx` document.
|
data/isodoc.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_dependency "ruby-xslt"
|
37
37
|
spec.add_dependency "thread_safe"
|
38
38
|
spec.add_dependency "uuidtools"
|
39
|
-
spec.add_dependency "html2doc"
|
39
|
+
spec.add_dependency "html2doc", ">= 0.7.1"
|
40
40
|
spec.add_dependency "liquid"
|
41
41
|
spec.add_dependency "roman-numerals"
|
42
42
|
spec.add_dependency "sass"
|
data/lib/isodoc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module IsoDoc
|
2
2
|
|
3
3
|
require_relative "isodoc/version"
|
4
4
|
|
@@ -12,6 +12,8 @@ require "image_size"
|
|
12
12
|
require "set"
|
13
13
|
require "pp"
|
14
14
|
require "isodoc/convert"
|
15
|
+
require "isodoc/metadata"
|
16
|
+
require "isodoc/htmlconvert/convert"
|
15
17
|
require "isodoc/wordconvert/convert"
|
16
18
|
require "isodoc/iso/convert"
|
17
19
|
require "isodoc/iso/wordconvert"
|
data/lib/isodoc/blocks.rb
CHANGED
data/lib/isodoc/cleanup.rb
CHANGED
data/lib/isodoc/convert.rb
CHANGED
@@ -9,16 +9,13 @@ require "isodoc/blocks"
|
|
9
9
|
require "isodoc/lists"
|
10
10
|
require "isodoc/table"
|
11
11
|
require "isodoc/inline"
|
12
|
-
require "isodoc/footnotes"
|
13
|
-
require "isodoc/comments"
|
14
12
|
require "isodoc/xref_gen"
|
15
13
|
require "isodoc/xref_sect_gen"
|
16
|
-
require "isodoc/html"
|
17
14
|
require "isodoc/i18n"
|
18
15
|
require "sass"
|
19
16
|
|
20
17
|
module IsoDoc
|
21
|
-
class
|
18
|
+
class Common
|
22
19
|
|
23
20
|
# htmlstylesheet: Generic stylesheet for HTML
|
24
21
|
# wordstylesheet: Generic stylesheet for Word
|
@@ -49,8 +46,6 @@ module IsoDoc
|
|
49
46
|
@note = false
|
50
47
|
@sourcecode = false
|
51
48
|
@anchors = {}
|
52
|
-
@meta = {}
|
53
|
-
init_metadata
|
54
49
|
@footnotes = []
|
55
50
|
@comments = []
|
56
51
|
@in_footnote = false
|
@@ -91,12 +86,18 @@ module IsoDoc
|
|
91
86
|
end.join("\n")
|
92
87
|
end
|
93
88
|
|
89
|
+
def metadata_init(lang, script, labels)
|
90
|
+
@meta = Metadata.new(lang, script, labels)
|
91
|
+
end
|
92
|
+
|
94
93
|
def convert_init(file, filename, debug)
|
95
94
|
docxml = Nokogiri::XML(file)
|
96
95
|
filename, dir = init_file(filename, debug)
|
97
96
|
docxml.root.default_namespace = ""
|
98
|
-
|
99
|
-
|
97
|
+
lang = docxml&.at(ns("//bibdata/language"))&.text || "en"
|
98
|
+
script = docxml&.at(ns("//bibdata/script"))&.text || "Latn"
|
99
|
+
i18n_init(lang, script)
|
100
|
+
metadata_init(lang, script, @labels)
|
100
101
|
[docxml, filename, dir]
|
101
102
|
end
|
102
103
|
|
@@ -1,5 +1,30 @@
|
|
1
1
|
module IsoDoc
|
2
|
-
class Convert
|
2
|
+
class Convert < Common
|
3
|
+
def make_body1(body, _docxml)
|
4
|
+
body.div **{ class: "title-section" } do |div1|
|
5
|
+
div1.p { |p| p << " " } # placeholder
|
6
|
+
end
|
7
|
+
section_break(body)
|
8
|
+
end
|
9
|
+
|
10
|
+
def make_body2(body, docxml)
|
11
|
+
body.div **{ class: "prefatory-section" } do |div2|
|
12
|
+
info docxml, div2
|
13
|
+
div2.p { |p| p << " " } # placeholder
|
14
|
+
end
|
15
|
+
section_break(body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def make_body3(body, docxml)
|
19
|
+
body.div **{ class: "main-section" } do |div3|
|
20
|
+
foreword docxml, div3
|
21
|
+
introduction docxml, div3
|
22
|
+
middle docxml, div3
|
23
|
+
footnotes div3
|
24
|
+
comments div3
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
3
28
|
def postprocess(result, filename, dir)
|
4
29
|
result = from_xhtml(cleanup(to_xhtml(result)))
|
5
30
|
toHTML(result, filename)
|
@@ -76,7 +101,7 @@ module IsoDoc
|
|
76
101
|
|
77
102
|
def html_main(docxml)
|
78
103
|
docxml.at("//head").add_child(html_head())
|
79
|
-
d = docxml.at('//div[@class="
|
104
|
+
d = docxml.at('//div[@class="main-section"]')
|
80
105
|
d.name = "main"
|
81
106
|
d.children.first.previous = html_button()
|
82
107
|
end
|
@@ -96,14 +121,14 @@ module IsoDoc
|
|
96
121
|
def html_cover(docxml)
|
97
122
|
cover = File.read(@htmlcoverpage, encoding: "UTF-8")
|
98
123
|
coverxml = to_xhtml_fragment(cover)
|
99
|
-
d = docxml.at('//div[@class="
|
124
|
+
d = docxml.at('//div[@class="title-section"]')
|
100
125
|
d.children.first.add_previous_sibling coverxml.to_xml(encoding: "US-ASCII")
|
101
126
|
end
|
102
127
|
|
103
128
|
def html_intro(docxml)
|
104
129
|
intro = File.read(@htmlintropage, encoding: "UTF-8")
|
105
130
|
introxml = to_xhtml_fragment(intro)
|
106
|
-
d = docxml.at('//div[@class="
|
131
|
+
d = docxml.at('//div[@class="prefatory-section"]')
|
107
132
|
d.children.first.add_previous_sibling introxml.to_xml(encoding: "US-ASCII")
|
108
133
|
end
|
109
134
|
|
data/lib/isodoc/i18n-en.yaml
CHANGED
@@ -9,13 +9,13 @@ term_def_boilerplate: |
|
|
9
9
|
<a href=http://www.electropedia.org>http://www.electropedia.org</a>
|
10
10
|
</p> </li> </ul>
|
11
11
|
scope: Scope
|
12
|
-
symbols: Symbols and
|
13
|
-
table_of_contents: Table of
|
12
|
+
symbols: Symbols and abbreviated terms
|
13
|
+
table_of_contents: Table of contents
|
14
14
|
introduction: Introduction
|
15
15
|
foreword: Foreword
|
16
|
-
termsdef: Terms and
|
17
|
-
termsdefsymbols: Terms,
|
18
|
-
normref: Normative
|
16
|
+
termsdef: Terms and definitions
|
17
|
+
termsdefsymbols: Terms, definitions, symbols and abbreviated terms
|
18
|
+
normref: Normative references
|
19
19
|
bibliography: Bibliography
|
20
20
|
clause: Clause
|
21
21
|
annex: Annex
|
data/lib/isodoc/i18n.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "yaml"
|
2
2
|
|
3
3
|
module IsoDoc
|
4
|
-
class
|
4
|
+
class Common
|
5
5
|
def i18n_init(lang, script)
|
6
6
|
@lang = lang
|
7
7
|
@script = script
|
@@ -84,7 +84,7 @@ module IsoDoc
|
|
84
84
|
|
85
85
|
# function localising spaces and punctuation.
|
86
86
|
# Not clear if period needs to be localised for zh
|
87
|
-
def l10n(x, lang
|
87
|
+
def self.l10n(x, lang, script)
|
88
88
|
if lang == "zh" && script == "Hans"
|
89
89
|
x.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "、").
|
90
90
|
gsub(/\(/, "(").gsub(/\)/, ")").
|
@@ -94,5 +94,9 @@ module IsoDoc
|
|
94
94
|
x
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
def l10n(x, lang = @lang, script = @script)
|
99
|
+
Common::l10n(x, lang, script)
|
100
|
+
end
|
97
101
|
end
|
98
102
|
end
|
data/lib/isodoc/inline.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "uuidtools"
|
2
2
|
|
3
3
|
module IsoDoc
|
4
|
-
class
|
4
|
+
class Common
|
5
5
|
def section_break(body)
|
6
6
|
body.br
|
7
7
|
end
|
@@ -13,7 +13,7 @@ module IsoDoc
|
|
13
13
|
def link_parse(node, out)
|
14
14
|
linktext = node.text
|
15
15
|
linktext = node["target"] if linktext.empty?
|
16
|
-
out.a
|
16
|
+
out.a(**{ "href": node["target"] }) { |l| l << linktext }
|
17
17
|
end
|
18
18
|
|
19
19
|
def callout_parse(node, out)
|
@@ -21,9 +21,9 @@ module IsoDoc
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def anchor_linkend(node, linkend)
|
24
|
-
if node["citeas"].nil? && get_anchors.has_key?(node["bibitemid"])
|
24
|
+
if node["citeas"].nil? && node["bibitemid"] && get_anchors.has_key?(node["bibitemid"])
|
25
25
|
return get_anchors[node["bibitemid"]][:xref]
|
26
|
-
elsif get_anchors.has_key?(node["target"])
|
26
|
+
elsif node["target"] && get_anchors.has_key?(node["target"])
|
27
27
|
linkend = get_anchors[node["target"]][:xref]
|
28
28
|
container = get_anchors[node["target"]][:container]
|
29
29
|
(container && get_note_container_id(node) != container) &&
|
@@ -44,7 +44,7 @@ module IsoDoc
|
|
44
44
|
|
45
45
|
def xref_parse(node, out)
|
46
46
|
linkend = get_linkend(node)
|
47
|
-
out.a
|
47
|
+
out.a(**{ "href": "#" + node["target"] }) { |l| l << linkend }
|
48
48
|
end
|
49
49
|
|
50
50
|
def eref_localities(refs)
|
@@ -63,10 +63,10 @@ module IsoDoc
|
|
63
63
|
linkend = get_linkend(node)
|
64
64
|
if node["type"] == "footnote"
|
65
65
|
out.sup do |s|
|
66
|
-
s.a
|
66
|
+
s.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend }
|
67
67
|
end
|
68
68
|
else
|
69
|
-
out.a
|
69
|
+
out.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend }
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -85,7 +85,7 @@ module IsoDoc
|
|
85
85
|
def error_parse(node, out)
|
86
86
|
text = node.to_xml.gsub(/</, "<").gsub(/>/, ">")
|
87
87
|
out.para do |p|
|
88
|
-
p.b
|
88
|
+
p.b(**{ role: "strong" }) { |e| e << text }
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
data/lib/isodoc/iso/convert.rb
CHANGED
@@ -128,12 +128,12 @@ main {
|
|
128
128
|
padding-right: 2em;
|
129
129
|
}
|
130
130
|
|
131
|
-
.
|
131
|
+
.title-section, .prefatory-section {
|
132
132
|
padding-left: 4em;
|
133
133
|
padding-top: 2em;
|
134
134
|
}
|
135
135
|
|
136
|
-
.
|
136
|
+
.prefatory-section {
|
137
137
|
margin-bottom: 5em;
|
138
138
|
}
|
139
139
|
|
@@ -350,7 +350,7 @@ p.Terms {
|
|
350
350
|
padding: 0;
|
351
351
|
}
|
352
352
|
|
353
|
-
.
|
353
|
+
.title-section, .prefatory-section {
|
354
354
|
padding-left: 0;
|
355
355
|
padding-top: 0;
|
356
356
|
width: 100%;
|