metanorma-document 0.2.12 → 0.3.0

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.
@@ -6,30 +6,18 @@ module Metanorma
6
6
  module HtmlRenderers
7
7
  module MarkRenderers
8
8
  def self.register(registry)
9
- registry.register_mark_handler("emphasis", ->(inner, _mark) {
10
- HtmlRenderers.wrap(:em, inner)
11
- })
12
- registry.register_mark_handler("strong", ->(inner, _mark) {
13
- HtmlRenderers.wrap(:strong, inner)
14
- })
15
- registry.register_mark_handler("subscript", ->(inner, _mark) {
16
- HtmlRenderers.wrap(:sub, inner)
17
- })
18
- registry.register_mark_handler("superscript", ->(inner, _mark) {
19
- HtmlRenderers.wrap(:sup, inner)
20
- })
21
- registry.register_mark_handler("code", ->(inner, _mark) {
22
- HtmlRenderers.wrap(:code, inner)
23
- })
24
- registry.register_mark_handler("underline", ->(inner, _mark) {
25
- HtmlRenderers.wrap(:u, inner)
26
- })
27
- registry.register_mark_handler("strike", ->(inner, _mark) {
28
- HtmlRenderers.wrap(:s, inner)
29
- })
30
- registry.register_mark_handler("smallcap", ->(inner, _mark) {
31
- HtmlRenderers.wrap(:span, inner, style: "font-variant: small-caps")
32
- })
9
+ # Simple-wrap marks: tag and attrs come from the shared Catalog
10
+ # so the Model-side renderer and the XML-side RichHtmlRenderer
11
+ # agree on HTML output.
12
+ Handlers::Inline::Catalog::SIMPLE_WRAPS.each do |mark_type, spec|
13
+ tag = spec[:tag]
14
+ attrs = spec.except(:tag)
15
+ registry.register_mark_handler(mark_type, ->(inner, _mark) {
16
+ HtmlRenderers.wrap(tag, inner, **attrs)
17
+ })
18
+ end
19
+
20
+ # Dynamic marks: attrs come from mark.attrs per instance.
33
21
  registry.register_mark_handler("link", ->(inner, mark) {
34
22
  HtmlRenderers.wrap(:a, inner, href: mark.attrs["href"] || "#")
35
23
  })
@@ -37,19 +25,8 @@ module Metanorma
37
25
  HtmlRenderers.wrap(:a, inner, href: "##{mark.attrs['target'] || ''}")
38
26
  })
39
27
  registry.register_mark_handler("eref", ->(inner, mark) {
40
- HtmlRenderers.wrap(:a, inner, class: "eref", cite: mark.attrs["citeas"] || "")
41
- })
42
- registry.register_mark_handler("footnote", ->(inner, _mark) {
43
- HtmlRenderers.wrap(:sup, inner, class: "footnote-inline")
44
- })
45
- registry.register_mark_handler("stem", ->(inner, _mark) {
46
- HtmlRenderers.wrap(:span, inner, class: "stem")
47
- })
48
- registry.register_mark_handler("concept", ->(inner, _mark) {
49
- HtmlRenderers.wrap(:span, inner, class: "concept")
50
- })
51
- registry.register_mark_handler("bcp14", ->(inner, _mark) {
52
- HtmlRenderers.wrap(:span, inner, class: "bcp14")
28
+ HtmlRenderers.wrap(:a, inner, class: "eref",
29
+ cite: mark.attrs["citeas"] || "")
53
30
  })
54
31
  registry.register_mark_handler("span", ->(inner, mark) {
55
32
  cls = mark.attrs["class_attr"]
@@ -3,20 +3,108 @@
3
3
  module Metanorma
4
4
  module Mirror
5
5
  class Transformer
6
- def initialize(registry: Mirror.default_registry, id_strategy: Mirror::DEFAULT_ID_STRATEGY)
6
+ attr_reader :registry, :id_strategy
7
+
8
+ def initialize(registry: Mirror.default_registry,
9
+ id_strategy: Mirror::DEFAULT_ID_STRATEGY)
7
10
  @registry = registry
8
11
  @id_strategy = id_strategy
9
12
  end
10
13
 
14
+ def call(root)
15
+ attrs = {}
16
+ attrs[:flavor] = root.flavor if root.flavor
17
+ attrs[:type] = root.type if root.type
18
+ attrs[:schema_version] = root.schema_version if root.schema_version
19
+
20
+ title = extract_root_title(root)
21
+ attrs[:title] = title if title
22
+
23
+ content = []
24
+
25
+ preface = root.preface
26
+ if preface
27
+ result = @registry.handle(preface, context: self)
28
+ result.append_to(content)
29
+ end
30
+
31
+ sections = root.sections
32
+ if sections
33
+ result = @registry.handle(sections, context: self)
34
+ result.append_to(content)
35
+ end
36
+
37
+ annex = root.annex
38
+ annex&.each do |a|
39
+ result = @registry.handle(a, context: self)
40
+ result.append_to(content)
41
+ end
42
+
43
+ bibliography = root.bibliography
44
+ if bibliography
45
+ result = @registry.handle(bibliography, context: self)
46
+ result.append_to(content)
47
+ end
48
+
49
+ Handlers.build_node("doc", attrs: attrs, content: content)
50
+ end
51
+
11
52
  def from_metanorma(root)
12
- document = MetanormaToMirror.new(registry: @registry,
13
- id_strategy: @id_strategy).call(root)
53
+ document = call(root)
14
54
  @id_strategy.finalize!(document)
15
55
  end
16
56
 
17
57
  def rewrite(mirror_node)
18
58
  Rewriter.new.call(mirror_node)
19
59
  end
60
+
61
+ def extract_blocks(element)
62
+ content = []
63
+
64
+ element.each_mixed_content do |node|
65
+ next if node.is_a?(String)
66
+
67
+ result = @registry.handle(node, context: self)
68
+ result.append_to(content)
69
+ end
70
+ content
71
+ end
72
+
73
+ def extract_section_children(element)
74
+ content = []
75
+ %i[clause terms definitions references floating_title].each do |attr|
76
+ collection = SafeAttr.read(element, attr)
77
+ next unless collection
78
+
79
+ collection.each do |child|
80
+ result = @registry.handle(child, context: self)
81
+ result.append_to(content)
82
+ end
83
+ end
84
+ content
85
+ end
86
+
87
+ def extract_named_collections(element, collection_attrs)
88
+ content = []
89
+ collection_attrs.each do |attr|
90
+ collection = SafeAttr.read(element, attr)
91
+ next unless collection
92
+
93
+ collection.each do |child|
94
+ result = @registry.handle(child, context: self)
95
+ result.append_to(content)
96
+ end
97
+ end
98
+ content
99
+ end
100
+
101
+ def text_node(text, marks: [])
102
+ Handlers.build_text(text, marks: marks)
103
+ end
104
+
105
+ def extract_root_title(root)
106
+ Metadata.title_from_bibdata(SafeAttr.read(root, :bibdata))
107
+ end
20
108
  end
21
109
  end
22
110
  end
@@ -10,7 +10,6 @@ module Metanorma
10
10
  autoload :Model, "#{__dir__}/mirror/model"
11
11
  autoload :HandlerResult, "#{__dir__}/mirror/handler_result"
12
12
  autoload :Transformer, "#{__dir__}/mirror/transformer"
13
- autoload :MetanormaToMirror, "#{__dir__}/mirror/metanorma_to_mirror"
14
13
  autoload :Rewriter, "#{__dir__}/mirror/rewriter"
15
14
  autoload :HandlerRegistry, "#{__dir__}/mirror/handler_registry"
16
15
  autoload :Handlers, "#{__dir__}/mirror/handlers"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-document
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-07-17 00:00:00.000000000 Z
11
+ date: 2026-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: relaton-bib
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.0.pre.alpha.1
48
+ - - "<"
46
49
  - !ruby/object:Gem::Version
47
- version: '2.1'
50
+ version: 2.3.0
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.2.0.pre.alpha.1
58
+ - - "<"
53
59
  - !ruby/object:Gem::Version
54
- version: '2.1'
60
+ version: 2.3.0
55
61
  description: A Ruby library for representing and processing Metanorma document XML,
56
62
  providing a comprehensive model for standards documents with support for various
57
63
  metadata, content blocks, and structured markup.
@@ -650,6 +656,8 @@ files:
650
656
  - lib/metanorma/html/drops/note_drop.rb
651
657
  - lib/metanorma/html/drops/sourcecode_drop.rb
652
658
  - lib/metanorma/html/drops/toc_entry_drop.rb
659
+ - lib/metanorma/html/flavor.rb
660
+ - lib/metanorma/html/flavor_registry.rb
653
661
  - lib/metanorma/html/generator.rb
654
662
  - lib/metanorma/html/icc_renderer.rb
655
663
  - lib/metanorma/html/iec_renderer.rb
@@ -661,8 +669,10 @@ files:
661
669
  - lib/metanorma/html/ogc_renderer.rb
662
670
  - lib/metanorma/html/oiml_renderer.rb
663
671
  - lib/metanorma/html/pdfa_renderer.rb
672
+ - lib/metanorma/html/renderer_delegation.rb
664
673
  - lib/metanorma/html/renderers.rb
665
674
  - lib/metanorma/html/renderers/block_renderer.rb
675
+ - lib/metanorma/html/renderers/element_order_traversal.rb
666
676
  - lib/metanorma/html/renderers/inline_renderer.rb
667
677
  - lib/metanorma/html/renderers/pubid_renderer.rb
668
678
  - lib/metanorma/html/renderers/section_renderer.rb
@@ -842,6 +852,7 @@ files:
842
852
  - lib/metanorma/mirror/handlers/figure.rb
843
853
  - lib/metanorma/mirror/handlers/formula.rb
844
854
  - lib/metanorma/mirror/handlers/inline.rb
855
+ - lib/metanorma/mirror/handlers/inline/catalog.rb
845
856
  - lib/metanorma/mirror/handlers/inline/rich_html_renderer.rb
846
857
  - lib/metanorma/mirror/handlers/inline/text_extractor.rb
847
858
  - lib/metanorma/mirror/handlers/list.rb
@@ -859,7 +870,6 @@ files:
859
870
  - lib/metanorma/mirror/id_strategy/preserve.rb
860
871
  - lib/metanorma/mirror/math_util.rb
861
872
  - lib/metanorma/mirror/metadata.rb
862
- - lib/metanorma/mirror/metanorma_to_mirror.rb
863
873
  - lib/metanorma/mirror/model.rb
864
874
  - lib/metanorma/mirror/model/container.rb
865
875
  - lib/metanorma/mirror/model/factory.rb
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Metanorma
4
- module Mirror
5
- class MetanormaToMirror
6
- attr_reader :registry, :id_strategy
7
-
8
- def initialize(registry: Mirror.default_registry,
9
- id_strategy: Mirror.DEFAULT_ID_STRATEGY)
10
- @registry = registry
11
- @id_strategy = id_strategy
12
- end
13
-
14
- def call(root)
15
- attrs = {}
16
- attrs[:flavor] = root.flavor if root.flavor
17
- attrs[:type] = root.type if root.type
18
- attrs[:schema_version] = root.schema_version if root.schema_version
19
-
20
- title = extract_root_title(root)
21
- attrs[:title] = title if title
22
-
23
- content = []
24
-
25
- preface = root.preface
26
- if preface
27
- result = @registry.handle(preface, context: self)
28
- result.append_to(content)
29
- end
30
-
31
- sections = root.sections
32
- if sections
33
- result = @registry.handle(sections, context: self)
34
- result.append_to(content)
35
- end
36
-
37
- annex = root.annex
38
- annex&.each do |a|
39
- result = @registry.handle(a, context: self)
40
- result.append_to(content)
41
- end
42
-
43
- bibliography = root.bibliography
44
- if bibliography
45
- result = @registry.handle(bibliography, context: self)
46
- result.append_to(content)
47
- end
48
-
49
- Handlers.build_node("doc", attrs: attrs, content: content)
50
- end
51
-
52
- def extract_blocks(element)
53
- content = []
54
-
55
- element.each_mixed_content do |node|
56
- next if node.is_a?(String)
57
-
58
- result = @registry.handle(node, context: self)
59
- result.append_to(content)
60
- end
61
- content
62
- end
63
-
64
- def extract_section_children(element)
65
- content = []
66
- %i[clause terms definitions references floating_title].each do |attr|
67
- collection = SafeAttr.read(element, attr)
68
- next unless collection
69
-
70
- collection.each do |child|
71
- result = @registry.handle(child, context: self)
72
- result.append_to(content)
73
- end
74
- end
75
- content
76
- end
77
-
78
- def extract_named_collections(element, collection_attrs)
79
- content = []
80
- collection_attrs.each do |attr|
81
- collection = SafeAttr.read(element, attr)
82
- next unless collection
83
-
84
- collection.each do |child|
85
- result = @registry.handle(child, context: self)
86
- result.append_to(content)
87
- end
88
- end
89
- content
90
- end
91
-
92
- def text_node(text, marks: [])
93
- Handlers.build_text(text, marks: marks)
94
- end
95
-
96
- def extract_root_title(root)
97
- Metadata.title_from_bibdata(SafeAttr.read(root, :bibdata))
98
- end
99
- end
100
- end
101
- end