metanorma-iso 3.5.9 → 3.5.23
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/.gitignore +1 -0
- data/.rubocop.yml +0 -1
- data/Gemfile +3 -1
- data/data/iso-dis/styles.yml +110 -25
- data/data/iso-dis/template.docx +0 -0
- data/data/iso-simple/document_metadata.yml +33 -0
- data/docs/validation-baselines.md +98 -0
- data/docs/validation-rule-kinds.md +80 -0
- data/docs/validation-suppression-authoring.md +119 -0
- data/lib/isodoc/iso/docx/adapter.rb +61 -1
- data/lib/isodoc/iso/docx/box_wrapper.rb +147 -8
- data/lib/isodoc/iso/docx/context.rb +15 -1
- data/lib/isodoc/iso/docx/cover_renderer.rb +253 -7
- data/lib/isodoc/iso/docx/document_properties.rb +6 -1
- data/lib/isodoc/iso/docx/formula_renderer.rb +55 -81
- data/lib/isodoc/iso/docx/inline.rb +139 -9
- data/lib/isodoc/iso/docx/inline_renderers/stem_renderer.rb +30 -7
- data/lib/isodoc/iso/docx/math_conversion.rb +132 -0
- data/lib/isodoc/iso/docx/mhtml_parity.rb +267 -0
- data/lib/isodoc/iso/docx/renderers/bibliography_renderer.rb +18 -0
- data/lib/isodoc/iso/docx/renderers/definition_list_renderer.rb +45 -4
- data/lib/isodoc/iso/docx/renderers/definition_section_renderer.rb +33 -0
- data/lib/isodoc/iso/docx/renderers/example_renderer.rb +18 -11
- data/lib/isodoc/iso/docx/renderers/list_attachments.rb +29 -0
- data/lib/isodoc/iso/docx/renderers/note_renderer.rb +14 -12
- data/lib/isodoc/iso/docx/renderers/ordered_list_renderer.rb +2 -0
- data/lib/isodoc/iso/docx/renderers/unordered_list_renderer.rb +2 -0
- data/lib/isodoc/iso/docx/renderers/walker.rb +12 -2
- data/lib/isodoc/iso/docx/renderers.rb +3 -0
- data/lib/isodoc/iso/docx/toc_builder.rb +120 -36
- data/lib/isodoc/iso/docx.rb +1 -0
- data/lib/isodoc/iso/html/style-human.css +10 -0
- data/lib/isodoc/iso/html/style-iso.css +10 -0
- data/lib/isodoc/iso/html_convert.rb +2 -2
- data/lib/isodoc/iso/isosts_convert.rb +4 -3
- data/lib/isodoc/iso/sts_convert.rb +32 -3
- data/lib/isodoc/iso/word_convert.rb +3 -3
- data/lib/isodoc/iso/word_dis_convert.rb +2 -2
- data/lib/metanorma/iso/base.rb +4 -3
- data/lib/metanorma/iso/cleanup_biblio.rb +1 -1
- data/lib/metanorma/iso/document/sections/iso_terms_section.rb +5 -0
- data/lib/metanorma/iso/log.rb +206 -2
- data/lib/metanorma/iso/processor.rb +33 -33
- data/lib/metanorma/iso/sts/html_renderer/ruby.rb +21 -4
- data/lib/metanorma/iso/sts/output_sanitizer/front_leak_sanitizer.rb +89 -0
- data/lib/metanorma/iso/sts/output_sanitizer/inline_identifier_sanitizer.rb +44 -0
- data/lib/metanorma/iso/sts/output_sanitizer/unique_id_sanitizer.rb +50 -0
- data/lib/metanorma/iso/sts/output_sanitizer.rb +61 -0
- data/lib/metanorma/iso/sts/transformer/block_dispatcher.rb +1 -1
- data/lib/metanorma/iso/sts/transformer/content_text.rb +5 -0
- data/lib/metanorma/iso/sts/transformer/inline_transformer.rb +10 -4
- data/lib/metanorma/iso/sts/transformer/list_transformer.rb +8 -6
- data/lib/metanorma/iso/sts/transformer/source_document.rb +6 -0
- data/lib/metanorma/iso/sts/transformer/term_transformer.rb +29 -16
- data/lib/metanorma/iso/sts.rb +10 -7
- data/lib/metanorma/iso/validate.rb +84 -46
- data/lib/metanorma/iso/validation/citation.rb +50 -0
- data/lib/metanorma/iso/validation/composed_registry.rb +321 -0
- data/lib/metanorma/iso/validation/context.rb +18 -2
- data/lib/metanorma/iso/validation/converter_state.rb +1 -1
- data/lib/metanorma/iso/validation/legacy_policy.rb +248 -0
- data/lib/metanorma/iso/validation/model_validator.rb +16 -2
- data/lib/metanorma/iso/validation/policy_doc.rb +378 -0
- data/lib/metanorma/iso/validation/profile.rb +162 -1
- data/lib/metanorma/iso/validation/profiles/directives.yml +13 -0
- data/lib/metanorma/iso/validation/profiles/house-style-core.yml +11 -0
- data/lib/metanorma/iso/validation/profiles/house-style.yml +18 -0
- data/lib/metanorma/iso/validation/profiles/lists.yml +10 -0
- data/lib/metanorma/iso/validation/profiles/oxford-spelling.yml +11 -0
- data/lib/metanorma/iso/validation/profiles/quality-english.yml +30 -0
- data/lib/metanorma/iso/validation/profiles/referencing.yml +11 -0
- data/lib/metanorma/iso/validation/rules/abbrev_first_use_rule.rb +324 -0
- data/lib/metanorma/iso/validation/rules/asset_cited_first_rule.rb +131 -0
- data/lib/metanorma/iso/validation/rules/base.rb +113 -5
- data/lib/metanorma/iso/validation/rules/broken_xref_rule.rb +9 -5
- data/lib/metanorma/iso/validation/rules/doctype_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/document_order_walk.rb +204 -0
- data/lib/metanorma/iso/validation/rules/foreword_presence_rule.rb +6 -1
- data/lib/metanorma/iso/validation/rules/foreword_structure_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/iteration_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/list_count_rule.rb +5 -2
- data/lib/metanorma/iso/validation/rules/list_depth_rule.rb +5 -2
- data/lib/metanorma/iso/validation/rules/list_punctuation_rule.rb +10 -3
- data/lib/metanorma/iso/validation/rules/locality_erefs_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/modal_in_clause_rule.rb +7 -0
- data/lib/metanorma/iso/validation/rules/normative_bibitem_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/normative_references_presence_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/only_child_clause_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/scope_presence_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/scope_subclauses_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/section_sequence_rule.rb +15 -1
- data/lib/metanorma/iso/validation/rules/see_xrefs_rule.rb +11 -4
- data/lib/metanorma/iso/validation/rules/stem_math.rb +87 -0
- data/lib/metanorma/iso/validation/rules/style_a_or_an_rule.rb +54 -0
- data/lib/metanorma/iso/validation/rules/style_abbrev_articles_rule.rb +44 -0
- data/lib/metanorma/iso/validation/rules/style_abbrev_plural_rule.rb +34 -0
- data/lib/metanorma/iso/validation/rules/style_abbrev_tables_only_rule.rb +36 -0
- data/lib/metanorma/iso/validation/rules/style_abbrev_uppercase_rule.rb +137 -0
- data/lib/metanorma/iso/validation/rules/style_ac_dc_rf_rule.rb +42 -0
- data/lib/metanorma/iso/validation/rules/style_affect_effect_rule.rb +53 -0
- data/lib/metanorma/iso/validation/rules/style_ambig_words_rule.rb +9 -0
- data/lib/metanorma/iso/validation/rules/style_apostrophe_plurals_rule.rb +60 -0
- data/lib/metanorma/iso/validation/rules/style_assure_ensure_rule.rb +82 -0
- data/lib/metanorma/iso/validation/rules/style_bar_knot_footnote_rule.rb +105 -0
- data/lib/metanorma/iso/validation/rules/style_bare_slash_rule.rb +58 -0
- data/lib/metanorma/iso/validation/rules/style_boxed_values_rule.rb +68 -0
- data/lib/metanorma/iso/validation/rules/style_ca_cf_rule.rb +35 -0
- data/lib/metanorma/iso/validation/rules/style_chem_prefix_rule.rb +167 -0
- data/lib/metanorma/iso/validation/rules/style_compliance_rule.rb +32 -0
- data/lib/metanorma/iso/validation/rules/style_contractions_rule.rb +39 -0
- data/lib/metanorma/iso/validation/rules/style_country_names_rule.rb +48 -0
- data/lib/metanorma/iso/validation/rules/style_currency_code_order_rule.rb +65 -0
- data/lib/metanorma/iso/validation/rules/style_currency_symbols_rule.rb +53 -0
- data/lib/metanorma/iso/validation/rules/style_cv_not_rsd_rule.rb +33 -0
- data/lib/metanorma/iso/validation/rules/style_date_duration_rule.rb +66 -0
- data/lib/metanorma/iso/validation/rules/style_date_formats_rule.rb +59 -0
- data/lib/metanorma/iso/validation/rules/style_decimal_comma_rule.rb +81 -0
- data/lib/metanorma/iso/validation/rules/style_directives_refs_rule.rb +78 -0
- data/lib/metanorma/iso/validation/rules/style_eg_etc_rule.rb +73 -0
- data/lib/metanorma/iso/validation/rules/style_eg_placement_rule.rb +73 -0
- data/lib/metanorma/iso/validation/rules/style_empty_clause_rule.rb +95 -0
- data/lib/metanorma/iso/validation/rules/style_en_dash_ranges_rule.rb +66 -0
- data/lib/metanorma/iso/validation/rules/style_family_suite_rule.rb +31 -0
- data/lib/metanorma/iso/validation/rules/style_fewer_less_rule.rb +60 -0
- data/lib/metanorma/iso/validation/rules/style_formulae_rule.rb +30 -0
- data/lib/metanorma/iso/validation/rules/style_guidelines_rule.rb +91 -0
- data/lib/metanorma/iso/validation/rules/style_impersonal_rule.rb +35 -0
- data/lib/metanorma/iso/validation/rules/style_imprecise_refs_rule.rb +37 -0
- data/lib/metanorma/iso/validation/rules/style_in_accordance_rule.rb +69 -0
- data/lib/metanorma/iso/validation/rules/style_inclusive_language_rule.rb +67 -0
- data/lib/metanorma/iso/validation/rules/style_informative_normative_rule.rb +39 -0
- data/lib/metanorma/iso/validation/rules/style_interlab_rule.rb +29 -0
- data/lib/metanorma/iso/validation/rules/style_iso_dates_rule.rb +67 -0
- data/lib/metanorma/iso/validation/rules/style_latin_plurals_rule.rb +62 -0
- data/lib/metanorma/iso/validation/rules/style_mixed_lists_rule.rb +68 -0
- data/lib/metanorma/iso/validation/rules/style_nested_parens_rule.rb +75 -0
- data/lib/metanorma/iso/validation/rules/style_no_boxes_rule.rb +50 -0
- data/lib/metanorma/iso/validation/rules/style_no_nos_rule.rb +37 -0
- data/lib/metanorma/iso/validation/rules/style_non_si_order_rule.rb +129 -0
- data/lib/metanorma/iso/validation/rules/style_number_rule.rb +28 -4
- data/lib/metanorma/iso/validation/rules/style_ordinals_rule.rb +29 -0
- data/lib/metanorma/iso/validation/rules/style_oxford_spelling_rule.rb +156 -0
- data/lib/metanorma/iso/validation/rules/style_penultimate_list_rule.rb +69 -0
- data/lib/metanorma/iso/validation/rules/style_per_cent_rule.rb +30 -0
- data/lib/metanorma/iso/validation/rules/style_plural_s_term_rule.rb +31 -0
- data/lib/metanorma/iso/validation/rules/style_quotation_punctuation_rule.rb +52 -0
- data/lib/metanorma/iso/validation/rules/style_respectively_rule.rb +58 -0
- data/lib/metanorma/iso/validation/rules/style_rule.rb +18 -6
- data/lib/metanorma/iso/validation/rules/style_self_reference_rule.rb +34 -0
- data/lib/metanorma/iso/validation/rules/style_sentence_start_number_rule.rb +62 -0
- data/lib/metanorma/iso/validation/rules/style_stem_symbol_rule.rb +283 -0
- data/lib/metanorma/iso/validation/rules/style_that_which_rule.rb +70 -0
- data/lib/metanorma/iso/validation/rules/style_units_rule.rb +7 -0
- data/lib/metanorma/iso/validation/rules/style_vague_time_rule.rb +42 -0
- data/lib/metanorma/iso/validation/rules/style_verbal_forms_rule.rb +37 -0
- data/lib/metanorma/iso/validation/rules/style_vocab_title_rule.rb +97 -0
- data/lib/metanorma/iso/validation/rules/style_wikipedia_rule.rb +55 -0
- data/lib/metanorma/iso/validation/rules/style_words_digits_rule.rb +168 -0
- data/lib/metanorma/iso/validation/rules/subcommittee_type_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/subpart_iec_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/symbols_in_annex_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules/symbols_section_content_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/symbols_section_count_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/technical_committee_type_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/term_source_complete_rule.rb +117 -0
- data/lib/metanorma/iso/validation/rules/term_xrefs_rule.rb +6 -1
- data/lib/metanorma/iso/validation/rules/termdef_style_rule.rb +38 -11
- data/lib/metanorma/iso/validation/rules/terms_presence_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/title_first_level_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/title_names_doctype_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/title_pairing_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/title_siblings_consistency_rule.rb +5 -0
- data/lib/metanorma/iso/validation/rules/tree_traversal.rb +90 -9
- data/lib/metanorma/iso/validation/rules/unique_id_rule.rb +9 -4
- data/lib/metanorma/iso/validation/rules/unreferenced_assets_rule.rb +8 -3
- data/lib/metanorma/iso/validation/rules/vocab_terms_titles_rule.rb +4 -0
- data/lib/metanorma/iso/validation/rules.rb +154 -2
- data/lib/metanorma/iso/validation/sentence_scan.rb +159 -0
- data/lib/metanorma/iso/validation/walk_cache.rb +81 -0
- data/lib/metanorma/iso/validation.rb +7 -0
- data/lib/metanorma/iso/validation_policy/metanorma.yml +268 -0
- data/lib/metanorma/iso/version.rb +1 -1
- data/lib/tasks/docx_parity.rake +42 -0
- data/metanorma-iso.gemspec +2 -1
- metadata +111 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Suppressing validation warnings in your document
|
|
2
|
+
|
|
3
|
+
Metanorma checks an ISO document against the ISO House Style policy and the
|
|
4
|
+
ISO/IEC Directives, Part 2, and reports every violation with a stable rule
|
|
5
|
+
code such as `ISO_21` or `STANDOC_48`. Some checks do not fit a particular
|
|
6
|
+
document: an annex may legitimately remain unreferenced, or a house may have
|
|
7
|
+
resolved that the generic style findings of one template carry no weight. The
|
|
8
|
+
declarative suppression attributes let the document author silence or
|
|
9
|
+
reclassify named rules for the whole document, and every suppressed entry
|
|
10
|
+
remains visible in an audit category, so a suppression is a recorded decision
|
|
11
|
+
rather than a silent drop.
|
|
12
|
+
|
|
13
|
+
## Rule codes
|
|
14
|
+
|
|
15
|
+
Every finding names its rule code. The codes of the ISO flavour are
|
|
16
|
+
documented, with their policy category, cited wording and severity, in the
|
|
17
|
+
validation policy page that the metanorma-iso gem generates
|
|
18
|
+
(`validation-policy.adoc` and `validation-policy.json`). The code is the
|
|
19
|
+
stable key for all suppression: an author never needs to know which
|
|
20
|
+
implementation kind produces a finding.
|
|
21
|
+
|
|
22
|
+
## The one-line attributes
|
|
23
|
+
|
|
24
|
+
The common cases are one document attribute line. Both take a
|
|
25
|
+
comma-separated list of rule codes.
|
|
26
|
+
|
|
27
|
+
`:validation-off:` stops the named rules from being reported at all:
|
|
28
|
+
|
|
29
|
+
```adoc
|
|
30
|
+
:validation-off: ISO_21, ISO_39
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`:validation-warning:` reclassifies the findings of the named rules as
|
|
34
|
+
warnings, so they still appear but no longer abort the build:
|
|
35
|
+
|
|
36
|
+
```adoc
|
|
37
|
+
:validation-warning: STANDOC_48
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The severities `info`, `warning` and `error` are all available through the
|
|
41
|
+
configuration file, which is the form to use when a document needs a
|
|
42
|
+
reclassification other than these two.
|
|
43
|
+
|
|
44
|
+
## The configuration file
|
|
45
|
+
|
|
46
|
+
A document can carry a suppression configuration file referenced through the
|
|
47
|
+
`:validation-config:` attribute, resolved like `:i18nyaml:`:
|
|
48
|
+
|
|
49
|
+
```adoc
|
|
50
|
+
:validation-config: validation.yml
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The file schema is `metanorma-validation-suppression/1` and is frozen for
|
|
54
|
+
the v1 mechanism. Each entry names a rule code and carries a single
|
|
55
|
+
`severity` action:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
schema: metanorma-validation-suppression/1
|
|
59
|
+
rules:
|
|
60
|
+
ISO_21:
|
|
61
|
+
severity: off
|
|
62
|
+
ISO_39:
|
|
63
|
+
severity: warning
|
|
64
|
+
STANDOC_48:
|
|
65
|
+
severity: info
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The action vocabulary is `off` (the rule is not reported), `info`,
|
|
69
|
+
`warning` and `error` (the rule is reported at that severity). Per-line,
|
|
70
|
+
element-scoped and message-regex exclusions are planned for the coradoc
|
|
71
|
+
era, which provides the line-anchored positions they require.
|
|
72
|
+
|
|
73
|
+
## How the layers resolve
|
|
74
|
+
|
|
75
|
+
The effective configuration is resolved from four layers, each overriding
|
|
76
|
+
the previous one per rule code:
|
|
77
|
+
|
|
78
|
+
1. the engine default, which reports every rule at its registered severity;
|
|
79
|
+
2. the flavour baseline, the `validation_policy/metanorma.yml` file that
|
|
80
|
+
each flavour gem ships (metanorma-iso declares the ISO House Style
|
|
81
|
+
baseline);
|
|
82
|
+
3. the taste overlay, applied when the document selects a taste through the
|
|
83
|
+
`:taste:` attribute or the environment;
|
|
84
|
+
4. the document configuration, through `:validation-config:` or the
|
|
85
|
+
one-line attributes.
|
|
86
|
+
|
|
87
|
+
The resolved effective configuration is dumped into the log with every
|
|
88
|
+
conversion, so a reader of the log can see which layer set each code.
|
|
89
|
+
|
|
90
|
+
## What happens to a suppressed entry
|
|
91
|
+
|
|
92
|
+
A suppressed finding is never deleted. It is moved to the dedicated
|
|
93
|
+
Suppressed category of the log, and each entry carries its original code,
|
|
94
|
+
message, element and the configuration line that suppressed it. The error
|
|
95
|
+
file gains a Suppressed section, so reviewers see what the author silenced
|
|
96
|
+
and can challenge it. Counting suppressed entries in CI arrives with the
|
|
97
|
+
second phase of the mechanism (`--fail-on-suppressed`).
|
|
98
|
+
|
|
99
|
+
The older `log-filter-severity`, `log-filter-category`, `log-filter-error-ids`,
|
|
100
|
+
`log-filter-error-regex` and `log-filter-error-loc` attributes are
|
|
101
|
+
deprecated: they map onto this configuration internally, and they were the
|
|
102
|
+
only suppression lever that removed entries silently.
|
|
103
|
+
|
|
104
|
+
## Worked example
|
|
105
|
+
|
|
106
|
+
An author working on an ISO technical report finds that the build fails on
|
|
107
|
+
findings the document intentionally carries: a Scope that contains
|
|
108
|
+
subclauses (`ISO_39`), and a stream of generic House Style findings
|
|
109
|
+
(`STANDOC_48`) that the drafting team has already dispositioned. The author
|
|
110
|
+
adds one line to the document header:
|
|
111
|
+
|
|
112
|
+
```adoc
|
|
113
|
+
:validation-off: ISO_39
|
|
114
|
+
:validation-warning: STANDOC_48
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The build now reports the House Style findings as warnings, and the Scope
|
|
118
|
+
finding no longer appears; both decisions are recorded in the Suppressed
|
|
119
|
+
section of the error file for the reviewer to confirm.
|
|
@@ -61,6 +61,8 @@ module IsoDoc
|
|
|
61
61
|
Renderers::TermsSectionRenderer],
|
|
62
62
|
[Metanorma::Iso::Document::Sections::IsoClauseSection,
|
|
63
63
|
Renderers::ClauseRenderer],
|
|
64
|
+
[Metanorma::Standoc::Document::Sections::DefinitionSection,
|
|
65
|
+
Renderers::DefinitionSectionRenderer],
|
|
64
66
|
[Metanorma::Standoc::Document::Sections::StandardReferencesSection,
|
|
65
67
|
Renderers::ReferencesRenderer],
|
|
66
68
|
[Metanorma::Document::Components::Sections::ReferencesSection,
|
|
@@ -84,6 +86,9 @@ module IsoDoc
|
|
|
84
86
|
Renderers::NullRenderer],
|
|
85
87
|
].freeze
|
|
86
88
|
|
|
89
|
+
# Output extensions routed through the MHTML save path.
|
|
90
|
+
MHTML_EXTENSIONS = [".doc", ".mht", ".mhtml"].freeze
|
|
91
|
+
|
|
87
92
|
# @param template [Symbol] :dis or :simple (default :dis)
|
|
88
93
|
# @param template_path [String, nil] explicit template DOCX path
|
|
89
94
|
# @param style_mapping_config [String, nil] explicit YAML config path
|
|
@@ -266,12 +271,67 @@ module IsoDoc
|
|
|
266
271
|
end
|
|
267
272
|
|
|
268
273
|
def save_document(model, output_path)
|
|
269
|
-
|
|
274
|
+
if mhtml_output?(output_path)
|
|
275
|
+
save_mhtml(model, output_path)
|
|
276
|
+
else
|
|
277
|
+
Uniword::DocumentWriter.new(model).save(output_path)
|
|
278
|
+
end
|
|
270
279
|
rescue StandardError => e
|
|
271
280
|
warn "[metanorma-iso] DOCX save failed: #{e.message}"
|
|
272
281
|
raise
|
|
273
282
|
end
|
|
274
283
|
|
|
284
|
+
# Uniword's DocumentWriter MHTML route converts a bare DocumentRoot
|
|
285
|
+
# without its relationships part, so every external hyperlink loses
|
|
286
|
+
# its URL resolution and is dropped whole from the MHTML output —
|
|
287
|
+
# the cover contact block's email/website lines came out empty.
|
|
288
|
+
# Route MHTML saves through OoxmlToMhtmlConverter's relationships
|
|
289
|
+
# parameter instead, preserving the hyperlink relationships that
|
|
290
|
+
# the DOCX path keeps.
|
|
291
|
+
def save_mhtml(model, output_path)
|
|
292
|
+
mhtml_doc = Uniword::Transformation::OoxmlToMhtmlConverter
|
|
293
|
+
.document_to_mht(model, model.core_properties,
|
|
294
|
+
merged_document_relationships(model))
|
|
295
|
+
Uniword::Infrastructure::MimePackager
|
|
296
|
+
.from_document(mhtml_doc).package(output_path)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# The relationships part for MHTML rendering: the loaded template
|
|
300
|
+
# rels plus the rels the IdAllocator registered during rendering.
|
|
301
|
+
# Builder-added relationships (hyperlinks, images) are merged into
|
|
302
|
+
# the saved rels part only by the DOCX reconciler, so on the MHTML
|
|
303
|
+
# path the merge happens here (same target-dedup rule as
|
|
304
|
+
# Docx::Reconciler::PackageStructure#append_allocator_rels).
|
|
305
|
+
def merged_document_relationships(model)
|
|
306
|
+
allocated = Array(model.allocator&.all_rels(scope: :document))
|
|
307
|
+
return model.document_rels if allocated.empty?
|
|
308
|
+
|
|
309
|
+
base = model.document_rels
|
|
310
|
+
rels = Array(base&.relationships).map do |rel|
|
|
311
|
+
Uniword::Ooxml::Relationships::PackageRelationship.new(
|
|
312
|
+
id: rel.id,
|
|
313
|
+
type: rel.type,
|
|
314
|
+
target: rel.target,
|
|
315
|
+
target_mode: rel.target_mode,
|
|
316
|
+
)
|
|
317
|
+
end
|
|
318
|
+
targets = rels.filter_map(&:target)
|
|
319
|
+
allocated.reject { |e| targets.include?(e[:target]) }
|
|
320
|
+
.each do |entry|
|
|
321
|
+
rels << Uniword::Ooxml::Relationships::PackageRelationship.new(
|
|
322
|
+
id: entry[:id],
|
|
323
|
+
type: entry[:type],
|
|
324
|
+
target: entry[:target],
|
|
325
|
+
target_mode: entry[:target_mode],
|
|
326
|
+
)
|
|
327
|
+
end
|
|
328
|
+
Uniword::Ooxml::Relationships::PackageRelationships.new(relationships: rels)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def mhtml_output?(path)
|
|
332
|
+
MHTML_EXTENSIONS.include?(File.extname(path).downcase)
|
|
333
|
+
end
|
|
334
|
+
|
|
275
335
|
def parse_xml(source)
|
|
276
336
|
xml = case source
|
|
277
337
|
when String
|
|
@@ -3,19 +3,51 @@
|
|
|
3
3
|
module IsoDoc
|
|
4
4
|
module Iso
|
|
5
5
|
module Docx
|
|
6
|
-
#
|
|
6
|
+
# Shared layout helpers for renderers that present a labelled
|
|
7
|
+
# block (Note, Example, Admonition).
|
|
7
8
|
#
|
|
8
|
-
#
|
|
9
|
-
# notes, examples, warnings:
|
|
10
|
-
# Box-begin — empty paragraph marking the start
|
|
11
|
-
# Box-title — optional title (e.g., "Note 1", "EXAMPLE 1")
|
|
12
|
-
# Box-end — empty paragraph marking the end
|
|
9
|
+
# Two layout contracts live here:
|
|
13
10
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
11
|
+
# [Era C box] (+with_box+) — Box-begin / Box-title / Box-end
|
|
12
|
+
# paragraphs draw a grey box around the content. Admonitions
|
|
13
|
+
# (caution, warning, important) keep this look.
|
|
14
|
+
#
|
|
15
|
+
# [XSL inline label] (+with_inline_label+) — mirrors the
|
|
16
|
+
# iso.international-standard.xsl NOTE/EXAMPLE contract: the
|
|
17
|
+
# label ("NOTE 1", "EXAMPLE") runs inline at the head of the
|
|
18
|
+
# first body paragraph — no border, no shading, no separate
|
|
19
|
+
# title paragraph. When the first child is not a plain
|
|
20
|
+
# paragraph (table, definition list, sourcecode first, ...),
|
|
21
|
+
# the label gets its own keep-with-next paragraph, mirroring
|
|
22
|
+
# the XSL "block" mode where the name is displayed as a
|
|
23
|
+
# separate block (example-name-style keep-with-next="always").
|
|
16
24
|
module BoxWrapper
|
|
17
25
|
include ModelUtils
|
|
18
26
|
|
|
27
|
+
# Gap between the label and the body. The XSL reserves
|
|
28
|
+
# padding-right on the label inline (6mm for notes, 5mm for
|
|
29
|
+
# examples); a single space keeps the ragged inline flow —
|
|
30
|
+
# wrapped lines return to the left margin, as in the PDF.
|
|
31
|
+
LABEL_GAP = " "
|
|
32
|
+
|
|
33
|
+
# Model classes whose presence anywhere in a block forces the
|
|
34
|
+
# XSL "block" mode for EXAMPLES (.//table or .//dl) and makes a
|
|
35
|
+
# paragraph unsuitable for inline-label merging. Sourcecode as
|
|
36
|
+
# the FIRST child triggers block mode in the XSL as well.
|
|
37
|
+
BLOCK_CHILD_CLASSES = [
|
|
38
|
+
Metanorma::Document::Components::Tables::TableBlock,
|
|
39
|
+
Metanorma::Document::Components::Lists::DefinitionList,
|
|
40
|
+
].freeze
|
|
41
|
+
|
|
42
|
+
PLAIN_PARAGRAPH_CLASS =
|
|
43
|
+
Metanorma::Document::Components::Paragraphs::ParagraphBlock
|
|
44
|
+
|
|
45
|
+
# Attributes carrying the rendered label ("NOTE 1", "EXAMPLE")
|
|
46
|
+
# and its cross-reference label. The XSL treats these specially
|
|
47
|
+
# (label inline / name block), so they are never part of the
|
|
48
|
+
# block-child walk.
|
|
49
|
+
LABEL_ATTRS = %i[fmt_name fmt_xref_label name].freeze
|
|
50
|
+
|
|
19
51
|
# Yield a block that appends body paragraphs to +doc+.
|
|
20
52
|
# Wraps the block's output with Box-begin before and Box-end after.
|
|
21
53
|
# If +title_text+ is provided, inserts a Box-title paragraph
|
|
@@ -27,6 +59,33 @@ module IsoDoc
|
|
|
27
59
|
doc << box_paragraph(:box_end)
|
|
28
60
|
end
|
|
29
61
|
|
|
62
|
+
# Inline-label layout for the XSL note/example contract.
|
|
63
|
+
#
|
|
64
|
+
# +style_key+ is the paragraph style for the label-carrying
|
|
65
|
+
# first paragraph (full width — the XSL renders the first
|
|
66
|
+
# body element inline after the label at the container margin).
|
|
67
|
+
def with_inline_label(node, doc, style_key)
|
|
68
|
+
children = block_children(node)
|
|
69
|
+
first = children.first
|
|
70
|
+
|
|
71
|
+
if inline_label_paragraph?(children)
|
|
72
|
+
para = build_paragraph(style_key)
|
|
73
|
+
append_label(para, label_text(node))
|
|
74
|
+
@inline_renderer.render(first, para)
|
|
75
|
+
@context.mark_zone_paragraph
|
|
76
|
+
doc << para
|
|
77
|
+
children.drop(1).each { |child| @walker.dispatch(child, doc) }
|
|
78
|
+
else
|
|
79
|
+
# XSL block mode: name in its own keep-with-next block,
|
|
80
|
+
# body content follows (indented via the zone body styles).
|
|
81
|
+
label_para = build_paragraph(style_key)
|
|
82
|
+
append_label(label_para, label_text(node))
|
|
83
|
+
label_para.keep_next
|
|
84
|
+
doc << label_para
|
|
85
|
+
children.each { |child| @walker.dispatch(child, doc) }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
30
89
|
# Extract a title from +node+'s fmt-name attribute and render
|
|
31
90
|
# it as a Box-title paragraph. No-op when the node has no
|
|
32
91
|
# fmt-name or its text is empty.
|
|
@@ -40,6 +99,86 @@ module IsoDoc
|
|
|
40
99
|
|
|
41
100
|
private
|
|
42
101
|
|
|
102
|
+
# True when the label can run inline into the first child:
|
|
103
|
+
# the first child must be a plain paragraph (no embedded block
|
|
104
|
+
# children — OOXML cannot nest a block inside a paragraph, and
|
|
105
|
+
# ParagraphRenderer's split path must stay in charge there),
|
|
106
|
+
# and the note/example must not force XSL block mode via a
|
|
107
|
+
# nested table or definition list.
|
|
108
|
+
def inline_label_paragraph?(children)
|
|
109
|
+
first = children.first
|
|
110
|
+
return false unless first.is_a?(PLAIN_PARAGRAPH_CLASS)
|
|
111
|
+
return false if embedded_block_child?(first)
|
|
112
|
+
return false if block_forcing_child?(children)
|
|
113
|
+
|
|
114
|
+
true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def block_forcing_child?(children)
|
|
118
|
+
children.any? do |child|
|
|
119
|
+
BLOCK_CHILD_CLASSES.any? { |klass| child.is_a?(klass) }
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def embedded_block_child?(paragraph)
|
|
124
|
+
return false unless ordered?(paragraph)
|
|
125
|
+
|
|
126
|
+
mapping = build_element_mapping(paragraph)
|
|
127
|
+
paragraph.element_order.any? do |el|
|
|
128
|
+
next false unless el.element?
|
|
129
|
+
|
|
130
|
+
attr = mapping[el.name]
|
|
131
|
+
next false unless attr
|
|
132
|
+
|
|
133
|
+
Array(paragraph.public_send(attr)).any? do |value|
|
|
134
|
+
Renderers::ParagraphRenderer::BLOCK_ELEMENT_CLASSES
|
|
135
|
+
.any? { |klass| value.is_a?(klass) }
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def label_text(node)
|
|
141
|
+
fmt = attribute_value(node, :fmt_name)
|
|
142
|
+
text = fmt ? collect_all_text(fmt).to_s.strip : ""
|
|
143
|
+
text.empty? ? nil : text
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def append_label(para, text)
|
|
147
|
+
return unless text
|
|
148
|
+
|
|
149
|
+
para << (text + LABEL_GAP)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Element children of +node+ in document order (text nodes and
|
|
153
|
+
# label attributes skipped — this is a block-level walk). Mirrors
|
|
154
|
+
# ModelUtils#each_ordered_element's collection indexing, and adds
|
|
155
|
+
# the label-attribute exclusion the shared walk does not need.
|
|
156
|
+
def block_children(node)
|
|
157
|
+
return [] unless ordered?(node)
|
|
158
|
+
|
|
159
|
+
mapping = build_element_mapping(node)
|
|
160
|
+
indices = Hash.new(0)
|
|
161
|
+
children = []
|
|
162
|
+
node.element_order.each do |el|
|
|
163
|
+
next unless el.element?
|
|
164
|
+
|
|
165
|
+
attr = mapping[el.name]
|
|
166
|
+
next unless attr
|
|
167
|
+
next if LABEL_ATTRS.include?(attr.to_sym)
|
|
168
|
+
|
|
169
|
+
coll = node.public_send(attr)
|
|
170
|
+
obj = if coll.is_a?(Array)
|
|
171
|
+
idx = indices[attr]
|
|
172
|
+
indices[attr] += 1
|
|
173
|
+
coll[idx]
|
|
174
|
+
else
|
|
175
|
+
coll
|
|
176
|
+
end
|
|
177
|
+
children << obj if obj
|
|
178
|
+
end
|
|
179
|
+
children
|
|
180
|
+
end
|
|
181
|
+
|
|
43
182
|
def append_box_title(doc, title_text)
|
|
44
183
|
return if title_text.nil? || title_text.to_s.empty?
|
|
45
184
|
|
|
@@ -13,7 +13,7 @@ module IsoDoc
|
|
|
13
13
|
attr_accessor :in_note, :in_example, :in_table, :in_annex,
|
|
14
14
|
:in_normative, :in_foreword, :in_introduction,
|
|
15
15
|
:in_bibliography, :in_definition_dd, :in_formula,
|
|
16
|
-
:in_figure,
|
|
16
|
+
:in_figure, :in_definitions,
|
|
17
17
|
:section_depth,
|
|
18
18
|
:term_counter, :section_counter, :body_width,
|
|
19
19
|
:amend_zone
|
|
@@ -32,6 +32,7 @@ module IsoDoc
|
|
|
32
32
|
@in_definition_dd = false
|
|
33
33
|
@in_formula = false
|
|
34
34
|
@in_figure = false
|
|
35
|
+
@in_definitions = false
|
|
35
36
|
@section_depth = 0
|
|
36
37
|
@section_counter = Counter.new(0)
|
|
37
38
|
@term_counter = Counter.new(0)
|
|
@@ -166,6 +167,18 @@ module IsoDoc
|
|
|
166
167
|
@in_figure = old
|
|
167
168
|
end
|
|
168
169
|
|
|
170
|
+
# Enter a definitions section (ISO "Symbols and abbreviated
|
|
171
|
+
# terms"). While inside, Context#zone returns :definitions so
|
|
172
|
+
# DefinitionListRenderer renders the symbol definition list as a
|
|
173
|
+
# two-column table (classic chain: WordFunction#dl_parse_table).
|
|
174
|
+
def with_definitions
|
|
175
|
+
old = @in_definitions
|
|
176
|
+
@in_definitions = true
|
|
177
|
+
yield
|
|
178
|
+
ensure
|
|
179
|
+
@in_definitions = old
|
|
180
|
+
end
|
|
181
|
+
|
|
169
182
|
# Enter an amend zone (:description or :newcontent). While inside,
|
|
170
183
|
# Context#zone returns the amend sub-zone so StyleResolver can
|
|
171
184
|
# apply BodyText for description and a3 (amend_newcontent) for
|
|
@@ -194,6 +207,7 @@ module IsoDoc
|
|
|
194
207
|
return :table if @in_table
|
|
195
208
|
return :formula if @in_formula
|
|
196
209
|
return :figure if @in_figure
|
|
210
|
+
return :definitions if @in_definitions
|
|
197
211
|
return :amend_description if @amend_zone == :description
|
|
198
212
|
return :amend_newcontent if @amend_zone == :newcontent
|
|
199
213
|
return :annex if @in_annex
|