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 +4 -4
- data/lib/isodoc/bibdata_parser.rb +101 -0
- data/lib/isodoc/function/footnotes.rb +1 -1
- data/lib/isodoc/metadata_bibdata.rb +5 -5
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/lists.rb +1 -1
- data/lib/isodoc/xref/xref_anchor.rb +12 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 78cb90e0e0fea60ab1ebfc166b51618d39abf17d345de2237a2b841acf9e0dff
|
|
4
|
+
data.tar.gz: 4a3828eb99a8e58d62ce6a77a26adceee9e40e5ac58d16c5501d17fdbbb861b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 (` `) 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
data/lib/isodoc/version.rb
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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-
|
|
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
|