metanorma-document 0.5.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 327323438369aca0879bcfd2556b9de423e78121abb553eeb92bae8010871c4e
4
- data.tar.gz: 61d1c5e8020b823c678f528189465d2df5fa234435b8f60a2ea61da0329c96c6
3
+ metadata.gz: 82bac7c730c60f7fa121afd4d4278380019eea11c7331254453c986cc988da95
4
+ data.tar.gz: 889dab00a67c3d56c2ce7e284da7a7b6bca13d952efc43b405bbb553837ef87b
5
5
  SHA512:
6
- metadata.gz: bde230705b324432565d10b68a7e570252c787dbe4ea388bddc8a1d89b4dabb57aad2c79ecfe34a077311a5f90436b3c12140c828099447b2a844531192225cc
7
- data.tar.gz: 758cb7e3ac461c0c778fcc721e90bea016400609004de98907a3076c1229723adf1e77b270e9a4ff83688fb4a9aa722d23496aade611d809f821a7b640579cbb
6
+ metadata.gz: 5d3fee68271cacc7e090d70b07b920202bec1d50129f5365d97140c4ba66efd6225628f8fc08ae2aa8c9b4b9925eaee5ad3450a1475560f7728c54df1de284db
7
+ data.tar.gz: 75b2af965e8ad9d792711d5393fd0c98fdcedcf3b73bb50cf4210faeb7a2f7b901caac32cfc4822738eb6e0c51cbca7b17a43d2ef6cc635bcde2dfdfa27ad84e
@@ -37,7 +37,7 @@
37
37
  [data-theme="dark"] .code-copy-btn { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
38
38
  [data-theme="dark"] .table-scroll-wrapper { box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
39
39
  [data-theme="dark"] .caption-label, [data-theme="dark"] .fmt-caption-label { color: #a8b4e0; }
40
- [data-theme="dark"] .term-number { color: #a8b4e0; }
40
+ [data-theme="dark"] .TermNum { color: #a8b4e0; }
41
41
  [data-theme="dark"] .term-name { color: var(--color-text); }
42
42
  [data-theme="dark"] div[id^="term-"] { border-top-color: #4a5a9a; }
43
43
  [data-theme="dark"] .term-source { border-top-color: var(--color-border); }
@@ -100,7 +100,7 @@
100
100
  [data-theme="sepia"] .cover-stage p { border-color: rgba(255,255,255,0.2); }
101
101
  [data-theme="sepia"] .code-copy-btn { background: rgba(0,0,0,0.15); border-color: rgba(255,255,255,0.1); }
102
102
  [data-theme="sepia"] .caption-label, [data-theme="sepia"] .fmt-caption-label { color: #6b4423; }
103
- [data-theme="sepia"] .term-number { color: #6b4423; }
103
+ [data-theme="sepia"] .TermNum { color: #6b4423; }
104
104
  [data-theme="sepia"] .term-name { color: #6b4423; }
105
105
  [data-theme="sepia"] div[id^="term-"] { border-top-color: #a67c20; }
106
106
  [data-theme="sepia"] h1 { border-bottom-color: var(--color-border); }
@@ -159,7 +159,7 @@
159
159
  [data-theme="oled"] .cover-stage p { border-color: #222; }
160
160
  [data-theme="oled"] .code-copy-btn { background: rgba(255,255,255,0.04); border-color: #1a1a1a; }
161
161
  [data-theme="oled"] .caption-label, [data-theme="oled"] .fmt-caption-label { color: #c0c0c0; }
162
- [data-theme="oled"] .term-number { color: #c0c0c0; }
162
+ [data-theme="oled"] .TermNum { color: #c0c0c0; }
163
163
  [data-theme="oled"] .term-name { color: #d0d0d0; }
164
164
  [data-theme="oled"] div[id^="term-"] { border-top-color: #222; }
165
165
  [data-theme="oled"] h1 { border-bottom-color: #1a1a1a; }
@@ -26,7 +26,7 @@
26
26
  h1, h2, h3, h4, h5, h6 { page-break-after: avoid; break-after: avoid; }
27
27
  .note-block, .example, .admonition, .formula, figure, table { page-break-inside: avoid; break-inside: avoid; }
28
28
  .caption-label, .fmt-caption-label { color: #000; padding: 0; }
29
- .term-number { color: #000; padding: 0; }
29
+ .TermNum { color: #000; padding: 0; }
30
30
  div[id^="term-"] { border-top: 2px solid #666; background: none; box-shadow: none; }
31
31
  .formula-number { background: none; border: none; color: #000; padding: 0; }
32
32
  .doc-title::after { display: none; }
@@ -9,13 +9,15 @@ div[id^="term-"] {
9
9
  }
10
10
  div[id^="term-"] + div[id^="term-"] { margin-top: 0; }
11
11
 
12
- .term-number {
12
+ /* TermNum is a heading (h2/h3 by nesting depth, per isodoc term_header) */
13
+ .TermNum {
13
14
  font-variant: small-caps;
14
15
  font-weight: 600;
15
16
  color: var(--mn-primary);
16
17
  background: none;
17
18
  padding: 0;
18
- font-size: 0.88em;
19
+ margin: 0 0 0.4em;
20
+ font-size: 0.95em;
19
21
  }
20
22
  .term-name { font-size: 1.1em; color: var(--mn-primary); font-weight: 500; }
21
23
  .term-name dfn { font-style: normal; }
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Metanorma
4
4
  module Document
5
- VERSION = "0.5.0"
5
+ VERSION = "0.5.1"
6
6
  Version = VERSION
7
7
  end
8
8
  end
@@ -125,6 +125,7 @@ module Metanorma
125
125
  def render_note_children(...) = @renderer.render_note_children(...)
126
126
  def render_simple_children(...) = @renderer.render_simple_children(...)
127
127
  def render_full_block_children(...) = @renderer.render_full_block_children(...)
128
+ def render_label_paragraph(...) = @renderer.render_label_paragraph(...)
128
129
  end
129
130
 
130
131
  def renderer_context
@@ -668,13 +669,20 @@ module Metanorma
668
669
  end
669
670
 
670
671
  def render_block_children(model,
671
- children:)
672
- @block_renderer.render_block_children(model, children: children)
672
+ children:, **)
673
+ @block_renderer.render_block_children(model, children: children, **)
673
674
  end
674
675
 
675
676
  def render_note_children(model) = @block_renderer.render_note_children(model)
676
677
  def render_simple_children(model) = @block_renderer.render_simple_children(model)
677
- def render_full_block_children(model) = @block_renderer.render_full_block_children(model)
678
+
679
+ def render_full_block_children(model, **)
680
+ @block_renderer.render_full_block_children(model, **)
681
+ end
682
+
683
+ def render_label_paragraph(content_html, **)
684
+ @block_renderer.render_label_paragraph(content_html, **)
685
+ end
678
686
 
679
687
  # Section rendering delegation
680
688
  def render_basic_section(section,
@@ -4,11 +4,18 @@ module Metanorma
4
4
  module Html
5
5
  module Drops
6
6
  class ExampleDrop < BlockElementDrop
7
+ LABEL_CLASS = "example-label"
8
+ private_constant :LABEL_CLASS
9
+
7
10
  def self.from_model(example, renderer:)
8
11
  id = renderer.safe_attr(example, :id)
9
12
  label = renderer.extract_block_label(example, "EXAMPLE")
10
13
 
11
- content_html = renderer.render_full_block_children(example) || ""
14
+ content_html = renderer.render_full_block_children(
15
+ example,
16
+ first_paragraph_label: label,
17
+ first_paragraph_label_class: LABEL_CLASS,
18
+ ) || ""
12
19
 
13
20
  new(
14
21
  id: id,
@@ -4,26 +4,53 @@ module Metanorma
4
4
  module Html
5
5
  module Drops
6
6
  class NoteDrop < BlockElementDrop
7
+ LABEL_CLASS = "note-label"
8
+ private_constant :LABEL_CLASS
9
+
7
10
  def self.from_model(note, renderer:)
8
11
  id = renderer.safe_attr(note, :id)
9
12
  label = renderer.extract_block_label(note, "NOTE")
10
13
 
11
14
  content_parts = []
15
+ label_rendered = label.nil?
16
+
12
17
  if note.content && !note.content.empty?
13
18
  note.content.each do |para|
14
- content_parts << (renderer.render_paragraph(para) || "")
19
+ if label_rendered
20
+ content_parts << (renderer.render_paragraph(para) || "")
21
+ else
22
+ content_parts << (renderer.render_paragraph(para,
23
+ label: label,
24
+ label_class: LABEL_CLASS) || "")
25
+ label_rendered = true
26
+ end
15
27
  end
16
28
  else
17
29
  inline = renderer.render_mixed_inline(note)
18
- content_parts << inline if inline
30
+ if inline
31
+ if label_rendered
32
+ content_parts << inline
33
+ else
34
+ content_parts << renderer.render_label_paragraph(inline,
35
+ label: label,
36
+ label_class: LABEL_CLASS)
37
+ label_rendered = true
38
+ end
39
+ end
19
40
  end
41
+
20
42
  content_parts << (renderer.render_note_children(note) || "")
21
- content_html = content_parts.join
43
+
44
+ if !label_rendered
45
+ content_parts.unshift(renderer.render_label_paragraph("",
46
+ label: label,
47
+ label_class: LABEL_CLASS))
48
+ end
22
49
 
23
50
  new(
24
51
  id: id,
25
52
  label_html: renderer.escape_html(label),
26
- content_html: content_html,
53
+ content_html: content_parts.join,
27
54
  css_class: "note-block",
28
55
  )
29
56
  end
@@ -34,7 +34,7 @@ module Metanorma
34
34
  @coordinator = coordinator
35
35
  end
36
36
 
37
- def render_paragraph(p, **_opts)
37
+ def render_paragraph(p, label: nil, label_class: nil, **_opts)
38
38
  attrs = element_attrs(id: safe_attr(p, :id),
39
39
  style: coordinator.alignment_style(safe_attr(p,
40
40
  :alignment)))
@@ -42,6 +42,21 @@ module Metanorma
42
42
  render_liquid("_paragraph.html.liquid", {
43
43
  "attrs" => attrs,
44
44
  "content" => content,
45
+ "label" => label,
46
+ "label_class" => label_class,
47
+ })
48
+ end
49
+
50
+ # Wraps an already-rendered HTML fragment in a `<p>` opened by the
51
+ # given label span. Used by NoteDrop / ExampleDrop when a note has
52
+ # no paragraph child to host the label (e.g. inline-only content or
53
+ # an empty note). All markup is emitted by `_paragraph.html.liquid`.
54
+ def render_label_paragraph(content_html, label:, label_class:)
55
+ render_liquid("_paragraph.html.liquid", {
56
+ "attrs" => "",
57
+ "content" => content_html,
58
+ "label" => label,
59
+ "label_class" => label_class,
45
60
  })
46
61
  end
47
62
 
@@ -354,16 +369,33 @@ module Metanorma
354
369
  })
355
370
  end
356
371
 
357
- def render_block_children(model, children:)
372
+ def render_block_children(model, children:, first_paragraph_label: nil,
373
+ first_paragraph_label_class: nil)
358
374
  parts = []
375
+ label_applied = first_paragraph_label.nil?
376
+
359
377
  children.each do |attr, render_method|
360
378
  values = safe_attr(model, attr)
361
379
  next if values.nil?
362
380
 
363
381
  Array(values).each do |v|
364
- parts << (public_send(render_method, v) || "")
382
+ if !label_applied && render_method == :render_paragraph
383
+ parts << (render_paragraph(v,
384
+ label: first_paragraph_label,
385
+ label_class: first_paragraph_label_class) || "")
386
+ label_applied = true
387
+ else
388
+ parts << (public_send(render_method, v) || "")
389
+ end
365
390
  end
366
391
  end
392
+
393
+ unless label_applied
394
+ parts.unshift(render_label_paragraph("",
395
+ label: first_paragraph_label,
396
+ label_class: first_paragraph_label_class))
397
+ end
398
+
367
399
  parts.join
368
400
  end
369
401
 
@@ -375,8 +407,11 @@ module Metanorma
375
407
  render_block_children(model, children: SIMPLE_CHILDREN)
376
408
  end
377
409
 
378
- def render_full_block_children(model)
379
- render_block_children(model, children: BLOCK_CHILDREN)
410
+ def render_full_block_children(model, first_paragraph_label: nil,
411
+ first_paragraph_label_class: nil)
412
+ render_block_children(model, children: BLOCK_CHILDREN,
413
+ first_paragraph_label: first_paragraph_label,
414
+ first_paragraph_label_class: first_paragraph_label_class)
380
415
  end
381
416
 
382
417
  private
@@ -100,7 +100,7 @@ module Metanorma
100
100
  parts << (render_standard_section_blocks(section, level) || "")
101
101
  parts << (render_subsections(section, level) || "") if with_subsections
102
102
  if with_terms
103
- section.terms&.each { |term| parts << (render_term(term) || "") }
103
+ section.terms&.each { |term| parts << (render_term(term, level: level + 1) || "") }
104
104
  end
105
105
  render_liquid("_element.html.liquid", {
106
106
  "tag" => "div",
@@ -164,13 +164,14 @@ module Metanorma
164
164
  # (StandardDocument::Terms::Term) and presentation-aware models with
165
165
  # fmt-* attributes (IsoDocument::Terms::IsoTerm): safe_attr returns nil
166
166
  # for attributes a model does not declare, so the fmt-* branches are
167
- # skipped automatically on semantic-only models.
168
- def render_term(term, **_opts)
167
+ # skipped automatically on semantic-only models. +level+ is the term's
168
+ # TermNum heading level (section level + 1, per isodoc's term_header).
169
+ def render_term(term, level: 2, **_opts)
169
170
  attrs = element_attrs(id: safe_attr(term, :id), **term_data_attrs(term))
170
171
  fmt_definition = safe_attr(term, :fmt_definition)
171
172
 
172
173
  parts = []
173
- parts << (render_term_number(term) || "")
174
+ parts << (render_term_number(term, level: level) || "")
174
175
  parts << render_term_designations(term, :fmt_preferred, :preferred,
175
176
  "preferred")
176
177
  parts << render_term_designations(term, :fmt_admitted, :admitted,
@@ -185,7 +186,7 @@ module Metanorma
185
186
  safe_attr(term, :admonition)&.each do |admonition|
186
187
  parts << (render_admonition(admonition) || "")
187
188
  end
188
- safe_attr(term, :term)&.each { |sub| parts << (render_term(sub) || "") }
189
+ safe_attr(term, :term)&.each { |sub| parts << (render_term(sub, level: level + 1) || "") }
189
190
  render_liquid("_element.html.liquid", {
190
191
  "tag" => "div",
191
192
  "extra_attrs" => attrs,
@@ -206,11 +207,15 @@ module Metanorma
206
207
  data_attrs
207
208
  end
208
209
 
209
- def render_term_number(term)
210
+ # The term number renders as a TermNum HEADING one level below the
211
+ # enclosing section heading (isodoc term_header postprocess: p.TermNum
212
+ # becomes h(parent+1), so top-level terms get h2, nested terms h3+).
213
+ def render_term_number(term, level: 2)
210
214
  fmt_name = safe_attr(term, :fmt_name)
211
215
  term_number = safe_attr(term, :term_number)
212
216
  if fmt_name
213
217
  render_liquid("_term_number.html.liquid", {
218
+ "level" => [level, 6].min,
214
219
  "content" => render_inline_element(fmt_name),
215
220
  })
216
221
  elsif term_number
@@ -220,6 +225,7 @@ module Metanorma
220
225
  extract_text_value(term_number)
221
226
  end
222
227
  render_liquid("_term_number.html.liquid", {
228
+ "level" => [level, 6].min,
223
229
  "content" => escape_html(number_text),
224
230
  })
225
231
  end
@@ -1,3 +1,3 @@
1
1
  <div{% if block.id %} id="{{ block.id }}"{% endif %} class="{{ block.css_class }}">
2
- <span class="example-label">{{ block.label_html }}</span>&nbsp;{{ block.content_html }}
2
+ {{ block.content_html }}
3
3
  </div>
@@ -1,3 +1,3 @@
1
1
  <div{% if block.id %} id="{{ block.id }}"{% endif %} class="{{ block.css_class }}">
2
- <span class="note-label">{{ block.label_html }}</span>&nbsp;{{ block.content_html }}
2
+ {{ block.content_html }}
3
3
  </div>
@@ -1 +1 @@
1
- <p{{ attrs }}>{{ content }}</p>
1
+ <p{{ attrs }}>{% if label %}<span class="{{ label_class }}">{{ label }}</span>&nbsp;{% endif %}{{ content }}</p>
@@ -1 +1 @@
1
- <p class="term-number">{{ content }}</p>
1
+ <h{{ level }} class="TermNum">{{ content }}</h{{ level }}>
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.5.0
4
+ version: 0.5.1
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-21 00:00:00.000000000 Z
11
+ date: 2026-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model