metanorma-iso 3.5.44 → 3.5.46
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/TODO.docx/P0-005-word-unreadable-content.md +3 -1
- data/TODO.docx/P3-007-verify-word-opens.md +4 -1
- data/lib/isodoc/iso/docx/adapter.rb +7 -0
- data/lib/isodoc/iso/docx/core_properties_builder.rb +6 -9
- data/lib/isodoc/iso/docx/custom_xml_items.rb +129 -0
- data/lib/isodoc/iso/docx/importer/front_matter.rb +164 -0
- data/lib/isodoc/iso/docx/importer/reader.rb +144 -0
- data/lib/isodoc/iso/docx/importer.rb +20 -0
- data/lib/isodoc/iso/docx.rb +1 -0
- data/lib/metanorma/iso/log.rb +0 -2
- data/lib/metanorma/iso/validation/rules/base.rb +22 -9
- data/lib/metanorma/iso/validation/rules/style_a_or_an_rule.rb +5 -4
- data/lib/metanorma/iso/validation/rules/style_assure_ensure_rule.rb +74 -19
- data/lib/metanorma/iso/validation/rules/style_non_si_order_rule.rb +39 -36
- data/lib/metanorma/iso/validation/rules/style_rule.rb +16 -2
- data/lib/metanorma/iso/validation/rules/style_words_digits_rule.rb +27 -13
- data/lib/metanorma/iso/validation/rules.rb +0 -2
- data/lib/metanorma/iso/validation/unit_tokens.rb +225 -0
- data/lib/metanorma/iso/validation.rb +1 -0
- data/lib/metanorma/iso/validation_policy/metanorma.yml +0 -2
- data/lib/metanorma/iso/version.rb +1 -1
- metadata +6 -2
- data/lib/metanorma/iso/validation/rules/style_abbrev_articles_rule.rb +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf78c30be6277e0ce4617f3c595d9f384ad6608791b6e932b6fdb8ca131f9eed
|
|
4
|
+
data.tar.gz: 37a36b75e451d11ed9979b8f65248e967628c3f2c96ca51e1bd116fe53645d60
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09f54138e874d23a49148a4094d0fd6f5fcfeec2fa41ff563d940ed3c5e8955e086b3583dbae4991ba717101e3fb54ad11f68e5b3bd9cedfe0e5092d8e4b7c48'
|
|
7
|
+
data.tar.gz: 81cd7a05bc855de03810b143f0d9ededd4f151bae0b4f9313beb02cdc26644f5a8aec8d9f8342c4120351cd10adef9bbafbb23a58c7c31fcf8d5c50ec95f35c0
|
|
@@ -49,7 +49,9 @@ the documented one-process render (metanorma-iso v3.5.42 worktree, deps in
|
|
|
49
49
|
other files … update the fields?" yes/no prompt on open. It is the
|
|
50
50
|
deliberate `w:updateFields` set by the ToC builder so Word refreshes
|
|
51
51
|
cached ToC page numbers; answering Yes refreshes, No keeps them. It is
|
|
52
|
-
not the corrupt-file dialog.
|
|
52
|
+
not the corrupt-file dialog. (Superseded in 3.5.44: `w:updateFields` is
|
|
53
|
+
dropped outright — c2f4e88e — Word auto-evaluates the ToC's PAGEREF
|
|
54
|
+
fields during on-open pagination either way, so the prompt is gone.)
|
|
53
55
|
|
|
54
56
|
### Strict OOXML (transitional schema) findings — none Word-blocking
|
|
55
57
|
|
|
@@ -44,7 +44,10 @@ Generated: `data/rice_fixed9.docx`
|
|
|
44
44
|
may refer to other files. Do you want to update the fields in this
|
|
45
45
|
document?" — driven by the deliberate `w:updateFields` from the ToC
|
|
46
46
|
builder so Word refreshes cached ToC page numbers. Not a corruption
|
|
47
|
-
warning; answering either way opens the document.
|
|
47
|
+
warning; answering either way opens the document. (Superseded in
|
|
48
|
+
3.5.44: `w:updateFields` is dropped outright — c2f4e88e — because Word
|
|
49
|
+
auto-evaluates the ToC's PAGEREF fields during on-open pagination with
|
|
50
|
+
or without the flag, so the prompt no longer appears at all.)
|
|
48
51
|
- Test-placement caveat for future manual runs: do not open test
|
|
49
52
|
artifacts from `/tmp` — after answering Yes, macOS asks Word to grant
|
|
50
53
|
access to /tmp, which Word cannot. Use a user folder (the baselines
|
|
@@ -5,6 +5,7 @@ require "metanorma/document"
|
|
|
5
5
|
# Resolves to the canonical copy in lib/metanorma/iso/document.rb (this gem's
|
|
6
6
|
# lib precedes metanorma-document's lib in $LOAD_PATH).
|
|
7
7
|
require "metanorma/iso/document"
|
|
8
|
+
require_relative "custom_xml_items"
|
|
8
9
|
|
|
9
10
|
module IsoDoc
|
|
10
11
|
module Iso
|
|
@@ -116,6 +117,7 @@ module IsoDoc
|
|
|
116
117
|
visit_root(doc_model, doc)
|
|
117
118
|
apply_custom_properties(doc_model, doc)
|
|
118
119
|
apply_core_properties(doc_model, doc)
|
|
120
|
+
apply_custom_xml(doc) unless mhtml_output?(output_path)
|
|
119
121
|
save_document(doc.model, output_path)
|
|
120
122
|
end
|
|
121
123
|
|
|
@@ -126,6 +128,7 @@ module IsoDoc
|
|
|
126
128
|
visit_root(model, doc)
|
|
127
129
|
apply_custom_properties(model, doc)
|
|
128
130
|
apply_core_properties(model, doc)
|
|
131
|
+
apply_custom_xml(doc) unless mhtml_output?(output_path)
|
|
129
132
|
save_document(doc.model, output_path)
|
|
130
133
|
end
|
|
131
134
|
|
|
@@ -648,6 +651,10 @@ module IsoDoc
|
|
|
648
651
|
doc.model.core_properties = CorePropertiesBuilder.new(model).build
|
|
649
652
|
end
|
|
650
653
|
|
|
654
|
+
def apply_custom_xml(doc)
|
|
655
|
+
CustomXmlItems.new.apply(doc.model)
|
|
656
|
+
end
|
|
657
|
+
|
|
651
658
|
# ── Root-level visitors ────────────────────────────────────────
|
|
652
659
|
#
|
|
653
660
|
# The document has three sections with different page numbering:
|
|
@@ -12,7 +12,7 @@ module IsoDoc
|
|
|
12
12
|
#
|
|
13
13
|
# Properties set:
|
|
14
14
|
# dc:title — composed English title (intro/main/part)
|
|
15
|
-
# dc:creator —
|
|
15
|
+
# dc:creator — organization abbreviation or name
|
|
16
16
|
# cp:lastModifiedBy — same as dc:creator
|
|
17
17
|
# cp:revision — version draft number from bibdata (defaults to "1")
|
|
18
18
|
# dcterms:created — first created/published/issued date from bibdata
|
|
@@ -60,7 +60,7 @@ module IsoDoc
|
|
|
60
60
|
org = copyright_owner_organization ||
|
|
61
61
|
contributor_organization_with_role("publisher") ||
|
|
62
62
|
contributor_organization_with_role("author")
|
|
63
|
-
|
|
63
|
+
org_label(org, :abbreviation) || org_label(org, :name) || DEFAULT_CREATOR
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# Word refuses to open a package whose cp:revision is not a
|
|
@@ -124,14 +124,11 @@ module IsoDoc
|
|
|
124
124
|
role.to_s == expected
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
def
|
|
128
|
-
return nil unless org
|
|
129
|
-
return nil unless org.class.attributes.key?(:name)
|
|
127
|
+
def org_label(org, attribute)
|
|
128
|
+
return nil unless org && org.class.attributes.key?(attribute)
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
extract_string(names.first)
|
|
130
|
+
value = extract_string(Array(org.public_send(attribute)).first)
|
|
131
|
+
value unless value.to_s.strip.empty?
|
|
135
132
|
end
|
|
136
133
|
|
|
137
134
|
def bibdate_of_type(type_name)
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "securerandom"
|
|
4
|
+
|
|
5
|
+
module IsoDoc
|
|
6
|
+
module Iso
|
|
7
|
+
module Docx
|
|
8
|
+
# The four custom XML stores used by the classic ISO OSD format.
|
|
9
|
+
class CustomXmlItems
|
|
10
|
+
TYPEFI = "http://www.typefi.com"
|
|
11
|
+
METADATA = "http://schemas.microsoft.com/office/2006/metadata"
|
|
12
|
+
PROPERTIES = "#{METADATA}/properties".freeze
|
|
13
|
+
FORMS = "http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"
|
|
14
|
+
CONTENT_TYPE = "#{METADATA}/contentType".freeze
|
|
15
|
+
OFFICE = "http://schemas.openxmlformats.org/officeDocument/2006"
|
|
16
|
+
BIBLIOGRAPHY = "#{OFFICE}/bibliography".freeze
|
|
17
|
+
REL_TYPE = "#{OFFICE}/relationships/customXml".freeze
|
|
18
|
+
XSD = "http://www.w3.org/2001/XMLSchema"
|
|
19
|
+
|
|
20
|
+
class TypefiNamespace < Lutaml::Xml::Namespace
|
|
21
|
+
uri TYPEFI
|
|
22
|
+
prefix_default "t"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class BibliographySources < Uniword::Bibliography::Sources
|
|
26
|
+
xml do
|
|
27
|
+
namespace_scope [{ namespace: TypefiNamespace, declare: :always }]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def apply(document)
|
|
32
|
+
document.custom_xml_items = build
|
|
33
|
+
document.allocator ||= Uniword::Docx::IdAllocator.new
|
|
34
|
+
document.custom_xml_items.each do |item|
|
|
35
|
+
document.allocator.alloc_rid(target: "/#{item.path}", type: REL_TYPE)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def build
|
|
42
|
+
payloads = [
|
|
43
|
+
[document_management, [PROPERTIES]],
|
|
44
|
+
[form_templates, [FORMS]],
|
|
45
|
+
[content_type_schema, [CONTENT_TYPE, XSD, PROPERTIES]],
|
|
46
|
+
[BibliographySources.new.to_xml, [BIBLIOGRAPHY]],
|
|
47
|
+
]
|
|
48
|
+
payloads.map.with_index(1) do |(xml, namespaces), index|
|
|
49
|
+
Uniword::Docx::CustomXmlItem.new(
|
|
50
|
+
index: index, xml_content: xml, props_xml: item_props(namespaces),
|
|
51
|
+
rels_xml: item_relationships(index)
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def document_management
|
|
57
|
+
xml_payload do |xml|
|
|
58
|
+
xml.create_and_add_element("properties", prefix: "m",
|
|
59
|
+
attributes: { "xmlns:m" => PROPERTIES, "xmlns:t" => TYPEFI }) do
|
|
60
|
+
xml.documentManagement do
|
|
61
|
+
xml.create_and_add_element("_Flow_SignoffStatus", prefix: "t")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def form_templates
|
|
68
|
+
xml_payload do |xml|
|
|
69
|
+
xml.FormTemplates("xmlns" => FORMS, "xmlns:t" => TYPEFI) do
|
|
70
|
+
xml.Display
|
|
71
|
+
xml.Edit
|
|
72
|
+
xml.New
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def content_type_schema
|
|
78
|
+
xml_payload do |xml|
|
|
79
|
+
xml.contentTypeSchema("xmlns" => CONTENT_TYPE, "xmlns:t" => TYPEFI) do
|
|
80
|
+
xml.create_and_add_element("schema", prefix: "xs",
|
|
81
|
+
attributes: { "xmlns:xs" => XSD, "targetNamespace" => PROPERTIES }) do
|
|
82
|
+
schema_elements(xml)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def schema_elements(xml)
|
|
89
|
+
schema_element(xml, "element", name: "properties") do
|
|
90
|
+
schema_element(xml, "complexType") do
|
|
91
|
+
schema_element(xml, "sequence") do
|
|
92
|
+
schema_element(xml, "element", name: "documentManagement", type: "xs:anyType")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def schema_element(xml, name, **attributes)
|
|
99
|
+
namespace = xml.current_element.namespace
|
|
100
|
+
xml.create_and_add_element(name, attributes: attributes) do
|
|
101
|
+
# The builder can inherit the enclosing contentTypeSchema's
|
|
102
|
+
# default namespace when attaching a child.
|
|
103
|
+
xml.current_element.namespace = namespace
|
|
104
|
+
yield if block_given?
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def xml_payload(&)
|
|
109
|
+
Lutaml::Xml::Builder::Base.build(engine: :nokogiri, &).to_xml
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def item_props(namespaces)
|
|
113
|
+
refs = (namespaces + [TYPEFI]).map { |uri| Uniword::Customxml::SchemaRef.new(uri: uri) }
|
|
114
|
+
Uniword::Customxml::DataStoreItem.new(
|
|
115
|
+
item_id: "{#{SecureRandom.uuid.upcase}}",
|
|
116
|
+
schema_refs: Uniword::Customxml::SchemaRefs.new(refs: refs),
|
|
117
|
+
).to_xml
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def item_relationships(index)
|
|
121
|
+
relationship = Uniword::Ooxml::Relationships::PackageRelationship.new(
|
|
122
|
+
id: "rId1", type: "#{REL_TYPE}Props", target: "itemProps#{index}.xml",
|
|
123
|
+
)
|
|
124
|
+
Uniword::Ooxml::Relationships::PackageRelationships.new(relationships: [relationship]).to_xml
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module IsoDoc
|
|
4
|
+
module Iso
|
|
5
|
+
module Docx
|
|
6
|
+
class Importer
|
|
7
|
+
# Maps the OSD cover, titles and foreword onto the ISO document model.
|
|
8
|
+
class FrontMatter
|
|
9
|
+
Document = Metanorma::Iso::Document
|
|
10
|
+
Metadata = Document::Metadata
|
|
11
|
+
Relaton = Metanorma::Document::Relaton
|
|
12
|
+
Inline = Metanorma::Document::Components::Inline
|
|
13
|
+
Paragraph = Metanorma::Document::Components::Paragraphs::ParagraphBlock
|
|
14
|
+
|
|
15
|
+
TITLE_TYPES = [
|
|
16
|
+
["intro", "title-intro", Metadata::TitleIntro, :title_intro],
|
|
17
|
+
["main", "title-main", Metadata::TitleMain, :title_main],
|
|
18
|
+
["compl", "title-part", Metadata::TitlePart, :title_part],
|
|
19
|
+
["full", "main", Metadata::TitleFull, :title_full],
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
LANGUAGE_SUFFIX = /\(([a-z]{2,3}|[efr])\)\z/i
|
|
23
|
+
LEGACY_LANGUAGES = { "e" => "en", "f" => "fr", "r" => "ru" }.freeze
|
|
24
|
+
EDITION_ORDINALS = {
|
|
25
|
+
"en" => %w[first second third fourth fifth sixth seventh eighth ninth tenth],
|
|
26
|
+
"fr" => %w[première deuxième troisième quatrième cinquième sixième septième huitième neuvième dixième],
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
FRONT_STYLES = %i[
|
|
30
|
+
cover_large cover_meta cover_title cover_subtitle main_title1 main_title2
|
|
31
|
+
foreword foreword_text
|
|
32
|
+
].freeze
|
|
33
|
+
|
|
34
|
+
def initialize(reader)
|
|
35
|
+
@reader = reader
|
|
36
|
+
@paragraphs = Hash.new { |styles, style| styles[style] = [] }
|
|
37
|
+
mapping = DocxStyleMapping.new(template: :dis)
|
|
38
|
+
styles = FRONT_STYLES.to_h { |key| [mapping.paragraph_style(key), key] }
|
|
39
|
+
reader.each_paragraph do |style, text|
|
|
40
|
+
key = styles[style]
|
|
41
|
+
@paragraphs[key] << text if key
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def build
|
|
46
|
+
Document::Root.new(bibdata: bibliography, preface: preface)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def bibliography
|
|
52
|
+
Metadata::IsoBibliographicItem.new(
|
|
53
|
+
type: "standard", doc_identifier: identifiers,
|
|
54
|
+
language: [Metadata::LanguageElement.new(value: language)],
|
|
55
|
+
edition: editions, date: dates, version: version
|
|
56
|
+
).tap { |bibdata| assign_titles(bibdata) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def identifiers
|
|
60
|
+
reference = cover_reference&.sub(LANGUAGE_SUFFIX, "")&.rstrip
|
|
61
|
+
return [] if reference.to_s.empty?
|
|
62
|
+
|
|
63
|
+
[Metadata::DocIdentifier.new(type: "ISO", primary: true,
|
|
64
|
+
value: reference)]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def cover_reference
|
|
68
|
+
@paragraphs[:cover_large].first
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def language
|
|
72
|
+
code = cover_reference.to_s[LANGUAGE_SUFFIX, 1]&.downcase || "en"
|
|
73
|
+
LEGACY_LANGUAGES.fetch(code, code)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def editions
|
|
77
|
+
text = @paragraphs[:cover_meta].find { |line| /\b[ée]dition\b/i.match?(line) }
|
|
78
|
+
return [] unless text
|
|
79
|
+
|
|
80
|
+
number = edition_number(text)
|
|
81
|
+
localized = Relaton::Edition.new(content: text, language: language)
|
|
82
|
+
return [localized] unless number
|
|
83
|
+
|
|
84
|
+
[Relaton::Edition.new(content: number.to_s), localized]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def edition_number(text)
|
|
88
|
+
digits = text[/\d+/]
|
|
89
|
+
return digits.to_i if digits
|
|
90
|
+
|
|
91
|
+
word = text.downcase[/\A[[:alpha:]]+/]
|
|
92
|
+
return 2 if language == "fr" && word == "seconde"
|
|
93
|
+
|
|
94
|
+
index = EDITION_ORDINALS.fetch(language, []).index(word)
|
|
95
|
+
index + 1 if index
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def dates
|
|
99
|
+
published = @paragraphs[:cover_meta].find { |line| /\A\d{4}-\d{2}(?:-\d{2})?\z/.match?(line) }
|
|
100
|
+
core = @reader.core
|
|
101
|
+
[
|
|
102
|
+
date("published", published),
|
|
103
|
+
date("created", core&.created&.value),
|
|
104
|
+
date("updated", core&.modified&.value),
|
|
105
|
+
].compact
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def date(type, value)
|
|
109
|
+
return if value.to_s.empty?
|
|
110
|
+
|
|
111
|
+
Relaton::BibliographicDate.new(type: type, on: Relaton::DateTime.new(content: value.to_s))
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def version
|
|
115
|
+
revision = @paragraphs[:cover_meta].filter_map { |line| line[/\ADate:\s*(\d{4}-\d{2}-\d{2})\z/i, 1] }.first
|
|
116
|
+
Relaton::VersionInfo.new(revision_date: revision) if revision
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def assign_titles(bibdata)
|
|
120
|
+
localized = Metadata::IsoLocalizedTitle.new(language: language)
|
|
121
|
+
items = TITLE_TYPES.zip(cover_titles).filter_map do |(name, type, klass, slot), fallback|
|
|
122
|
+
title = build_title(name, type, klass, fallback)
|
|
123
|
+
localized.public_send("#{slot}=", title) if title
|
|
124
|
+
title
|
|
125
|
+
end
|
|
126
|
+
bibdata.titles = items
|
|
127
|
+
bibdata.titles.per_language = [localized] unless items.empty?
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def build_title(name, type, klass, fallback)
|
|
131
|
+
text = @reader.custom_title(name)
|
|
132
|
+
text = fallback.to_s if text.empty?
|
|
133
|
+
klass.new(_type: type, language: language, value: text) unless text.empty?
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def cover_titles
|
|
137
|
+
main = @paragraphs[:main_title1].first || @paragraphs[:cover_title].first
|
|
138
|
+
part = @paragraphs[:main_title2].first || @paragraphs[:cover_subtitle].first
|
|
139
|
+
intro, main, inline_part = split_main_title(main)
|
|
140
|
+
part = (part || inline_part)&.sub(/\APart(?:ie)?[[:space:]]+\S+?:[[:space:]]*/i, "")
|
|
141
|
+
full = [intro, main, part].compact.join(" — ")
|
|
142
|
+
full = @reader.core&.title.to_s.strip if full.empty?
|
|
143
|
+
[intro, main, part, full]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def split_main_title(text)
|
|
147
|
+
parts = text.to_s.split("—", 3).map(&:strip).reject(&:empty?)
|
|
148
|
+
parts.size > 1 ? parts : [nil, parts.first]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def preface
|
|
152
|
+
heading = @paragraphs[:foreword].first
|
|
153
|
+
paragraphs = @paragraphs[:foreword_text].map { |text| Paragraph.new(text: [text]) }
|
|
154
|
+
return if heading.nil? && paragraphs.empty?
|
|
155
|
+
|
|
156
|
+
title = Inline::TitleWithAnnotationElement.new(text: [heading]) if heading
|
|
157
|
+
foreword = Document::Sections::IsoForewordSection.new(title: title, paragraphs: paragraphs)
|
|
158
|
+
Document::Sections::IsoPreface.new(foreword: foreword)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module IsoDoc
|
|
4
|
+
module Iso
|
|
5
|
+
module Docx
|
|
6
|
+
class Importer
|
|
7
|
+
# Exposes typed properties and text from top-level styled paragraphs.
|
|
8
|
+
class Reader
|
|
9
|
+
IGNORED_FIELDS = %w[TOC PAGEREF REF].freeze
|
|
10
|
+
|
|
11
|
+
Word = Uniword::Wordprocessingml
|
|
12
|
+
Ooxml = Uniword::Ooxml
|
|
13
|
+
WordNamespace = Ooxml::Namespaces::WordProcessingML
|
|
14
|
+
|
|
15
|
+
# Teach Lutaml about inline smart tags without changing Uniword's
|
|
16
|
+
# shared paragraph mapping. Their contents use the same run mapping.
|
|
17
|
+
class Paragraph < Word::Paragraph
|
|
18
|
+
attribute :smart_tags, self, collection: true, initialize_empty: true
|
|
19
|
+
|
|
20
|
+
xml do
|
|
21
|
+
map_element "smartTag", to: :smart_tags
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Body < Lutaml::Model::Serializable
|
|
26
|
+
attribute :paragraphs, Paragraph, collection: true, initialize_empty: true
|
|
27
|
+
|
|
28
|
+
xml do
|
|
29
|
+
element "body"
|
|
30
|
+
namespace WordNamespace
|
|
31
|
+
map_element "p", to: :paragraphs
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class DocumentPart < Lutaml::Model::Serializable
|
|
36
|
+
attribute :body, Body
|
|
37
|
+
|
|
38
|
+
xml do
|
|
39
|
+
element "document"
|
|
40
|
+
namespace WordNamespace
|
|
41
|
+
map_element "body", to: :body
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
attr_reader :core
|
|
46
|
+
|
|
47
|
+
def initialize(path)
|
|
48
|
+
parts = Uniword::Infrastructure::ZipExtractor.new.extract(path)
|
|
49
|
+
@core = read_part(parts, :core_properties)
|
|
50
|
+
@custom_properties = read_part(parts, :custom_properties)
|
|
51
|
+
@body = document_body(parts)
|
|
52
|
+
@fields = []
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def custom_title(name)
|
|
56
|
+
property = @custom_properties&.properties&.find do |item|
|
|
57
|
+
item.name == name
|
|
58
|
+
end
|
|
59
|
+
property&.value.to_s.strip
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def each_paragraph
|
|
63
|
+
# The body mapping only reads top-level paragraphs, so it skips
|
|
64
|
+
# TOC galleries while retaining content controls within paragraphs.
|
|
65
|
+
Array(@body&.paragraphs).each do |paragraph|
|
|
66
|
+
text = paragraph_text(paragraph).strip
|
|
67
|
+
yield paragraph.style&.value, text unless text.empty?
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def read_part(parts, key)
|
|
74
|
+
definition = Ooxml::PartRegistry.find_by_key(key)
|
|
75
|
+
xml = parts[definition.path]
|
|
76
|
+
definition.loader_model.from_xml(xml) if xml
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def document_body(parts)
|
|
80
|
+
definition = Ooxml::PartRegistry.find_by_key(:document)
|
|
81
|
+
relationships = read_part(parts, :package_rels)&.relationships
|
|
82
|
+
relationship = relationships&.find { |rel| rel.type.to_s.include?(definition.rel_type) }
|
|
83
|
+
xml = parts[relationship&.target&.delete_prefix("/")] || parts[definition.path]
|
|
84
|
+
DocumentPart.from_xml(xml).body if xml
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def paragraph_text(paragraph)
|
|
88
|
+
ordered_text(paragraph, "fldSimple" => paragraph.simple_fields,
|
|
89
|
+
"smartTag" => paragraph.smart_tags)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def ordered_text(container, extra = {})
|
|
93
|
+
elements = {
|
|
94
|
+
"r" => container.runs, "hyperlink" => container.hyperlinks,
|
|
95
|
+
"sdt" => container.sdts
|
|
96
|
+
}.merge(extra).transform_values(&:dup)
|
|
97
|
+
container.element_order.filter_map do |entry|
|
|
98
|
+
element = elements[entry.name]&.shift
|
|
99
|
+
read_element(element) if element
|
|
100
|
+
end.join
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def read_element(element)
|
|
104
|
+
case element
|
|
105
|
+
when Word::Run then read_run(element)
|
|
106
|
+
when Paragraph then paragraph_text(element)
|
|
107
|
+
when Word::StructuredDocumentTag then ordered_text(element.content) if element.content
|
|
108
|
+
when Word::SimpleField
|
|
109
|
+
read_runs(element.runs) unless ignored_field?(element.instr)
|
|
110
|
+
else read_runs(element.runs)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def read_runs(runs)
|
|
115
|
+
runs.map { |run| read_run(run) }.join
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def read_run(run)
|
|
119
|
+
case run.field_char&.fldCharType
|
|
120
|
+
when "begin" then @fields.push(+"")
|
|
121
|
+
when "end" then @fields.pop
|
|
122
|
+
else
|
|
123
|
+
return run_content(run)
|
|
124
|
+
end
|
|
125
|
+
nil
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def run_content(run)
|
|
129
|
+
if run.instr_text
|
|
130
|
+
@fields.last&.concat(run.instr_text.to_s)
|
|
131
|
+
return
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
run.text_string unless @fields.any? { |instruction| ignored_field?(instruction) }
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def ignored_field?(instruction)
|
|
138
|
+
IGNORED_FIELDS.include?(instruction.to_s.split.first&.upcase)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uniword"
|
|
4
|
+
require "metanorma/iso/document"
|
|
5
|
+
|
|
6
|
+
module IsoDoc
|
|
7
|
+
module Iso
|
|
8
|
+
module Docx
|
|
9
|
+
# Reads the front matter of a classic ISO OSD DOCX into the ISO model.
|
|
10
|
+
class Importer
|
|
11
|
+
autoload :Reader, "isodoc/iso/docx/importer/reader"
|
|
12
|
+
autoload :FrontMatter, "isodoc/iso/docx/importer/front_matter"
|
|
13
|
+
|
|
14
|
+
def import(path)
|
|
15
|
+
FrontMatter.new(Reader.new(path)).build
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/isodoc/iso/docx.rb
CHANGED
|
@@ -33,6 +33,7 @@ module IsoDoc
|
|
|
33
33
|
autoload :DocumentProperties, "isodoc/iso/docx/document_properties"
|
|
34
34
|
autoload :FormulaRenderer, "isodoc/iso/docx/formula_renderer"
|
|
35
35
|
autoload :HeaderFooterRenderer, "isodoc/iso/docx/header_footer_renderer"
|
|
36
|
+
autoload :Importer, "isodoc/iso/docx/importer"
|
|
36
37
|
autoload :IndexsectRenderer, "isodoc/iso/docx/indexsect_renderer"
|
|
37
38
|
autoload :InlineRenderers, "isodoc/iso/docx/inline_renderers"
|
|
38
39
|
autoload :InlineRenderer, "isodoc/iso/docx/inline"
|
data/lib/metanorma/iso/log.rb
CHANGED
|
@@ -180,8 +180,6 @@ module Metanorma
|
|
|
180
180
|
severity: 2 },
|
|
181
181
|
ISO_62: { category: "Grammar", error: "%s",
|
|
182
182
|
severity: 2 },
|
|
183
|
-
ISO_63: { category: "Grammar", error: "%s",
|
|
184
|
-
severity: 2 },
|
|
185
183
|
ISO_64: { category: "Abbreviated terms", error: "%s",
|
|
186
184
|
severity: 2 },
|
|
187
185
|
ISO_65: { category: "Abbreviations and contractions", error: "%s",
|
|
@@ -243,18 +243,31 @@ module Metanorma
|
|
|
243
243
|
params[0..-2] + ["#{params.last} #{suffix}"]
|
|
244
244
|
end
|
|
245
245
|
|
|
246
|
-
# Model-based location string for an Issue
|
|
247
|
-
#
|
|
248
|
-
#
|
|
249
|
-
#
|
|
250
|
-
|
|
246
|
+
# Model-based location string for an Issue: "ClassName#id" from
|
|
247
|
+
# the first id-bearing node among +node+ and then +fallbacks+
|
|
248
|
+
# (nearest first); the bare "ClassName" of +node+ when none of
|
|
249
|
+
# them carries an id; nil for a nil +node+. NEVER produces
|
|
250
|
+
# XPath — locations are diagnostic labels, not XML queries.
|
|
251
|
+
#
|
|
252
|
+
# +fallbacks+ locate nodes that never carry an id of their own.
|
|
253
|
+
# The model keeps no parent pointers, so the caller supplies
|
|
254
|
+
# the next-nearest id-bearing candidates. StyleRule passes the
|
|
255
|
+
# scanned paragraph: standoc mints the stable "_<hash>" id on
|
|
256
|
+
# every <p> and never on the enclosing <li>
|
|
257
|
+
# (metanorma-pdfa#133), so a finding raised against a ListItem
|
|
258
|
+
# is located by that paragraph's id — the node the id really
|
|
259
|
+
# belongs to names the label, keeping "ClassName#id" truthful.
|
|
260
|
+
def model_location(node, *fallbacks)
|
|
251
261
|
return nil if node.nil?
|
|
252
262
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
263
|
+
id_owner = [node, *fallbacks].compact.find { |n| read_id(n) }
|
|
264
|
+
return class_label(node) if id_owner.nil?
|
|
265
|
+
|
|
266
|
+
"#{class_label(id_owner)}##{read_id(id_owner)}"
|
|
267
|
+
end
|
|
256
268
|
|
|
257
|
-
|
|
269
|
+
def class_label(node)
|
|
270
|
+
node.class.name.split("::").last
|
|
258
271
|
end
|
|
259
272
|
|
|
260
273
|
# Read +id+ from a model node if (and only if) the node's class
|
|
@@ -10,10 +10,11 @@ module Metanorma
|
|
|
10
10
|
# "a user", "a university", "a one-hour test".
|
|
11
11
|
#
|
|
12
12
|
# Both directions are closed exception lists covering WORDS
|
|
13
|
-
# only
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
13
|
+
# only, and skip all-caps initialisms (their article follows
|
|
14
|
+
# letter-name sounds, a grammar-model question, not a word
|
|
15
|
+
# list). The ISO_63 initialism rule was withdrawn: its hand
|
|
16
|
+
# list mixed both sound classes; initialism article checks
|
|
17
|
+
# return with the grammar-model integration.
|
|
17
18
|
class StyleAOrAnRule < StyleRule
|
|
18
19
|
code "ISO_62"
|
|
19
20
|
|