asciidoctor-m3d 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ require "isodoc"
2
+ require_relative "metadata"
3
+ require_relative "m3dhtmlrender"
4
+
5
+ module IsoDoc
6
+ module M3d
7
+ # A {Converter} implementation that generates CSAND output, and a document
8
+ # schema encapsulation of the document for validation
9
+ class Convert < IsoDoc::Convert
10
+ def html_doc_path(file)
11
+ File.join(File.dirname(__FILE__), File.join("html", file))
12
+ end
13
+
14
+ def initialize(options)
15
+ super
16
+ @htmlstylesheet = generate_css(html_doc_path("htmlstyle.scss"), true, default_fonts(options))
17
+ @htmlcoverpage = html_doc_path("html_m3d_titlepage.html")
18
+ @htmlintropage = html_doc_path("html_m3d_intro.html")
19
+ @scripts = html_doc_path("scripts.html")
20
+ system "cp #{html_doc_path('logo.jpg')} logo.jpg"
21
+ @files_to_delete << "logo.jpg"
22
+ end
23
+
24
+ def default_fonts(options)
25
+ b = options[:bodyfont] ||
26
+ (options[:script] == "Hans" ? '"SimSun",serif' :
27
+ '"Garamond",serif')
28
+ h = options[:headerfont] ||
29
+ (options[:script] == "Hans" ? '"SimHei",sans-serif' :
30
+ '"Garamond",serif')
31
+ m = options[:monospacefont] || '"Courier New",monospace'
32
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
33
+ end
34
+
35
+ def metadata_init(lang, script, labels)
36
+ @meta = Metadata.new(lang, script, labels)
37
+ end
38
+
39
+ def colophon(body, docxml)
40
+ body.div **{ class: "colophon" } do |div|
41
+ div << <<~"COLOPHON"
42
+ <p>As with all M3AAWG documents that we publish, please check the M3AAWG website
43
+ (<a href="http://www.m3aawg.org">www.m3aawg.org</a>) for updates to this paper.</p>
44
+ <p>&copy; 2017 copyright by the Messaging, Malware and Mobile Anti-Abuse Working Group (M3AAWG)</p>
45
+ COLOPHON
46
+ end
47
+ end
48
+
49
+ def html_head()
50
+ <<~HEAD.freeze
51
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
52
+
53
+ <!--TOC script import-->
54
+ <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script>
55
+
56
+ <!--Google fonts-->
57
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
58
+ <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
59
+ <!--Font awesome import for the link icon-->
60
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
61
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
62
+ <style class="anchorjs"></style>
63
+ HEAD
64
+ end
65
+
66
+ def make_body(xml, docxml)
67
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
68
+ xml.body **body_attr do |body|
69
+ make_body1(body, docxml)
70
+ make_body2(body, docxml)
71
+ make_body3(body, docxml)
72
+ colophon(body, docxml)
73
+ end
74
+ end
75
+
76
+ def html_toc(docxml)
77
+ docxml
78
+ end
79
+
80
+ def annex_name(annex, name, div)
81
+ div.h1 **{ class: "Annex" } do |t|
82
+ t << "#{get_anchors[annex['id']][:label]} "
83
+ t << "<b>#{name.text}</b>"
84
+ end
85
+ end
86
+
87
+ def annex_name_lbl(clause, num)
88
+ obl = l10n("(#{@inform_annex_lbl})")
89
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
90
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
91
+ end
92
+
93
+ def pre_parse(node, out)
94
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
95
+ end
96
+
97
+ def term_defs_boilerplate(div, source, term, preface)
98
+ if source.empty? && term.nil?
99
+ div << @no_terms_boilerplate
100
+ else
101
+ div << term_defs_boilerplate_cont(source, term)
102
+ end
103
+ end
104
+
105
+ def i18n_init(lang, script)
106
+ super
107
+ @annex_lbl = "Appendix"
108
+ end
109
+
110
+ def error_parse(node, out)
111
+ # catch elements not defined in ISO
112
+ case node.name
113
+ when "pre"
114
+ pre_parse(node, out)
115
+ when "keyword"
116
+ out.span node.text, **{ class: "keyword" }
117
+ else
118
+ super
119
+ end
120
+ end
121
+
122
+ def fileloc(loc)
123
+ File.join(File.dirname(__FILE__), loc)
124
+ end
125
+
126
+ def cleanup(docxml)
127
+ super
128
+ term_cleanup(docxml)
129
+ end
130
+
131
+ def term_cleanup(docxml)
132
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
133
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
134
+ h2.add_child("&nbsp;")
135
+ h2.add_child(d.remove)
136
+ end
137
+ docxml
138
+ end
139
+ end
140
+ end
141
+ end
142
+
@@ -0,0 +1,68 @@
1
+ module IsoDoc
2
+ module M3d
3
+ # A {Converter} implementation that generates CSAND output, and a document
4
+ # schema encapsulation of the document for validation
5
+ class Convert < IsoDoc::Convert
6
+ def annex_name(annex, name, div)
7
+ div.h1 **{ class: "Annex" } do |t|
8
+ t << "#{get_anchors[annex['id']][:label]} "
9
+ t << "<b>#{name.text}</b>"
10
+ end
11
+ end
12
+
13
+ def annex_name_lbl(clause, num)
14
+ obl = l10n("(#{@inform_annex_lbl})")
15
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
16
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
17
+ end
18
+
19
+ def pre_parse(node, out)
20
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
21
+ end
22
+
23
+ def term_defs_boilerplate(div, source, term, preface)
24
+ if source.empty? && term.nil?
25
+ div << @no_terms_boilerplate
26
+ else
27
+ div << term_defs_boilerplate_cont(source, term)
28
+ end
29
+ end
30
+
31
+ def i18n_init(lang, script)
32
+ super
33
+ @annex_lbl = "Appendix"
34
+ end
35
+
36
+ def error_parse(node, out)
37
+ # catch elements not defined in ISO
38
+ case node.name
39
+ when "pre"
40
+ pre_parse(node, out)
41
+ when "keyword"
42
+ out.span node.text, **{ class: "keyword" }
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def fileloc(loc)
49
+ File.join(File.dirname(__FILE__), loc)
50
+ end
51
+
52
+ def cleanup(docxml)
53
+ super
54
+ term_cleanup(docxml)
55
+ end
56
+
57
+ def term_cleanup(docxml)
58
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
59
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
60
+ h2.add_child("&nbsp;")
61
+ h2.add_child(d.remove)
62
+ end
63
+ docxml
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,88 @@
1
+ require "isodoc"
2
+ require_relative "m3wordrender"
3
+
4
+ module IsoDoc
5
+ module M3d
6
+ # A {Converter} implementation that generates GB output, and a document
7
+ # schema encapsulation of the document for validation
8
+
9
+ class WordConvert < IsoDoc::WordConvert
10
+ def html_doc_path(file)
11
+ File.join(File.dirname(__FILE__), File.join("html", file))
12
+ end
13
+
14
+ def initialize(options)
15
+ super
16
+ @wordstylesheet = generate_css(html_doc_path("wordstyle.scss"), false, default_fonts(options))
17
+ @standardstylesheet = generate_css(html_doc_path("m3d.scss"), false, default_fonts(options))
18
+ @header = html_doc_path("header.html")
19
+ @wordintropage = html_doc_path("word_m3d_intro.html")
20
+ @ulstyle = "l3"
21
+ @olstyle = "l2"
22
+ system "cp #{html_doc_path('logo.jpg')} logo.jpg"
23
+ end
24
+
25
+ def default_fonts(options)
26
+ b = options[:bodyfont] ||
27
+ (options[:script] == "Hans" ? '"SimSun",serif' :
28
+ '"Garamond",serif')
29
+ h = options[:headerfont] ||
30
+ (options[:script] == "Hans" ? '"SimHei",sans-serif' :
31
+ '"Garamond",serif')
32
+ m = options[:monospacefont] || '"Courier New",monospace'
33
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
34
+ end
35
+
36
+ def colophon(body, docxml)
37
+ section_break(body)
38
+ body.div **{ class: "colophon" } do |div|
39
+ end
40
+ end
41
+
42
+ def make_body(xml, docxml)
43
+ body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
44
+ xml.body **body_attr do |body|
45
+ make_body2(body, docxml)
46
+ make_body3(body, docxml)
47
+ colophon(body, docxml)
48
+ end
49
+ end
50
+
51
+ def make_body2(body, docxml)
52
+ body.div **{ class: "WordSection2" } do |div2|
53
+ info docxml, div2
54
+ div2.p { |p| p << "&nbsp;" } # placeholder
55
+ end
56
+ body.br **{ clear: "all", style: "page-break-before:auto;mso-break-type:section-break;" }
57
+ end
58
+
59
+ def title(isoxml, _out)
60
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
61
+ set_metadata(:doctitle, main)
62
+ end
63
+
64
+ def generate_header(filename, dir)
65
+ return unless @header
66
+ template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
67
+ meta = @meta.get
68
+ meta[:filename] = filename
69
+ params = meta.map { |k, v| [k.to_s, v] }.to_h
70
+ File.open("header.html", "w") { |f| f.write(template.render(params)) }
71
+ @files_to_delete << "header.html"
72
+ end
73
+
74
+ def header_strip(h)
75
+ h = h.to_s.gsub(%r{<br/>}, " ").sub(/<\/?h[12][^>]*>/, "")
76
+ h1 = to_xhtml_fragment(h.dup)
77
+ h1.traverse do |x|
78
+ x.replace(" ") if x.name == "span" &&
79
+ /mso-tab-count/.match?(x["style"])
80
+ x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
81
+ x.remove if x.name == "a" && x["epub:type"] == "footnote"
82
+ x.replace(x.children) if x.name == "a"
83
+ end
84
+ from_xhtml(h1)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,68 @@
1
+ module IsoDoc
2
+ module M3d
3
+ # A {Converter} implementation that generates CSAND output, and a document
4
+ # schema encapsulation of the document for validation
5
+ class WordConvert < IsoDoc::WordConvert
6
+ def annex_name(annex, name, div)
7
+ div.h1 **{ class: "Annex" } do |t|
8
+ t << "#{get_anchors[annex['id']][:label]} "
9
+ t << "<b>#{name.text}</b>"
10
+ end
11
+ end
12
+
13
+ def annex_name_lbl(clause, num)
14
+ obl = l10n("(#{@inform_annex_lbl})")
15
+ obl = l10n("(#{@norm_annex_lbl})") if clause["obligation"] == "normative"
16
+ l10n("<b>#{@annex_lbl} #{num}</b> #{obl}")
17
+ end
18
+
19
+ def pre_parse(node, out)
20
+ out.pre node.text # content.gsub(/</, "&lt;").gsub(/>/, "&gt;")
21
+ end
22
+
23
+ def term_defs_boilerplate(div, source, term, preface)
24
+ if source.empty? && term.nil?
25
+ div << @no_terms_boilerplate
26
+ else
27
+ div << term_defs_boilerplate_cont(source, term)
28
+ end
29
+ end
30
+
31
+ def i18n_init(lang, script)
32
+ super
33
+ @annex_lbl = "Appendix"
34
+ end
35
+
36
+ def error_parse(node, out)
37
+ # catch elements not defined in ISO
38
+ case node.name
39
+ when "pre"
40
+ pre_parse(node, out)
41
+ when "keyword"
42
+ out.span node.text, **{ class: "keyword" }
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def fileloc(loc)
49
+ File.join(File.dirname(__FILE__), loc)
50
+ end
51
+
52
+ def cleanup(docxml)
53
+ super
54
+ term_cleanup(docxml)
55
+ end
56
+
57
+ def term_cleanup(docxml)
58
+ docxml.xpath("//p[@class = 'Terms']").each do |d|
59
+ h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
60
+ h2.add_child("&nbsp;")
61
+ h2.add_child(d.remove)
62
+ end
63
+ docxml
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,82 @@
1
+ require "isodoc"
2
+
3
+ module IsoDoc
4
+ module M3d
5
+ # A {Converter} implementation that generates CSAND output, and a document
6
+ # schema encapsulation of the document for validation
7
+ class Metadata < IsoDoc::Metadata
8
+ def initialize(lang, script, labels)
9
+ super
10
+ set(:status, "XXX")
11
+ end
12
+
13
+ def title(isoxml, _out)
14
+ main = isoxml&.at(ns("//title[@language='en']"))&.text
15
+ set(:doctitle, main)
16
+ end
17
+
18
+ def subtitle(_isoxml, _out)
19
+ nil
20
+ end
21
+
22
+ def author(isoxml, _out)
23
+ set(:tc, "XXXX")
24
+ tc = isoxml.at(ns("//editorialgroup/technical-committee"))
25
+ set(:tc, tc.text) if tc
26
+ end
27
+
28
+ def docid(isoxml, _out)
29
+ docnumber = isoxml.at(ns("//bibdata/docidentifier"))
30
+ docstatus = isoxml.at(ns("//bibdata/status"))
31
+ dn = docnumber&.text
32
+ if docstatus
33
+ set(:status, status_print(docstatus.text))
34
+ abbr = status_abbr(docstatus.text)
35
+ dn = "#{dn}(#{abbr})" unless abbr.empty?
36
+ end
37
+ set(:docnumber, dn)
38
+ end
39
+
40
+ def status_print(status)
41
+ status.split(/-/).map{ |w| w.capitalize }.join(" ")
42
+ end
43
+
44
+ def status_abbr(status)
45
+ case status
46
+ when "working-draft" then "wd"
47
+ when "committee-draft" then "cd"
48
+ when "draft-standard" then "d"
49
+ else
50
+ ""
51
+ end
52
+ end
53
+
54
+ def version(isoxml, _out)
55
+ super
56
+ revdate = get[:revdate]
57
+ set(:revdate_monthyear, monthyr(revdate))
58
+ end
59
+
60
+ MONTHS = {
61
+ "01": "January",
62
+ "02": "February",
63
+ "03": "March",
64
+ "04": "April",
65
+ "05": "May",
66
+ "06": "June",
67
+ "07": "July",
68
+ "08": "August",
69
+ "09": "September",
70
+ "10": "October",
71
+ "11": "November",
72
+ "12": "December",
73
+ }.freeze
74
+
75
+ def monthyr(isodate)
76
+ m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
77
+ return isodate unless m && m[:yr] && m[:mo]
78
+ return "#{MONTHS[m[:mo].to_sym]} #{m[:yr]}"
79
+ end
80
+ end
81
+ end
82
+ end