metanorma-document 0.2.0 → 0.2.1
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/README.adoc +59 -18
- data/data/stylesheets/components/bibliography.css +2 -2
- data/data/stylesheets/components/inline.css +11 -12
- data/docs/html-renderer.adoc +261 -0
- data/lib/metanorma/document/version.rb +1 -1
- data/lib/metanorma/html/base_renderer.rb +180 -219
- data/lib/metanorma/html/drops/admonition_drop.rb +26 -0
- data/lib/metanorma/html/drops/block_element_drop.rb +20 -0
- data/lib/metanorma/html/drops/example_drop.rb +35 -0
- data/lib/metanorma/html/drops/figure_drop.rb +53 -0
- data/lib/metanorma/html/drops/formula_drop.rb +44 -0
- data/lib/metanorma/html/drops/note_drop.rb +32 -0
- data/lib/metanorma/html/drops/sourcecode_drop.rb +37 -0
- data/lib/metanorma/html/drops.rb +7 -0
- data/lib/metanorma/html/iso_renderer.rb +96 -79
- data/lib/metanorma/html/ogc_renderer.rb +5 -5
- data/lib/metanorma/html/standard_renderer.rb +34 -28
- data/lib/metanorma/html/templates/_admonition.html.liquid +4 -0
- data/lib/metanorma/html/templates/_doc_title.html.liquid +1 -1
- data/lib/metanorma/html/templates/_example.html.liquid +3 -0
- data/lib/metanorma/html/templates/_figure.html.liquid +6 -0
- data/lib/metanorma/html/templates/_formula.html.liquid +6 -0
- data/lib/metanorma/html/templates/_iso_doc_title.html.liquid +2 -2
- data/lib/metanorma/html/templates/_note.html.liquid +3 -0
- data/lib/metanorma/html/templates/_sourcecode.html.liquid +4 -0
- metadata +16 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class AdmonitionDrop < BlockElementDrop
|
|
7
|
+
def self.from_model(admonition, renderer:)
|
|
8
|
+
type = renderer.safe_attr(admonition, :type) || "note"
|
|
9
|
+
id = renderer.safe_attr(admonition, :id)
|
|
10
|
+
|
|
11
|
+
content_html = renderer.capture_output do
|
|
12
|
+
admonition.paragraphs&.each { |para| renderer.render_paragraph(para) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
new(
|
|
16
|
+
id: id,
|
|
17
|
+
type: type,
|
|
18
|
+
label_html: renderer.escape_html(type.capitalize),
|
|
19
|
+
content_html: content_html,
|
|
20
|
+
css_class: "admonition #{type}",
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class BlockElementDrop < Liquid::Drop
|
|
7
|
+
attr_reader :id, :type, :label_html, :content_html, :css_class
|
|
8
|
+
|
|
9
|
+
def initialize(attrs = {})
|
|
10
|
+
attrs.each { |k, v| instance_variable_set(:"@#{k}", v) }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Subclasses override to build from model + RendererContext
|
|
14
|
+
def self.from_model(_model, renderer:)
|
|
15
|
+
raise NotImplementedError, "#{name} must implement .from_model"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class ExampleDrop < BlockElementDrop
|
|
7
|
+
def self.from_model(example, renderer:)
|
|
8
|
+
id = renderer.safe_attr(example, :id)
|
|
9
|
+
label = renderer.extract_block_label(example, "EXAMPLE")
|
|
10
|
+
|
|
11
|
+
content_html = renderer.capture_output do
|
|
12
|
+
if example.paragraphs && !example.paragraphs.empty?
|
|
13
|
+
example.paragraphs.each { |para| renderer.render_paragraph(para) }
|
|
14
|
+
end
|
|
15
|
+
example.ul&.each { |ul| renderer.render_unordered_list(ul) }
|
|
16
|
+
example.ol&.each { |ol| renderer.render_ordered_list(ol) }
|
|
17
|
+
example.dl&.each { |dl| renderer.render_definition_list(dl) }
|
|
18
|
+
example.sourcecode&.each { |sc| renderer.render_sourcecode(sc) }
|
|
19
|
+
example.table&.each { |t| renderer.render_table(t) }
|
|
20
|
+
example.figure&.each { |f| renderer.render_figure(f) }
|
|
21
|
+
example.quote&.each { |q| renderer.render_quote(q) }
|
|
22
|
+
example.formula&.each { |f| renderer.render_formula(f) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
new(
|
|
26
|
+
id: id,
|
|
27
|
+
label_html: renderer.escape_html(label),
|
|
28
|
+
content_html: content_html,
|
|
29
|
+
css_class: "example",
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class FigureDrop < BlockElementDrop
|
|
7
|
+
attr_reader :image_html, :caption_html, :key_html, :sub_figures_html
|
|
8
|
+
|
|
9
|
+
def self.from_model(figure, renderer:)
|
|
10
|
+
id = renderer.safe_attr(figure, :id)
|
|
11
|
+
fig_name = renderer.safe_attr(figure, :fmt_name) || renderer.safe_attr(figure, :name)
|
|
12
|
+
if id && fig_name
|
|
13
|
+
renderer.register_figure_entry(id: id, text: renderer.extract_plain_text(fig_name))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
image_html = renderer.capture_output do
|
|
17
|
+
if figure.image
|
|
18
|
+
renderer.render_image(figure.image)
|
|
19
|
+
elsif renderer.safe_attr(figure, :source)
|
|
20
|
+
src = renderer.safe_attr(figure, :source)
|
|
21
|
+
@output << %(<img src="#{renderer.escape_html(src)}" />)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
caption_html = if fig_name || renderer.safe_attr(figure, :name)
|
|
26
|
+
renderer.capture_output do
|
|
27
|
+
el = renderer.safe_attr(figure, :fmt_name) || figure.name
|
|
28
|
+
renderer.render_inline_element(el)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
sub_figures_html = renderer.capture_output do
|
|
33
|
+
figure.figure&.each { |sub| renderer.render_figure(sub) }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
key_html = renderer.capture_output do
|
|
37
|
+
renderer.safe_attr(figure, :note)&.each { |n| renderer.render_note(n) }
|
|
38
|
+
renderer.safe_attr(figure, :dl)&.then { |dl| renderer.render_definition_list(dl) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
new(
|
|
42
|
+
id: id,
|
|
43
|
+
image_html: image_html,
|
|
44
|
+
caption_html: caption_html,
|
|
45
|
+
key_html: key_html,
|
|
46
|
+
sub_figures_html: sub_figures_html,
|
|
47
|
+
css_class: "figure",
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class FormulaDrop < BlockElementDrop
|
|
7
|
+
attr_reader :stem_html, :where_html, :number_html
|
|
8
|
+
|
|
9
|
+
def self.from_model(formula, renderer:)
|
|
10
|
+
id = renderer.safe_attr(formula, :id)
|
|
11
|
+
|
|
12
|
+
stem_html = renderer.capture_output do
|
|
13
|
+
renderer.render_stem_content(formula.stem) if formula.stem
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
where_html = renderer.capture_output do
|
|
17
|
+
if formula.key
|
|
18
|
+
if formula.key.dl
|
|
19
|
+
@output = renderer.capture_output {}
|
|
20
|
+
# "where" label rendered in template, just render the dl
|
|
21
|
+
renderer.render_definition_list(formula.key.dl)
|
|
22
|
+
end
|
|
23
|
+
formula.key.p&.each { |para| renderer.render_paragraph(para) }
|
|
24
|
+
end
|
|
25
|
+
formula.dl&.then { |dl| renderer.render_definition_list(dl) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
name_el = renderer.safe_attr(formula, :fmt_name) || renderer.safe_attr(formula, :name)
|
|
29
|
+
number_html = if name_el
|
|
30
|
+
renderer.capture_output { renderer.render_inline_element(name_el) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
new(
|
|
34
|
+
id: id,
|
|
35
|
+
stem_html: stem_html,
|
|
36
|
+
where_html: where_html,
|
|
37
|
+
number_html: number_html,
|
|
38
|
+
css_class: "formula",
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class NoteDrop < BlockElementDrop
|
|
7
|
+
def self.from_model(note, renderer:)
|
|
8
|
+
id = renderer.safe_attr(note, :id)
|
|
9
|
+
label = renderer.extract_block_label(note, "NOTE")
|
|
10
|
+
|
|
11
|
+
content_html = renderer.capture_output do
|
|
12
|
+
if note.content && !note.content.empty?
|
|
13
|
+
note.content.each { |para| renderer.render_paragraph(para) }
|
|
14
|
+
else
|
|
15
|
+
renderer.render_mixed_inline(note)
|
|
16
|
+
end
|
|
17
|
+
note.ul&.each { |ul| renderer.render_unordered_list(ul) }
|
|
18
|
+
note.ol&.each { |ol| renderer.render_ordered_list(ol) }
|
|
19
|
+
note.dl&.then { |dl| renderer.render_definition_list(dl) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
new(
|
|
23
|
+
id: id,
|
|
24
|
+
label_html: renderer.escape_html(label),
|
|
25
|
+
content_html: content_html,
|
|
26
|
+
css_class: "note-block",
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Html
|
|
5
|
+
module Drops
|
|
6
|
+
class SourcecodeDrop < BlockElementDrop
|
|
7
|
+
attr_reader :lang, :name_html, :code_html
|
|
8
|
+
|
|
9
|
+
def self.from_model(sc, renderer:)
|
|
10
|
+
id = renderer.safe_attr(sc, :id)
|
|
11
|
+
lang = renderer.safe_attr(sc, :lang)
|
|
12
|
+
|
|
13
|
+
name_html = if sc.name
|
|
14
|
+
renderer.capture_output { renderer.render_inline_element(sc.name) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
code_text = if sc.body&.content
|
|
18
|
+
sc.body.content
|
|
19
|
+
elsif sc.content
|
|
20
|
+
sc.content
|
|
21
|
+
else
|
|
22
|
+
""
|
|
23
|
+
end
|
|
24
|
+
raw_text = code_text.gsub("<", "<").gsub(">", ">").gsub("&", "&").gsub(""", "\"")
|
|
25
|
+
|
|
26
|
+
new(
|
|
27
|
+
id: id,
|
|
28
|
+
lang: lang,
|
|
29
|
+
name_html: name_html,
|
|
30
|
+
code_html: renderer.escape_html(raw_text),
|
|
31
|
+
css_class: "sourcecode",
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/metanorma/html/drops.rb
CHANGED
|
@@ -4,6 +4,13 @@ module Metanorma
|
|
|
4
4
|
module Html
|
|
5
5
|
module Drops
|
|
6
6
|
autoload :FootnoteDrop, "metanorma/html/drops/footnote_drop"
|
|
7
|
+
autoload :BlockElementDrop, "metanorma/html/drops/block_element_drop"
|
|
8
|
+
autoload :NoteDrop, "metanorma/html/drops/note_drop"
|
|
9
|
+
autoload :AdmonitionDrop, "metanorma/html/drops/admonition_drop"
|
|
10
|
+
autoload :ExampleDrop, "metanorma/html/drops/example_drop"
|
|
11
|
+
autoload :SourcecodeDrop, "metanorma/html/drops/sourcecode_drop"
|
|
12
|
+
autoload :FormulaDrop, "metanorma/html/drops/formula_drop"
|
|
13
|
+
autoload :FigureDrop, "metanorma/html/drops/figure_drop"
|
|
7
14
|
end
|
|
8
15
|
end
|
|
9
16
|
end
|