isodoc 3.7.16 → 3.7.18

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: b3701ef0c0696c15bc2dd4ca2e53ebd2ac8d6537ae1c42753aa70b7ccb393b5b
4
- data.tar.gz: 5247ea712405f4e65a076ed7895e942a0ca358862cac8b6287df3be86750c5e2
3
+ metadata.gz: 78cb90e0e0fea60ab1ebfc166b51618d39abf17d345de2237a2b841acf9e0dff
4
+ data.tar.gz: 4a3828eb99a8e58d62ce6a77a26adceee9e40e5ac58d16c5501d17fdbbb861b5
5
5
  SHA512:
6
- metadata.gz: ec06723c5b0546f8ab2addd40595875ace2b48dcded48de5844828f48dcb50752369739093a916cf37057da485c6b32c93a038dbd67da12ed375fa56bf756bbe
7
- data.tar.gz: fca0121441106e42448442384648e1e8362c91518ebddc5b0454ef0886ff1661a3c631f2ee9e8f0d03065b88a5dfdb4430546397a479234f69068c39268198e5
6
+ metadata.gz: f81f19086e763fca68dc8b1ad70b325592eeac99945628f81e16fadebed2b6e010df91cccf0b27d8232a62d769514a1bcbac2a9f907bbda3f0a2e3ed39fcd73f
7
+ data.tar.gz: 6349cad368a56fe08aad86ea77825ef72aff7947828dcb955cec2aadec17911df52607ef0a3c1a57f6742157654025e0b4aa71146682354b8d80c32dd18a461c
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "moxml"
4
+ require "relaton"
5
+ require "relaton/bib"
6
+
7
+ module IsoDoc
8
+ # Bibdata ingestion through relaton's library surface, not Relaton::Cli.
9
+ #
10
+ # Same pattern as Metanorma::Collection::Config::BibdataParser
11
+ # (metanorma/metanorma#716), which mirrors the flavor dispatch of
12
+ # relaton cli.rb parse_xml: the processor is named by the first
13
+ # docidentifier's type, else by the leading word of its text. It takes
14
+ # an XML String, so it behaves the same on relaton releases before and
15
+ # after 3.1.6, where Cli.parse_xml changed from a Nokogiri document to a
16
+ # String argument.
17
+ module BibdataParser
18
+ class << self
19
+ # @param xml [String] serialized bibdata or bibitem XML
20
+ # @return [Relaton::Bib::ItemData, nil] nil when the source is not
21
+ # parseable XML
22
+ def from_xml(xml)
23
+ return unless xml
24
+
25
+ doc = Moxml.new.parse(xml)
26
+ plain = without_namespaces(doc)
27
+ processor = processor_for_xml(doc)
28
+ processor ? processor.from_xml(plain) : generic_from_xml(plain)
29
+ rescue Moxml::ParseError
30
+ nil
31
+ end
32
+
33
+ private
34
+
35
+ # No-flavor fallback: unparseable sources degrade to a nil bibdata,
36
+ # as in the mirrored Cli method.
37
+ def generic_from_xml(plain)
38
+ Relaton::Bib::Item.from_xml(plain)
39
+ rescue StandardError
40
+ nil
41
+ end
42
+
43
+ # The processor named by the first docidentifier's type, else by
44
+ # the first word of its text.
45
+ def processor_for_xml(doc)
46
+ docid = doc.xpath("//*[local-name()='docidentifier']").first
47
+ return unless docid
48
+
49
+ get_proc(docid) ||
50
+ Relaton::Db::Registry.instance.by_type(docid.text[/^\w+/])
51
+ end
52
+
53
+ def get_proc(docid)
54
+ type = docid["type"]
55
+ return unless type
56
+
57
+ Relaton::Db::Registry.instance.by_type(type)
58
+ end
59
+
60
+ # The root element as XML, with every element and attribute in no
61
+ # namespace (`xml:` attributes keep their prefix). The lutaml-model
62
+ # mappings are namespace-free, and Moxml cannot drop a namespace in
63
+ # place, so this builds a copy.
64
+ def without_namespaces(doc)
65
+ plain = Moxml.new.create_document
66
+ plain.add_child plain_element(plain, doc.root)
67
+ plain.root.to_xml
68
+ end
69
+
70
+ def plain_element(doc, src)
71
+ elm = doc.create_element(src.name)
72
+ # An attribute in no namespace wins over a prefixed one of the
73
+ # same local name (`type` over `a:type`).
74
+ src.attributes.sort_by { |a| a.namespace ? 0 : 1 }.each do |attr|
75
+ elm[plain_name(attr)] = attr.value
76
+ end
77
+ src.children.each { |child| elm.add_child plain_node(doc, child) }
78
+ elm
79
+ end
80
+
81
+ # The local name; an `xml:` attribute keeps its prefix.
82
+ def plain_name(attr)
83
+ attr.namespace&.prefix == "xml" ? "xml:#{attr.name}" : attr.name
84
+ end
85
+
86
+ # An entity reference (`&nbsp;`) stays as its text: lutaml-model
87
+ # cannot read an entity it has no declaration for. A processing
88
+ # instruction becomes an empty text.
89
+ def plain_node(doc, src)
90
+ case src
91
+ when Moxml::Element then plain_element(doc, src)
92
+ when Moxml::Cdata then doc.create_cdata(src.content)
93
+ when Moxml::Text then doc.create_text(src.content)
94
+ when Moxml::Comment then doc.create_comment(src.content)
95
+ when Moxml::EntityReference then doc.create_text("&#{src.name};")
96
+ else doc.create_text("")
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -3,7 +3,7 @@ module IsoDoc
3
3
  module Footnotes
4
4
  def make_table_footnote_link(out, fnid, node)
5
5
  attrs = { href: "##{fnid}", class: "TableFootnoteRef" }
6
- sup = node.at(ns(".//sup")) and sup.replace(sup.children)
6
+ sup = node&.at(ns(".//sup")) and sup.replace(sup.children)
7
7
  out.a(**attrs) do |a|
8
8
  children_parse(node, a)
9
9
  end
@@ -1,6 +1,6 @@
1
1
  require "relaton"
2
2
  require "relaton/bib"
3
- require "relaton/cli"
3
+ require_relative "bibdata_parser"
4
4
 
5
5
  module IsoDoc
6
6
  class BibdataConfig < ::Lutaml::Model::Serializable
@@ -16,12 +16,12 @@ module IsoDoc
16
16
  to: :bibdata_to_xml }
17
17
  end
18
18
 
19
+ # Through relaton's library surface, as metanorma#716 does for
20
+ # collections. Under the moxml/leptris adapter the mapping node's
21
+ # native is not Nokogiri, so go through markup.
19
22
  def bibdata_from_xml(model, node)
20
23
  node or return
21
- # Cli.parse_xml's contract is a Nokogiri::XML::Document
22
- # (remove_namespaces!, at); under the moxml/leptris adapter the
23
- # mapping node's native is not Nokogiri. Convert via markup.
24
- model.bibdata = Relaton::Cli.parse_xml(Nokogiri::XML(node.to_xml))
24
+ model.bibdata = BibdataParser.from_xml(node.to_xml)
25
25
  end
26
26
 
27
27
  def bibdata_to_xml(model, parent, doc); end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "3.7.16".freeze
2
+ VERSION = "3.7.18".freeze
3
3
  end
@@ -10,7 +10,7 @@ module IsoDoc
10
10
  def dt_parse(dterm, term)
11
11
  term.p(**attr_code(WORD_DT_ATTRS)) do |p|
12
12
  if dterm.elements.empty?
13
- p << dterm.text
13
+ p.text dterm.text
14
14
  else
15
15
  dterm.children.each { |n| parse(n, p) }
16
16
  end
@@ -78,9 +78,20 @@ module IsoDoc
78
78
  # <title>), semx-wrapped, so that xrefstyle=full can render
79
79
  # "Table 3, caption" the way clauses render "Clause 6, Title". Returns nil
80
80
  # when the asset has no caption, so anchor_xref_full falls back to short.
81
+ #
82
+ # Footnote references are dropped from the captured caption: this
83
+ # capture is taken while parsing the anchors, before the footnote
84
+ # numbering passes have inserted fmt-fn-label into any copy of the
85
+ # caption. Embedding it into xrefstyle=full cross-reference text
86
+ # would inject footnote references that no fmt-fn-label numbering
87
+ # pass ever reaches, which the HTML/DOC renderers cannot resolve
88
+ # (and would duplicate the caption's own footnote marker in
89
+ # unrelated text).
81
90
  def asset_title(node)
82
91
  n = node.at(ns("./name")) || node.at(ns("./title")) or return nil
83
- semx(node, n.children.to_xml, n.name)
92
+ c = n.dup
93
+ c.xpath(ns(".//fn | .//fmt-fn-label")).each(&:remove)
94
+ semx(node, c.children.to_xml, n.name)
84
95
  end
85
96
 
86
97
  include ::IsoDoc::XrefGen::Util
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.16
4
+ version: 3.7.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-14 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -270,6 +270,7 @@ files:
270
270
  - lib/isodoc/base_style/scripts.html
271
271
  - lib/isodoc/base_style/typography.css
272
272
  - lib/isodoc/base_style/typography.scss
273
+ - lib/isodoc/bibdata_parser.rb
273
274
  - lib/isodoc/class_utils.rb
274
275
  - lib/isodoc/common.rb
275
276
  - lib/isodoc/convert.rb