metanorma-document 0.2.9 → 0.2.12
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/.rubocop_todo.yml +164 -66
- data/CLAUDE.md +26 -0
- data/README.adoc +144 -0
- data/Rakefile +14 -2
- data/TODO.finalize/01-split-multi-class-files.md +8 -0
- data/TODO.finalize/02-remove-data-dist-iso-document-frontend.md +6 -0
- data/TODO.finalize/03-align-frontend-iife-and-gha-build.md +11 -0
- data/TODO.finalize/04-theme-per-flavor-config-driven.md +9 -0
- data/TODO.finalize/05-migrate-all-html-to-liquid.md +16 -0
- data/TODO.finalize/06-integrate-pubid-library.md +16 -0
- data/TODO.finalize/07-replace-relaton-models-with-relaton-bib.md +39 -0
- data/TODO.finalize/08-refactor-renderer-architecture.md +25 -0
- data/TODO.finalize/09-eliminate-code-smells.md +14 -0
- data/TODO.finalize/10-comprehensive-spec-coverage.md +24 -0
- data/TODO.finalize/11-config-driven-flavor-metadata.md +20 -0
- data/TODO.finalize/12-add-frozen-string-literal.md +6 -0
- data/TODO.finalize/13-extract-composition-from-god-class.md +96 -0
- data/TODO.finalize/14-config-driven-section-ordering.md +31 -0
- data/TODO.finalize/15-theme-directories-per-flavor.md +46 -0
- data/TODO.finalize/16-theme-lutaml-model-schema.md +44 -0
- data/data/javascripts/components/mn-footnotes.js +68 -0
- data/data/javascripts/components/mn-lightbox.js +18 -2
- data/data/javascripts/components/mn-shortcuts.js +2 -0
- data/data/javascripts/core/mn-navigation.js +8 -0
- data/data/javascripts/core/mn-theme.js +9 -9
- data/data/logos/oiml-logo-full-dark.svg +1 -0
- data/data/logos/oiml-logo-full-light.svg +1 -0
- data/data/logos/oiml-logo-icon-dark.svg +1 -0
- data/data/logos/oiml-logo-icon-light.svg +1 -0
- data/data/logos/oiml-logo.svg +1 -0
- data/data/logos/pdfa-logo.svg +31 -94
- data/data/stylesheets/base/_layout.css +3 -0
- data/data/stylesheets/base/_reset.css +3 -3
- data/data/stylesheets/base/_typography.css +0 -5
- data/data/stylesheets/components/bibliography.css +3 -3
- data/data/stylesheets/components/cover.css +3 -1
- data/data/stylesheets/components/figure.css +13 -1
- data/data/stylesheets/components/footnote.css +65 -5
- data/data/stylesheets/components/formula.css +44 -0
- data/data/stylesheets/components/header.css +17 -2
- data/data/stylesheets/components/inline.css +1 -1
- data/data/stylesheets/components/table.css +15 -2
- data/data/stylesheets/components/term.css +0 -1
- data/data/themes/bipm.yaml +60 -0
- data/data/themes/cc.yaml +43 -0
- data/data/themes/icc.yaml +39 -0
- data/data/themes/iec.yaml +44 -0
- data/data/themes/ieee.yaml +43 -0
- data/data/themes/ietf.yaml +45 -0
- data/data/themes/iho.yaml +46 -0
- data/data/themes/iso.yaml +40 -0
- data/data/themes/itu.yaml +45 -0
- data/data/themes/ogc.yaml +51 -0
- data/data/themes/oiml.yaml +56 -0
- data/data/themes/pdfa.yaml +44 -0
- data/data/themes/ribose.yaml +43 -0
- data/exe/metanorma-document +11 -0
- data/frontend/e2e/sample-html.test.ts +256 -0
- data/frontend/index.html +12 -0
- data/frontend/package-lock.json +4725 -0
- data/frontend/package.json +32 -0
- data/frontend/postcss.config.js +6 -0
- data/frontend/src/App.vue +79 -0
- data/frontend/src/app.ts +21 -0
- data/frontend/src/components/AppSidebar.vue +77 -0
- data/frontend/src/components/DocumentReader.vue +180 -0
- data/frontend/src/components/MirrorRenderer.vue +23 -0
- data/frontend/src/components/ReadingProgressBar.vue +29 -0
- data/frontend/src/components/TextRenderer.vue +131 -0
- data/frontend/src/components/TocItem.vue +57 -0
- data/frontend/src/components/TopBar.vue +49 -0
- data/frontend/src/components/__tests__/MirrorRenderer.test.ts +178 -0
- data/frontend/src/components/blocks/AdmonitionBlock.vue +74 -0
- data/frontend/src/components/blocks/ClauseBlock.vue +53 -0
- data/frontend/src/components/blocks/ExampleBlock.vue +21 -0
- data/frontend/src/components/blocks/FallbackBlock.vue +18 -0
- data/frontend/src/components/blocks/FigureBlock.vue +26 -0
- data/frontend/src/components/blocks/FootnotesBlock.vue +25 -0
- data/frontend/src/components/blocks/ListBlocks.vue +62 -0
- data/frontend/src/components/blocks/NoteBlock.vue +21 -0
- data/frontend/src/components/blocks/ParagraphBlock.vue +25 -0
- data/frontend/src/components/blocks/QuoteBlock.vue +25 -0
- data/frontend/src/components/blocks/ReviewBlock.vue +39 -0
- data/frontend/src/components/blocks/SourcecodeBlock.vue +52 -0
- data/frontend/src/components/blocks/TableBlock.vue +48 -0
- data/frontend/src/components/blocks/index.ts +36 -0
- data/frontend/src/stores/__tests__/documentStore.fixture.test.ts +272 -0
- data/frontend/src/stores/__tests__/documentStore.test.ts +143 -0
- data/frontend/src/stores/__tests__/ebookStore.test.ts +145 -0
- data/frontend/src/stores/__tests__/uiStore.test.ts +42 -0
- data/frontend/src/stores/documentStore.ts +153 -0
- data/frontend/src/stores/ebookStore.ts +179 -0
- data/frontend/src/stores/uiStore.ts +32 -0
- data/frontend/src/styles.css +156 -0
- data/frontend/src/types/__tests__/rendering-contract.test.ts +172 -0
- data/frontend/src/types/rendering-contract.ts +209 -0
- data/frontend/src/utils/__tests__/typeMetadata.test.ts +102 -0
- data/frontend/src/utils/typeMetadata.ts +121 -0
- data/frontend/tailwind.config.js +18 -0
- data/frontend/test/fixtures/iso-document.json +271 -0
- data/frontend/tmp/debug_e2e.cjs +46 -0
- data/frontend/tsconfig.json +25 -0
- data/frontend/tsconfig.node.json +11 -0
- data/frontend/vite.config.ts +37 -0
- data/frontend/vitest.e2e.config.ts +9 -0
- data/lib/metanorma/bipm_document/metadata/bipm_bibliographic_item.rb +0 -14
- data/lib/metanorma/bipm_document/metadata/depiction_element.rb +18 -0
- data/lib/metanorma/bipm_document/metadata.rb +1 -1
- data/lib/metanorma/document/cli.rb +116 -0
- data/lib/metanorma/document/components/ancillary_blocks/callout_annotation.rb +27 -0
- data/lib/metanorma/document/components/ancillary_blocks/sourcecode_block.rb +0 -65
- data/lib/metanorma/document/components/ancillary_blocks/sourcecode_body.rb +18 -0
- data/lib/metanorma/document/components/ancillary_blocks.rb +4 -0
- data/lib/metanorma/document/components/bib_data/bib_data.rb +7 -0
- data/lib/metanorma/document/components/blocks/classification_value.rb +21 -0
- data/lib/metanorma/document/components/blocks/permission_model.rb +28 -0
- data/lib/metanorma/document/components/blocks/recommendation_model.rb +28 -0
- data/lib/metanorma/document/components/blocks/requirement_base.rb +30 -0
- data/lib/metanorma/document/components/blocks/requirement_classification.rb +20 -0
- data/lib/metanorma/document/components/blocks/requirement_description.rb +43 -0
- data/lib/metanorma/document/components/blocks/requirement_inherit.rb +24 -0
- data/lib/metanorma/document/components/blocks/requirement_model.rb +0 -131
- data/lib/metanorma/document/components/blocks.rb +8 -7
- data/lib/metanorma/document/components/id_elements/image.rb +2 -0
- data/lib/metanorma/document/components/inline/asciimath_element.rb +2 -0
- data/lib/metanorma/document/components/inline/attribution_element.rb +2 -0
- data/lib/metanorma/document/components/inline/bcp14_element.rb +2 -0
- data/lib/metanorma/document/components/inline/biblio_tag_element.rb +2 -0
- data/lib/metanorma/document/components/inline/br_element.rb +2 -0
- data/lib/metanorma/document/components/inline/comma_element.rb +2 -0
- data/lib/metanorma/document/components/inline/concept_element.rb +2 -0
- data/lib/metanorma/document/components/inline/display_text_element.rb +2 -0
- data/lib/metanorma/document/components/inline/em_raw_element.rb +2 -0
- data/lib/metanorma/document/components/inline/enum_comma_element.rb +2 -0
- data/lib/metanorma/document/components/inline/eref_element.rb +2 -0
- data/lib/metanorma/document/components/inline/fmt_admitted_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_annotation_body_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_annotation_end_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_annotation_start_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_concept_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_definition_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_fn_body_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_fn_label_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_footnote_container_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_identifier_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_name_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_preferred_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_sourcecode_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_stem_element.rb +10 -0
- data/lib/metanorma/document/components/inline/fmt_termsource_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_title_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_xref_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fmt_xref_label_element.rb +4 -0
- data/lib/metanorma/document/components/inline/fn_element.rb +2 -0
- data/lib/metanorma/document/components/inline/link_element.rb +2 -0
- data/lib/metanorma/document/components/inline/localized_string_element.rb +2 -0
- data/lib/metanorma/document/components/inline/localized_strings_element.rb +2 -0
- data/lib/metanorma/document/components/inline/location_element.rb +24 -0
- data/lib/metanorma/document/components/inline/math_element.rb +2 -0
- data/lib/metanorma/document/components/inline/name_with_id_element.rb +4 -0
- data/lib/metanorma/document/components/inline/rendered_display.rb +23 -0
- data/lib/metanorma/document/components/inline/rendered_math_element.rb +21 -0
- data/lib/metanorma/document/components/inline/semantic_content.rb +51 -0
- data/lib/metanorma/document/components/inline/semantic_math_element.rb +20 -0
- data/lib/metanorma/document/components/inline/semx_child_element.rb +2 -0
- data/lib/metanorma/document/components/inline/semx_element.rb +13 -1
- data/lib/metanorma/document/components/inline/small_cap_element.rb +2 -0
- data/lib/metanorma/document/components/inline/span_element.rb +10 -15
- data/lib/metanorma/document/components/inline/stem_inline_element.rb +7 -1
- data/lib/metanorma/document/components/inline/strong_raw_element.rb +2 -0
- data/lib/metanorma/document/components/inline/sub_element.rb +2 -0
- data/lib/metanorma/document/components/inline/sup_element.rb +2 -0
- data/lib/metanorma/document/components/inline/tab_element.rb +2 -0
- data/lib/metanorma/document/components/inline/title_with_annotation_element.rb +4 -0
- data/lib/metanorma/document/components/inline/tt_element.rb +2 -0
- data/lib/metanorma/document/components/inline/variant_title_element.rb +2 -0
- data/lib/metanorma/document/components/inline/vocabulary.rb +184 -0
- data/lib/metanorma/document/components/inline/xref_element.rb +10 -0
- data/lib/metanorma/document/components/inline.rb +12 -0
- data/lib/metanorma/document/components/multi_paragraph/quote_author_element.rb +20 -0
- data/lib/metanorma/document/components/multi_paragraph/quote_block.rb +0 -29
- data/lib/metanorma/document/components/multi_paragraph.rb +2 -0
- data/lib/metanorma/document/components/reference_elements/source_element.rb +0 -31
- data/lib/metanorma/document/components/reference_elements/source_modification.rb +21 -0
- data/lib/metanorma/document/components/reference_elements/source_origin.rb +28 -0
- data/lib/metanorma/document/components/reference_elements.rb +2 -2
- data/lib/metanorma/document/components/tables/col_element.rb +18 -0
- data/lib/metanorma/document/components/tables/col_group_element.rb +18 -0
- data/lib/metanorma/document/components/tables/table_block.rb +0 -22
- data/lib/metanorma/document/components/tables/table_body_section.rb +16 -0
- data/lib/metanorma/document/components/tables/table_foot_section.rb +16 -0
- data/lib/metanorma/document/components/tables/table_head_section.rb +16 -0
- data/lib/metanorma/document/components/tables/table_section.rb +0 -25
- data/lib/metanorma/document/components/tables.rb +5 -3
- data/lib/metanorma/document/relaton/address.rb +0 -27
- data/lib/metanorma/document/relaton/bib_item_locality.rb +3 -12
- data/lib/metanorma/document/relaton/copyright_association.rb +0 -10
- data/lib/metanorma/document/relaton/copyright_owner.rb +16 -0
- data/lib/metanorma/document/relaton/edition.rb +4 -7
- data/lib/metanorma/document/relaton/formatted_address.rb +29 -0
- data/lib/metanorma/document/relaton/logo_element.rb +18 -0
- data/lib/metanorma/document/relaton/organization.rb +0 -14
- data/lib/metanorma/document/relaton/phone.rb +3 -9
- data/lib/metanorma/document/relaton/place_type.rb +0 -13
- data/lib/metanorma/document/relaton/price_type.rb +3 -9
- data/lib/metanorma/document/relaton/region_element.rb +18 -0
- data/lib/metanorma/document/relaton.rb +6 -1
- data/lib/metanorma/document/version.rb +1 -1
- data/lib/metanorma/document.rb +2 -0
- data/lib/metanorma/html/asset_pipeline.rb +1 -0
- data/lib/metanorma/html/base_renderer.rb +261 -1008
- data/lib/metanorma/html/bipm_renderer.rb +15 -144
- data/lib/metanorma/html/cc_renderer.rb +1 -45
- data/lib/metanorma/html/component/base.rb +2 -7
- data/lib/metanorma/html/component/index_section.rb +41 -43
- data/lib/metanorma/html/drops/admonition_drop.rb +1 -4
- data/lib/metanorma/html/drops/biblio_entry_drop.rb +50 -0
- data/lib/metanorma/html/drops/block_element_drop.rb +7 -2
- data/lib/metanorma/html/drops/example_drop.rb +1 -4
- data/lib/metanorma/html/drops/figure_drop.rb +31 -22
- data/lib/metanorma/html/drops/footnote_drop.rb +1 -1
- data/lib/metanorma/html/drops/formula_drop.rb +45 -16
- data/lib/metanorma/html/drops/note_drop.rb +9 -7
- data/lib/metanorma/html/drops/sourcecode_drop.rb +12 -5
- data/lib/metanorma/html/drops.rb +2 -0
- data/lib/metanorma/html/generator.rb +2 -2
- data/lib/metanorma/html/icc_renderer.rb +0 -39
- data/lib/metanorma/html/iec_renderer.rb +1 -44
- data/lib/metanorma/html/ieee_renderer.rb +1 -45
- data/lib/metanorma/html/ietf_renderer.rb +1 -48
- data/lib/metanorma/html/iho_renderer.rb +1 -46
- data/lib/metanorma/html/iso_renderer.rb +290 -343
- data/lib/metanorma/html/itu_renderer.rb +1 -45
- data/lib/metanorma/html/ogc_renderer.rb +15 -76
- data/lib/metanorma/html/oiml_renderer.rb +18 -38
- data/lib/metanorma/html/pdfa_renderer.rb +0 -39
- data/lib/metanorma/html/renderers/block_renderer.rb +372 -0
- data/lib/metanorma/html/renderers/inline_renderer.rb +655 -0
- data/lib/metanorma/html/renderers/pubid_renderer.rb +69 -0
- data/lib/metanorma/html/renderers/section_renderer.rb +193 -0
- data/lib/metanorma/html/renderers.rb +8 -0
- data/lib/metanorma/html/ribose_renderer.rb +1 -45
- data/lib/metanorma/html/standard_renderer.rb +341 -229
- data/lib/metanorma/html/templates/_audio.html.liquid +1 -0
- data/lib/metanorma/html/templates/_biblio_entry.html.liquid +1 -0
- data/lib/metanorma/html/templates/_bipm_cover.html.liquid +27 -0
- data/lib/metanorma/html/templates/_boilerplate.html.liquid +1 -0
- data/lib/metanorma/html/templates/_bookmark.html.liquid +1 -0
- data/lib/metanorma/html/templates/_br.html.liquid +1 -0
- data/lib/metanorma/html/templates/_definition_list.html.liquid +6 -0
- data/lib/metanorma/html/templates/_element.html.liquid +1 -0
- data/lib/metanorma/html/templates/_fn_marker.html.liquid +1 -0
- data/lib/metanorma/html/templates/_footnotes.html.liquid +6 -6
- data/lib/metanorma/html/templates/_formula.html.liquid +1 -1
- data/lib/metanorma/html/templates/_header.html.liquid +1 -1
- data/lib/metanorma/html/templates/_heading.html.liquid +1 -0
- data/lib/metanorma/html/templates/_image.html.liquid +1 -0
- data/lib/metanorma/html/templates/_inline_span.html.liquid +1 -0
- data/lib/metanorma/html/templates/_iso_cover.html.liquid +1 -1
- data/lib/metanorma/html/templates/_link.html.liquid +1 -0
- data/lib/metanorma/html/templates/_list.html.liquid +3 -0
- data/lib/metanorma/html/templates/_list_item.html.liquid +1 -0
- data/lib/metanorma/html/templates/_main_content.html.liquid +1 -0
- data/lib/metanorma/html/templates/_math_container.html.liquid +1 -0
- data/lib/metanorma/html/templates/_paragraph.html.liquid +1 -0
- data/lib/metanorma/html/templates/_prefatory_section.html.liquid +1 -0
- data/lib/metanorma/html/templates/_pubid_identifier.html.liquid +1 -0
- data/lib/metanorma/html/templates/_quote.html.liquid +4 -0
- data/lib/metanorma/html/templates/_ref_date.html.liquid +1 -0
- data/lib/metanorma/html/templates/_ref_title.html.liquid +1 -0
- data/lib/metanorma/html/templates/_section.html.liquid +5 -0
- data/lib/metanorma/html/templates/_standard_cover.html.liquid +31 -0
- data/lib/metanorma/html/templates/_standard_doc_title.html.liquid +3 -0
- data/lib/metanorma/html/templates/_stem_span.html.liquid +1 -0
- data/lib/metanorma/html/templates/_table.html.liquid +9 -0
- data/lib/metanorma/html/templates/_term_domain.html.liquid +1 -0
- data/lib/metanorma/html/templates/_term_example.html.liquid +1 -0
- data/lib/metanorma/html/templates/_term_note.html.liquid +1 -0
- data/lib/metanorma/html/templates/_term_number.html.liquid +1 -0
- data/lib/metanorma/html/templates/_term_source.html.liquid +1 -0
- data/lib/metanorma/html/templates/_term_text_note.html.liquid +1 -0
- data/lib/metanorma/html/templates/_video.html.liquid +1 -0
- data/lib/metanorma/html/templates/_wrapped_preface.html.liquid +1 -0
- data/lib/metanorma/html/templates/document.html.liquid +4 -0
- data/lib/metanorma/html/theme.rb +180 -107
- data/lib/metanorma/html.rb +13 -0
- data/lib/metanorma/ietf_document/metadata/ietf_bib_data_extension_type.rb +0 -25
- data/lib/metanorma/ietf_document/metadata/pi_settings.rb +32 -0
- data/lib/metanorma/ietf_document/metadata.rb +2 -0
- data/lib/metanorma/iso_document/metadata/doctype_element.rb +20 -0
- data/lib/metanorma/iso_document/metadata/iso_bib_data_extension_type.rb +0 -48
- data/lib/metanorma/iso_document/metadata/iso_bibliographic_item.rb +0 -72
- data/lib/metanorma/iso_document/metadata/iso_document_status.rb +0 -30
- data/lib/metanorma/iso_document/metadata/iso_localized_title.rb +4 -1
- data/lib/metanorma/iso_document/metadata/language_element.rb +18 -0
- data/lib/metanorma/iso_document/metadata/project_number.rb +22 -0
- data/lib/metanorma/iso_document/metadata/script_element.rb +18 -0
- data/lib/metanorma/iso_document/metadata/stage_element.rb +26 -0
- data/lib/metanorma/iso_document/metadata/stagename_element.rb +18 -0
- data/lib/metanorma/iso_document/metadata/structured_identifier.rb +0 -17
- data/lib/metanorma/iso_document/metadata/title_collection.rb +1 -0
- data/lib/metanorma/iso_document/metadata.rb +9 -4
- data/lib/metanorma/iso_document/terms/iso_term.rb +0 -13
- data/lib/metanorma/iso_document/terms/term_domain_element.rb +18 -0
- data/lib/metanorma/iso_document/terms.rb +1 -0
- data/lib/metanorma/itu_document/metadata/itu_bib_data_extension_type.rb +0 -37
- data/lib/metanorma/itu_document/metadata/meeting_date.rb +18 -0
- data/lib/metanorma/itu_document/metadata/meeting_element.rb +18 -0
- data/lib/metanorma/itu_document/metadata/study_period.rb +18 -0
- data/lib/metanorma/itu_document/metadata.rb +3 -4
- data/lib/metanorma/mirror/default_registry.rb +170 -0
- data/lib/metanorma/mirror/handler_registry.rb +60 -0
- data/lib/metanorma/mirror/handler_result.rb +37 -0
- data/lib/metanorma/mirror/handlers/admonition.rb +18 -0
- data/lib/metanorma/mirror/handlers/example.rb +21 -0
- data/lib/metanorma/mirror/handlers/figure.rb +53 -0
- data/lib/metanorma/mirror/handlers/formula.rb +35 -0
- data/lib/metanorma/mirror/handlers/inline/rich_html_renderer.rb +159 -0
- data/lib/metanorma/mirror/handlers/inline/text_extractor.rb +116 -0
- data/lib/metanorma/mirror/handlers/inline.rb +225 -0
- data/lib/metanorma/mirror/handlers/list.rb +110 -0
- data/lib/metanorma/mirror/handlers/note.rb +26 -0
- data/lib/metanorma/mirror/handlers/paragraph.rb +19 -0
- data/lib/metanorma/mirror/handlers/quote.rb +16 -0
- data/lib/metanorma/mirror/handlers/review.rb +19 -0
- data/lib/metanorma/mirror/handlers/section.rb +149 -0
- data/lib/metanorma/mirror/handlers/sourcecode.rb +27 -0
- data/lib/metanorma/mirror/handlers/structural.rb +68 -0
- data/lib/metanorma/mirror/handlers/table.rb +81 -0
- data/lib/metanorma/mirror/handlers/term.rb +100 -0
- data/lib/metanorma/mirror/handlers.rb +60 -0
- data/lib/metanorma/mirror/id_strategy/positional.rb +166 -0
- data/lib/metanorma/mirror/id_strategy/preserve.rb +12 -0
- data/lib/metanorma/mirror/id_strategy.rb +34 -0
- data/lib/metanorma/mirror/math_util.rb +53 -0
- data/lib/metanorma/mirror/metadata.rb +37 -0
- data/lib/metanorma/mirror/metanorma_to_mirror.rb +101 -0
- data/lib/metanorma/mirror/model/container.rb +47 -0
- data/lib/metanorma/mirror/model/factory.rb +52 -0
- data/lib/metanorma/mirror/model/guide.rb +25 -0
- data/lib/metanorma/mirror/model/leaf.rb +17 -0
- data/lib/metanorma/mirror/model/mark.rb +53 -0
- data/lib/metanorma/mirror/model/node.rb +47 -0
- data/lib/metanorma/mirror/model/soft_break.rb +33 -0
- data/lib/metanorma/mirror/model/text.rb +34 -0
- data/lib/metanorma/mirror/model.rb +16 -0
- data/lib/metanorma/mirror/output/builder.rb +39 -0
- data/lib/metanorma/mirror/output/formats/base_format.rb +90 -0
- data/lib/metanorma/mirror/output/formats/inline_format.rb +81 -0
- data/lib/metanorma/mirror/output/formats.rb +53 -0
- data/lib/metanorma/mirror/output/html_renderer.rb +95 -0
- data/lib/metanorma/mirror/output/html_renderers/block_renderers.rb +178 -0
- data/lib/metanorma/mirror/output/html_renderers/inline_renderer.rb +61 -0
- data/lib/metanorma/mirror/output/html_renderers/list_renderers.rb +96 -0
- data/lib/metanorma/mirror/output/html_renderers/mark_renderers.rb +64 -0
- data/lib/metanorma/mirror/output/html_renderers/section_renderers.rb +129 -0
- data/lib/metanorma/mirror/output/html_renderers/structural_renderers.rb +80 -0
- data/lib/metanorma/mirror/output/html_renderers/table_renderers.rb +87 -0
- data/lib/metanorma/mirror/output/html_renderers.rb +76 -0
- data/lib/metanorma/mirror/output/pipeline.rb +92 -0
- data/lib/metanorma/mirror/output/pipeline_context.rb +22 -0
- data/lib/metanorma/mirror/output.rb +14 -0
- data/lib/metanorma/mirror/rewriter.rb +121 -0
- data/lib/metanorma/mirror/safe_attr.rb +16 -0
- data/lib/metanorma/mirror/serialization/json_serializer.rb +25 -0
- data/lib/metanorma/mirror/serialization/yaml_serializer.rb +20 -0
- data/lib/metanorma/mirror/serialization.rb +10 -0
- data/lib/metanorma/mirror/transformer.rb +22 -0
- data/lib/metanorma/mirror.rb +32 -0
- data/lib/metanorma/standard_document/annotation.rb +37 -0
- data/lib/metanorma/standard_document/block_attributes.rb +15 -2
- data/lib/metanorma/standard_document/blocks/block_source.rb +0 -23
- data/lib/metanorma/standard_document/blocks/source_origin_element.rb +23 -0
- data/lib/metanorma/standard_document/blocks.rb +1 -1
- data/lib/metanorma/standard_document/terms/term_expression.rb +0 -31
- data/lib/metanorma/standard_document/terms/term_name_element.rb +29 -0
- data/lib/metanorma/standard_document/terms.rb +1 -0
- data/script/render_both.rb +18 -0
- metadata +262 -13
- data/.github/workflows/rake.yml +0 -21
- data/.github/workflows/release.yml +0 -25
- data/.github/workflows/roundtrip-samples.yml +0 -132
- data/.gitignore +0 -19
- data/.rspec +0 -3
- data/.rubocop.yml +0 -22
- data/Gemfile +0 -28
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/metanorma-document.gemspec +0 -35
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Inline
|
|
7
|
+
autoload :TextExtractor, "#{__dir__}/inline/text_extractor"
|
|
8
|
+
autoload :RichHtmlRenderer, "#{__dir__}/inline/rich_html_renderer"
|
|
9
|
+
|
|
10
|
+
MARK_BUILDERS = {
|
|
11
|
+
Metanorma::Document::Components::Inline::EmRawElement => ->(_el) {
|
|
12
|
+
Handlers.build_mark("emphasis")
|
|
13
|
+
},
|
|
14
|
+
Metanorma::Document::Components::Inline::StrongRawElement => ->(_el) {
|
|
15
|
+
Handlers.build_mark("strong")
|
|
16
|
+
},
|
|
17
|
+
Metanorma::Document::Components::Inline::SubElement => ->(_el) {
|
|
18
|
+
Handlers.build_mark("subscript")
|
|
19
|
+
},
|
|
20
|
+
Metanorma::Document::Components::Inline::SupElement => ->(_el) {
|
|
21
|
+
Handlers.build_mark("superscript")
|
|
22
|
+
},
|
|
23
|
+
Metanorma::Document::Components::Inline::TtElement => ->(_el) {
|
|
24
|
+
Handlers.build_mark("code")
|
|
25
|
+
},
|
|
26
|
+
Metanorma::Document::Components::TextElements::UnderlineElement => ->(_el) {
|
|
27
|
+
Handlers.build_mark("underline")
|
|
28
|
+
},
|
|
29
|
+
Metanorma::Document::Components::TextElements::StrikeElement => ->(_el) {
|
|
30
|
+
Handlers.build_mark("strike")
|
|
31
|
+
},
|
|
32
|
+
Metanorma::Document::Components::Inline::SmallCapElement => ->(_el) {
|
|
33
|
+
Handlers.build_mark("smallcap")
|
|
34
|
+
},
|
|
35
|
+
Metanorma::Document::Components::Inline::Bcp14Element => ->(_el) {
|
|
36
|
+
Handlers.build_mark("bcp14")
|
|
37
|
+
},
|
|
38
|
+
Metanorma::Document::Components::Inline::LinkElement => ->(el) {
|
|
39
|
+
attrs = {
|
|
40
|
+
href: SafeAttr.read(el, :target) || SafeAttr.read(el, :href),
|
|
41
|
+
}.compact
|
|
42
|
+
Handlers.build_mark("link", attrs: attrs)
|
|
43
|
+
},
|
|
44
|
+
Metanorma::Document::Components::Inline::XrefElement => ->(el) {
|
|
45
|
+
attrs = { target: SafeAttr.read(el, :target) }.compact
|
|
46
|
+
Handlers.build_mark("xref", attrs: attrs)
|
|
47
|
+
},
|
|
48
|
+
Metanorma::Document::Components::Inline::ErefElement => ->(el) {
|
|
49
|
+
attrs = {
|
|
50
|
+
bibitemid: SafeAttr.read(el, :bibitemid),
|
|
51
|
+
citeas: SafeAttr.read(el, :citeas),
|
|
52
|
+
}.compact
|
|
53
|
+
Handlers.build_mark("eref", attrs: attrs)
|
|
54
|
+
},
|
|
55
|
+
Metanorma::Document::Components::Inline::FnElement => ->(el) {
|
|
56
|
+
attrs = {
|
|
57
|
+
id: SafeAttr.read(el, :id),
|
|
58
|
+
reference: SafeAttr.read(el, :reference),
|
|
59
|
+
}.compact
|
|
60
|
+
Handlers.build_mark("footnote", attrs: attrs)
|
|
61
|
+
},
|
|
62
|
+
Metanorma::Document::Components::Inline::StemInlineElement => ->(el) {
|
|
63
|
+
attrs = { stem_type: SafeAttr.read(el, :stem_type) || "MathML" }
|
|
64
|
+
math = SafeAttr.read(el, :math)
|
|
65
|
+
attrs[:mathml] = MathUtil.mathml_from_math(math) if math
|
|
66
|
+
Handlers.build_mark("stem", attrs: attrs.compact)
|
|
67
|
+
},
|
|
68
|
+
Metanorma::Document::Components::Inline::ConceptElement => ->(el) {
|
|
69
|
+
attrs = {
|
|
70
|
+
refterm: SafeAttr.read(el, :refterm),
|
|
71
|
+
renderterm: SafeAttr.read(el, :renderterm),
|
|
72
|
+
}.compact
|
|
73
|
+
Handlers.build_mark("concept", attrs: attrs)
|
|
74
|
+
},
|
|
75
|
+
Metanorma::Document::Components::Inline::SpanElement => ->(el) {
|
|
76
|
+
attrs = {
|
|
77
|
+
class_attr: SafeAttr.read(el, :class_attr),
|
|
78
|
+
style: SafeAttr.read(el, :style),
|
|
79
|
+
}.compact
|
|
80
|
+
Handlers.build_mark("span", attrs: attrs)
|
|
81
|
+
},
|
|
82
|
+
}.freeze
|
|
83
|
+
|
|
84
|
+
SEMX_MARK_CONFIG = {
|
|
85
|
+
"xref" => { mark_type: "xref", target_attr: :target,
|
|
86
|
+
fmt_attr: :fmt_xref },
|
|
87
|
+
"eref" => { mark_type: "eref", target_attr: :target,
|
|
88
|
+
fmt_attr: :fmt_xref },
|
|
89
|
+
"link" => { mark_type: "link", target_attr: :target,
|
|
90
|
+
fmt_attr: :fmt_link },
|
|
91
|
+
}.freeze
|
|
92
|
+
|
|
93
|
+
CROSSREF_MARKS = %w[xref eref link].to_set.freeze
|
|
94
|
+
|
|
95
|
+
# Delegates to TextExtractor
|
|
96
|
+
def self.extract_element_text(element)
|
|
97
|
+
TextExtractor.extract_element_text(element)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.extract_formatted_text(element)
|
|
101
|
+
TextExtractor.extract_formatted_text(element)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.extract_text_from_model(node)
|
|
105
|
+
TextExtractor.extract_text_from_model(node)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Delegates to RichHtmlRenderer
|
|
109
|
+
def self.extract_rich_html(element)
|
|
110
|
+
RichHtmlRenderer.extract(element)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Primary entry point: extract inline content from a mixed-content element.
|
|
114
|
+
# Iterates semantic children only — `fmt-*` rendered siblings are skipped
|
|
115
|
+
# to avoid emitting duplicate marks for the same logical content.
|
|
116
|
+
def self.extract_inline(element, context:)
|
|
117
|
+
nodes = []
|
|
118
|
+
Metanorma::Document::Components::Inline::SemanticContent.each(element) do |node|
|
|
119
|
+
case node
|
|
120
|
+
when String
|
|
121
|
+
nodes << context.text_node(node) unless node.empty?
|
|
122
|
+
else
|
|
123
|
+
handle_inline_element(node, nodes, context:)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
filter_empty_crossrefs(nodes)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.handle_inline_element(element, nodes, context:)
|
|
130
|
+
if semx_element?(element)
|
|
131
|
+
handle_semx(element, nodes, context:)
|
|
132
|
+
return
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
if block_in_inline?(element, context)
|
|
136
|
+
handle_block_in_inline(element, nodes, context:)
|
|
137
|
+
return
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
mark_builder = MARK_BUILDERS[element.class]
|
|
141
|
+
if mark_builder
|
|
142
|
+
mark = mark_builder.call(element)
|
|
143
|
+
text = extract_marked_text(mark.type, element)
|
|
144
|
+
nodes << context.text_node(text, marks: [mark])
|
|
145
|
+
else
|
|
146
|
+
handle_structured_inline(element, nodes, context:)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.handle_semx(element, nodes, context:)
|
|
151
|
+
config = SEMX_MARK_CONFIG[element.element_attr]
|
|
152
|
+
if config
|
|
153
|
+
handle_semx_crossref(element, config, nodes, context:)
|
|
154
|
+
else
|
|
155
|
+
handle_structured_inline(element, nodes, context:)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def self.handle_semx_crossref(element, config, nodes, context:)
|
|
160
|
+
fmt_children = SafeAttr.read(element, config[:fmt_attr])
|
|
161
|
+
fmt_child = fmt_children&.first
|
|
162
|
+
|
|
163
|
+
mark_attrs = {}
|
|
164
|
+
if fmt_child && config[:target_attr]
|
|
165
|
+
mark_attrs[config[:target_attr]] = SafeAttr.read(fmt_child, :target)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
if element.element_attr == "eref" && fmt_child
|
|
169
|
+
mark_attrs[:citeas] = extract_formatted_text(fmt_child)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
text = extract_formatted_text(fmt_child || element)
|
|
173
|
+
mark = Handlers.build_mark(config[:mark_type],
|
|
174
|
+
attrs: mark_attrs.compact)
|
|
175
|
+
nodes << context.text_node(text, marks: [mark])
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def self.handle_block_in_inline(element, nodes, context:)
|
|
179
|
+
result = context.registry.handle(element, context: context)
|
|
180
|
+
result.append_to(nodes)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def self.handle_structured_inline(element, nodes, context:)
|
|
184
|
+
if element.is_a?(Lutaml::Model::Serializable)
|
|
185
|
+
inner_nodes = extract_inline(element, context:)
|
|
186
|
+
nodes.concat(inner_nodes)
|
|
187
|
+
else
|
|
188
|
+
text = element.text
|
|
189
|
+
nodes << context.text_node(text) if text.is_a?(String) && !text.strip.empty?
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def self.mark_text_extractors
|
|
194
|
+
@mark_text_extractors ||= {
|
|
195
|
+
"footnote" => TextExtractor.method(:extract_fn_label),
|
|
196
|
+
"stem" => TextExtractor.method(:extract_stem_text),
|
|
197
|
+
"span" => TextExtractor.method(:extract_span_text),
|
|
198
|
+
}
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def self.extract_marked_text(mark_type, element)
|
|
202
|
+
extractor = mark_text_extractors[mark_type]
|
|
203
|
+
return extractor.call(element) if extractor
|
|
204
|
+
|
|
205
|
+
TextExtractor.extract_element_text(element)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def self.semx_element?(element)
|
|
209
|
+
element.is_a?(Metanorma::Document::Components::Inline::SemxElement)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def self.block_in_inline?(element, context)
|
|
213
|
+
context.registry.registered?(element.class)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def self.filter_empty_crossrefs(nodes)
|
|
217
|
+
nodes.reject do |n|
|
|
218
|
+
n.is_a?(Model::Text) && n.text.strip.empty? &&
|
|
219
|
+
n.marks.any? { |m| CROSSREF_MARKS.include?(m.type) }
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module List
|
|
7
|
+
def self.bullet(element, context:)
|
|
8
|
+
attrs = list_attrs(element)
|
|
9
|
+
items = extract_items(element, context:)
|
|
10
|
+
|
|
11
|
+
Handlers.build_node("bullet_list", attrs: attrs, content: items)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.ordered(element, context:)
|
|
15
|
+
attrs = list_attrs(element)
|
|
16
|
+
attrs[:type] = SafeAttr.read(element, :type)
|
|
17
|
+
attrs[:start] = SafeAttr.read(element, :start)
|
|
18
|
+
attrs[:group] = SafeAttr.read(element, :group)
|
|
19
|
+
items = extract_items(element, context:)
|
|
20
|
+
|
|
21
|
+
Handlers.build_node("ordered_list", attrs: attrs.compact,
|
|
22
|
+
content: items)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.definition(element, context:)
|
|
26
|
+
attrs = list_attrs(element)
|
|
27
|
+
attrs[:key] = SafeAttr.read(element, :key)
|
|
28
|
+
items = extract_definition_items(element, context:)
|
|
29
|
+
|
|
30
|
+
Handlers.build_node("dl", attrs: attrs.compact, content: items)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.list_item(element, context:)
|
|
34
|
+
attrs = {}
|
|
35
|
+
attrs[:id] = SafeAttr.read(element, :id)
|
|
36
|
+
attrs[:checkbox] = SafeAttr.read(element, :checkbox)
|
|
37
|
+
attrs[:checkedcheckbox] = SafeAttr.read(element, :checkedcheckbox)
|
|
38
|
+
|
|
39
|
+
content = []
|
|
40
|
+
text = SafeAttr.read(element, :text)
|
|
41
|
+
if text.is_a?(Array)
|
|
42
|
+
text.each do |t|
|
|
43
|
+
next if t.is_a?(String) && t.strip.empty?
|
|
44
|
+
|
|
45
|
+
content << context.text_node(t.to_s)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
%i[paragraphs unordered_lists ordered_lists sourcecode figure example
|
|
50
|
+
note quote table].each do |attr|
|
|
51
|
+
collection = SafeAttr.read(element, attr)
|
|
52
|
+
next unless collection
|
|
53
|
+
|
|
54
|
+
collection.each do |child|
|
|
55
|
+
result = context.registry.handle(child, context: context)
|
|
56
|
+
result.append_to(content)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
Handlers.build_node("list_item", attrs: attrs.compact,
|
|
61
|
+
content: content)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.extract_items(element, context:)
|
|
65
|
+
Array(element.listitem).filter_map do |li|
|
|
66
|
+
result = context.registry.handle(li, context: context)
|
|
67
|
+
result.nodes
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.extract_definition_items(element, context:)
|
|
72
|
+
items = []
|
|
73
|
+
dts = Array(element.dt)
|
|
74
|
+
dds = Array(element.dd)
|
|
75
|
+
|
|
76
|
+
dts.each_with_index do |dt, idx|
|
|
77
|
+
dt_attrs = {}
|
|
78
|
+
dt_attrs[:id] = SafeAttr.read(dt, :id)
|
|
79
|
+
dt_content = Inline.extract_inline(dt, context:)
|
|
80
|
+
items << Handlers.build_node("dt", attrs: dt_attrs.compact,
|
|
81
|
+
content: dt_content)
|
|
82
|
+
|
|
83
|
+
dd = dds[idx]
|
|
84
|
+
next unless dd
|
|
85
|
+
|
|
86
|
+
dd_attrs = {}
|
|
87
|
+
dd_attrs[:id] = SafeAttr.read(dd, :id)
|
|
88
|
+
dd_content = context.extract_named_collections(dd,
|
|
89
|
+
%i[p ul ol
|
|
90
|
+
sourcecode figure example note table formula quote dl])
|
|
91
|
+
items << Handlers.build_node("dd", attrs: dd_attrs.compact,
|
|
92
|
+
content: dd_content)
|
|
93
|
+
end
|
|
94
|
+
items
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.list_attrs(element)
|
|
98
|
+
attrs = {}
|
|
99
|
+
attrs[:id] = SafeAttr.read(element, :id)
|
|
100
|
+
attrs[:nobullet] = SafeAttr.read(element, :nobullet)
|
|
101
|
+
attrs[:bare] = SafeAttr.read(element, :bare)
|
|
102
|
+
attrs[:spacing] = SafeAttr.read(element, :spacing)
|
|
103
|
+
attrs[:indent] = SafeAttr.read(element, :indent)
|
|
104
|
+
attrs[:semx_id] = SafeAttr.read(element, :semx_id)
|
|
105
|
+
attrs.compact
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Note
|
|
7
|
+
EXTRA = { type_attr: :type_attr, remove_in_rfc: nil }.freeze
|
|
8
|
+
|
|
9
|
+
def self.call(element, context:)
|
|
10
|
+
attrs = Handlers.extract_attrs(element, extra_attrs: EXTRA)
|
|
11
|
+
|
|
12
|
+
content = []
|
|
13
|
+
element_content = SafeAttr.read(element, :content)
|
|
14
|
+
if element_content.is_a?(Array)
|
|
15
|
+
element_content.each do |p|
|
|
16
|
+
result = context.registry.handle(p, context: context)
|
|
17
|
+
result.append_to(content)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Handlers.build_node("note", attrs: attrs, content: content)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Paragraph
|
|
7
|
+
EXTRA = { alignment: nil, keep_with_next: nil,
|
|
8
|
+
keep_with_previous: nil }.freeze
|
|
9
|
+
|
|
10
|
+
def self.call(element, context:)
|
|
11
|
+
attrs = Handlers.extract_attrs(element, extra_attrs: EXTRA)
|
|
12
|
+
content = Inline.extract_inline(element, context:)
|
|
13
|
+
|
|
14
|
+
Handlers.build_node("paragraph", attrs: attrs, content: content)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Quote
|
|
7
|
+
def self.call(element, context:)
|
|
8
|
+
attrs = Handlers.extract_attrs(element)
|
|
9
|
+
content = context.extract_blocks(element)
|
|
10
|
+
|
|
11
|
+
Handlers.build_node("quote", attrs: attrs, content: content)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Review
|
|
7
|
+
EXTRA = { date: nil, from: nil, to: nil, reviewer: nil,
|
|
8
|
+
display: nil }.freeze
|
|
9
|
+
|
|
10
|
+
def self.call(element, context:)
|
|
11
|
+
attrs = Handlers.extract_attrs(element, extra_attrs: EXTRA)
|
|
12
|
+
content = context.extract_blocks(element)
|
|
13
|
+
|
|
14
|
+
Handlers.build_node("review", attrs: attrs, content: content)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Section
|
|
7
|
+
def self.clause(element, context:)
|
|
8
|
+
attrs = section_attrs(element, context:)
|
|
9
|
+
content = context.extract_blocks(element)
|
|
10
|
+
|
|
11
|
+
Handlers.build_node("clause", attrs: attrs, content: content)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.annex(element, context:)
|
|
15
|
+
attrs = section_attrs(element, context:)
|
|
16
|
+
attrs[:commentary] = SafeAttr.read(element, :commentary)
|
|
17
|
+
attrs[:language] = SafeAttr.read(element, :language)
|
|
18
|
+
attrs[:script] = SafeAttr.read(element, :script)
|
|
19
|
+
|
|
20
|
+
content = context.extract_blocks(element)
|
|
21
|
+
|
|
22
|
+
Handlers.build_node("annex", attrs: attrs.compact, content: content)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.content_section(element, context:)
|
|
26
|
+
attrs = section_attrs(element, context:)
|
|
27
|
+
content = context.extract_blocks(element)
|
|
28
|
+
|
|
29
|
+
subsection = SafeAttr.read(element, :subsection)
|
|
30
|
+
subsection&.each do |sub|
|
|
31
|
+
result = context.registry.handle(sub, context: context)
|
|
32
|
+
result.append_to(content)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
Handlers.build_node("content_section", attrs: attrs, content: content)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.terms(element, context:)
|
|
39
|
+
attrs = section_attrs(element, context:)
|
|
40
|
+
content = context.extract_named_collections(element,
|
|
41
|
+
%i[p term dl example
|
|
42
|
+
admonition])
|
|
43
|
+
children = context.extract_section_children(element)
|
|
44
|
+
|
|
45
|
+
Handlers.build_node("terms", attrs: attrs,
|
|
46
|
+
content: content + children)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.definitions(element, context:)
|
|
50
|
+
attrs = section_attrs(element, context:)
|
|
51
|
+
content = context.extract_blocks(element)
|
|
52
|
+
|
|
53
|
+
Handlers.build_node("definitions", attrs: attrs, content: content)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.references(element, context:)
|
|
57
|
+
attrs = section_attrs(element, context:)
|
|
58
|
+
attrs[:normative] = SafeAttr.read(element, :normative)
|
|
59
|
+
attrs[:hidden] = SafeAttr.read(element, :hidden)
|
|
60
|
+
|
|
61
|
+
# Prefatory paragraphs (e.g. "The following documents are referred to...")
|
|
62
|
+
content = context.extract_named_collections(element,
|
|
63
|
+
%i[p])
|
|
64
|
+
|
|
65
|
+
# Bibliographic items
|
|
66
|
+
refs = SafeAttr.read(element, :references)
|
|
67
|
+
refs&.each do |ref|
|
|
68
|
+
text = extract_biblio_text(ref)
|
|
69
|
+
next if text.strip.empty?
|
|
70
|
+
|
|
71
|
+
content << Handlers.build_node("paragraph",
|
|
72
|
+
attrs: { id: SafeAttr.read(ref,
|
|
73
|
+
:id) }.compact,
|
|
74
|
+
content: [context.text_node(text)])
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
Handlers.build_node("references", attrs: attrs, content: content)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.extract_biblio_text(ref)
|
|
81
|
+
parts = []
|
|
82
|
+
|
|
83
|
+
tag = SafeAttr.read(ref, :biblio_tag)
|
|
84
|
+
if tag
|
|
85
|
+
tag_text = Inline.extract_formatted_text(tag).strip
|
|
86
|
+
parts << tag_text unless tag_text.empty?
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
formatted = SafeAttr.read(ref, :formatted_ref)
|
|
90
|
+
if formatted
|
|
91
|
+
fmt_text = Inline.extract_formatted_text(formatted).strip
|
|
92
|
+
parts << fmt_text unless fmt_text.empty?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
return parts.join(" ") unless parts.empty?
|
|
96
|
+
|
|
97
|
+
docid = SafeAttr.read(ref, :docidentifier)
|
|
98
|
+
if docid
|
|
99
|
+
text = Inline.extract_formatted_text(docid)
|
|
100
|
+
return text unless text.strip.empty?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
""
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def self.floating_title(element, context:)
|
|
107
|
+
attrs = {}
|
|
108
|
+
attrs[:id] = context.id_strategy.assign_id(element)
|
|
109
|
+
attrs[:depth] = SafeAttr.read(element, :depth)
|
|
110
|
+
attrs[:semx_id] = SafeAttr.read(element, :semx_id)
|
|
111
|
+
|
|
112
|
+
title = extract_title(element)
|
|
113
|
+
attrs[:title] = title if title
|
|
114
|
+
|
|
115
|
+
Handlers.build_node("floating_title", attrs: attrs.compact)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def self.section_attrs(element, context:)
|
|
119
|
+
attrs = {}
|
|
120
|
+
attrs[:id] = context.id_strategy.assign_id(element)
|
|
121
|
+
attrs[:number] = SafeAttr.read(element, :number)
|
|
122
|
+
attrs[:obligation] = SafeAttr.read(element, :obligation)
|
|
123
|
+
attrs[:unnumbered] = SafeAttr.read(element, :unnumbered)
|
|
124
|
+
attrs[:toc] = SafeAttr.read(element, :toc)
|
|
125
|
+
attrs[:type] = SafeAttr.read(element, :type)
|
|
126
|
+
attrs[:semx_id] = SafeAttr.read(element, :semx_id)
|
|
127
|
+
attrs[:autonum] = SafeAttr.read(element, :autonum)
|
|
128
|
+
attrs[:displayorder] = SafeAttr.read(element, :displayorder)
|
|
129
|
+
|
|
130
|
+
title = extract_title(element)
|
|
131
|
+
attrs[:title] = title if title
|
|
132
|
+
attrs.compact
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def self.extract_title(element)
|
|
136
|
+
title = SafeAttr.read(element, :title)
|
|
137
|
+
return nil unless title
|
|
138
|
+
|
|
139
|
+
case title
|
|
140
|
+
when String then title
|
|
141
|
+
else
|
|
142
|
+
rich = Inline.extract_rich_html(title)
|
|
143
|
+
rich.empty? ? Inline.extract_element_text(title) : rich
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Sourcecode
|
|
7
|
+
EXTRA = { language: :lang, filename: nil, linenums: nil }.freeze
|
|
8
|
+
|
|
9
|
+
def self.call(element, context:)
|
|
10
|
+
attrs = Handlers.extract_attrs(element, extra_attrs: EXTRA)
|
|
11
|
+
|
|
12
|
+
body = SafeAttr.read(element, :body)
|
|
13
|
+
text = if body
|
|
14
|
+
Array(body.content).join
|
|
15
|
+
elsif SafeAttr.read(element, :content).is_a?(String)
|
|
16
|
+
SafeAttr.read(element, :content)
|
|
17
|
+
else
|
|
18
|
+
""
|
|
19
|
+
end
|
|
20
|
+
attrs[:text] = text
|
|
21
|
+
|
|
22
|
+
Handlers.build_node("sourcecode", attrs: attrs.compact)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Mirror
|
|
5
|
+
module Handlers
|
|
6
|
+
module Structural
|
|
7
|
+
def self.preface(element, context:)
|
|
8
|
+
attrs = {}
|
|
9
|
+
attrs[:semx_id] = SafeAttr.read(element, :semx_id)
|
|
10
|
+
attrs[:displayorder] = SafeAttr.read(element, :displayorder)
|
|
11
|
+
|
|
12
|
+
content = []
|
|
13
|
+
%i[abstract foreword introduction acknowledgements
|
|
14
|
+
executivesummary].each do |attr|
|
|
15
|
+
child = SafeAttr.read(element, attr)
|
|
16
|
+
next unless child
|
|
17
|
+
|
|
18
|
+
result = context.registry.handle(child, context: context)
|
|
19
|
+
result.append_to(content)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
element_content = SafeAttr.read(element, :content)
|
|
23
|
+
Array(element_content).each do |child|
|
|
24
|
+
result = context.registry.handle(child, context: context)
|
|
25
|
+
result.append_to(content)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Handlers.build_node("preface", attrs: attrs.compact, content: content)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.sections(element, context:)
|
|
32
|
+
attrs = {}
|
|
33
|
+
attrs[:semx_id] = SafeAttr.read(element, :semx_id)
|
|
34
|
+
attrs[:displayorder] = SafeAttr.read(element, :displayorder)
|
|
35
|
+
|
|
36
|
+
content = []
|
|
37
|
+
%i[clause terms definitions references floating_title].each do |attr|
|
|
38
|
+
collection = SafeAttr.read(element, attr)
|
|
39
|
+
next unless collection
|
|
40
|
+
|
|
41
|
+
Array(collection).each do |child|
|
|
42
|
+
result = context.registry.handle(child, context: context)
|
|
43
|
+
result.append_to(content)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
Handlers.build_node("sections", attrs: attrs.compact,
|
|
48
|
+
content: content)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.bibliography(element, context:)
|
|
52
|
+
attrs = {}
|
|
53
|
+
attrs[:semx_id] = SafeAttr.read(element, :semx_id)
|
|
54
|
+
|
|
55
|
+
content = []
|
|
56
|
+
refs = SafeAttr.read(element, :references)
|
|
57
|
+
Array(refs).each do |ref|
|
|
58
|
+
result = context.registry.handle(ref, context: context)
|
|
59
|
+
result.append_to(content)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
Handlers.build_node("bibliography", attrs: attrs.compact,
|
|
63
|
+
content: content)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|