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,52 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="block.attrs?.id" class="mn-sourcecode">
|
|
3
|
+
<div v-if="language" class="code-language-badge">{{ language }}</div>
|
|
4
|
+
<pre class="code-block"><code>{{ code }}</code></pre>
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { computed } from 'vue'
|
|
10
|
+
import type { MirrorBlockNode } from '@/stores/documentStore'
|
|
11
|
+
|
|
12
|
+
const props = defineProps<{ block: MirrorBlockNode }>()
|
|
13
|
+
|
|
14
|
+
const language = computed(() => props.block.attrs?.language || '')
|
|
15
|
+
const code = computed(() => props.block.attrs?.text || extractText(props.block.content || []))
|
|
16
|
+
|
|
17
|
+
function extractText(content: any[]): string {
|
|
18
|
+
return content.map(node => {
|
|
19
|
+
if (node.type === 'text') return node.text || ''
|
|
20
|
+
if (node.content) return extractText(node.content)
|
|
21
|
+
return ''
|
|
22
|
+
}).join('')
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<style scoped>
|
|
27
|
+
.mn-sourcecode { margin: 1.5rem 0; border-radius: 8px; overflow: hidden; position: relative; }
|
|
28
|
+
.code-language-badge {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
padding: 2px 10px;
|
|
31
|
+
font-family: ui-monospace, monospace;
|
|
32
|
+
font-size: 0.7rem;
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
text-transform: uppercase;
|
|
35
|
+
letter-spacing: 0.05em;
|
|
36
|
+
background: var(--ebook-bg-secondary);
|
|
37
|
+
color: var(--ebook-text-muted);
|
|
38
|
+
border-bottom: 1px solid var(--ebook-border);
|
|
39
|
+
border-radius: 8px 8px 0 0;
|
|
40
|
+
}
|
|
41
|
+
.code-block {
|
|
42
|
+
font-family: ui-monospace, monospace;
|
|
43
|
+
font-size: 0.875rem;
|
|
44
|
+
background: var(--chrome-bg-hover, #f1f5f9);
|
|
45
|
+
padding: 1rem 1.25rem;
|
|
46
|
+
overflow-x: auto;
|
|
47
|
+
border: 1px solid var(--ebook-border);
|
|
48
|
+
border-radius: 8px;
|
|
49
|
+
margin: 0;
|
|
50
|
+
}
|
|
51
|
+
.code-block code { font-family: inherit; }
|
|
52
|
+
</style>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :id="block.attrs?.id" class="mb-4">
|
|
3
|
+
<div v-if="block.attrs?.title" class="text-sm font-semibold muted-text mb-1">
|
|
4
|
+
{{ block.attrs.title }}
|
|
5
|
+
</div>
|
|
6
|
+
<div class="table-scroll-wrapper">
|
|
7
|
+
<table class="w-full border-collapse text-sm">
|
|
8
|
+
<thead v-for="(section, si) in (block.content || []).filter((s): s is MirrorBlockNode => s.type === 'table_head')" :key="'h'+si">
|
|
9
|
+
<tr v-for="(row, ri) in section.content!.filter((r): r is MirrorBlockNode => 'content' in r)" :key="ri" class="border-b-2 border-ebook-border">
|
|
10
|
+
<th v-for="(cell, ci) in row.content!.filter((c): c is MirrorBlockNode => 'content' in c)" :key="ci"
|
|
11
|
+
class="px-3 py-2 text-left font-semibold ebook-text border border-ebook-border"
|
|
12
|
+
:colspan="cell.attrs?.colspan"
|
|
13
|
+
:rowspan="cell.attrs?.rowspan">
|
|
14
|
+
<MirrorRenderer :blocks="cell.content || []" />
|
|
15
|
+
</th>
|
|
16
|
+
</tr>
|
|
17
|
+
</thead>
|
|
18
|
+
<tbody v-for="(section, si) in (block.content || []).filter((s): s is MirrorBlockNode => s.type === 'table_body')" :key="'b'+si">
|
|
19
|
+
<tr v-for="(row, ri) in section.content!.filter((r): r is MirrorBlockNode => 'content' in r)" :key="ri" class="table-row border-b border-ebook-border">
|
|
20
|
+
<td v-for="(cell, ci) in row.content!.filter((c): c is MirrorBlockNode => 'content' in c)" :key="ci"
|
|
21
|
+
class="px-3 py-2 ebook-text border border-ebook-border"
|
|
22
|
+
:colspan="cell.attrs?.colspan"
|
|
23
|
+
:rowspan="cell.attrs?.rowspan">
|
|
24
|
+
<MirrorRenderer :blocks="cell.content || []" />
|
|
25
|
+
</td>
|
|
26
|
+
</tr>
|
|
27
|
+
</tbody>
|
|
28
|
+
</table>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import type { MirrorBlockNode } from '@/stores/documentStore'
|
|
35
|
+
import MirrorRenderer from '@/components/MirrorRenderer.vue'
|
|
36
|
+
|
|
37
|
+
defineProps<{ block: MirrorBlockNode }>()
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<style scoped>
|
|
41
|
+
.ebook-text { color: var(--ebook-text); }
|
|
42
|
+
.muted-text { color: var(--ebook-text-muted); }
|
|
43
|
+
.border-ebook-border { border-color: var(--ebook-border); }
|
|
44
|
+
.table-scroll-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; border: 1px solid var(--ebook-border); }
|
|
45
|
+
.table-scroll-wrapper table { min-width: 400px; }
|
|
46
|
+
.table-scroll-wrapper thead th { position: sticky; top: 0; background: var(--ebook-bg-secondary); z-index: 1; }
|
|
47
|
+
.table-row:nth-child(even) { background: color-mix(in srgb, var(--ebook-text) 3%, var(--ebook-bg)); }
|
|
48
|
+
</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Component } from 'vue'
|
|
2
|
+
import ParagraphBlock from './ParagraphBlock.vue'
|
|
3
|
+
import AdmonitionBlock from './AdmonitionBlock.vue'
|
|
4
|
+
import TableBlock from './TableBlock.vue'
|
|
5
|
+
import FigureBlock from './FigureBlock.vue'
|
|
6
|
+
import SourcecodeBlock from './SourcecodeBlock.vue'
|
|
7
|
+
import NoteBlock from './NoteBlock.vue'
|
|
8
|
+
import ExampleBlock from './ExampleBlock.vue'
|
|
9
|
+
import ListBlocks from './ListBlocks.vue'
|
|
10
|
+
import QuoteBlock from './QuoteBlock.vue'
|
|
11
|
+
import ReviewBlock from './ReviewBlock.vue'
|
|
12
|
+
import FootnotesBlock from './FootnotesBlock.vue'
|
|
13
|
+
import FallbackBlock from './FallbackBlock.vue'
|
|
14
|
+
|
|
15
|
+
const BLOCK_COMPONENTS: Record<string, Component> = {
|
|
16
|
+
paragraph: ParagraphBlock,
|
|
17
|
+
admonition: AdmonitionBlock,
|
|
18
|
+
table: TableBlock,
|
|
19
|
+
figure: FigureBlock,
|
|
20
|
+
image: FigureBlock,
|
|
21
|
+
sourcecode: SourcecodeBlock,
|
|
22
|
+
note: NoteBlock,
|
|
23
|
+
example: ExampleBlock,
|
|
24
|
+
bullet_list: ListBlocks,
|
|
25
|
+
ordered_list: ListBlocks,
|
|
26
|
+
dl: ListBlocks,
|
|
27
|
+
quote: QuoteBlock,
|
|
28
|
+
review: ReviewBlock,
|
|
29
|
+
footnotes: FootnotesBlock,
|
|
30
|
+
formula: SourcecodeBlock,
|
|
31
|
+
floating_title: ParagraphBlock,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getBlockComponent(type: string): Component {
|
|
35
|
+
return BLOCK_COMPONENTS[type] ?? FallbackBlock
|
|
36
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { setActivePinia, createPinia } from 'pinia'
|
|
3
|
+
import { useDocumentStore } from '../documentStore'
|
|
4
|
+
import fixture from '@test/fixtures/iso-document.json'
|
|
5
|
+
|
|
6
|
+
describe('useDocumentStore with real mirror data', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
setActivePinia(createPinia())
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
describe('processMetanormaData with fixture', () => {
|
|
12
|
+
it('sets mirrorDocument from fixture data', () => {
|
|
13
|
+
const store = useDocumentStore()
|
|
14
|
+
store.processMetanormaData(fixture)
|
|
15
|
+
expect(store.mirrorDocument).not.toBeNull()
|
|
16
|
+
expect(store.mirrorDocument?.type).toBe('doc')
|
|
17
|
+
expect(store.mirrorDocument?.content).toBeDefined()
|
|
18
|
+
expect(store.mirrorDocument!.content!.length).toBeGreaterThan(0)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('extracts TOC from toc.sections', () => {
|
|
22
|
+
const store = useDocumentStore()
|
|
23
|
+
store.processMetanormaData(fixture)
|
|
24
|
+
expect(store.sections.length).toBe(5)
|
|
25
|
+
expect(store.sections[0].id).toBe('foreword')
|
|
26
|
+
expect(store.sections[0].title).toBe('Foreword')
|
|
27
|
+
expect(store.sections[0].type).toBe('foreword')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('extracts nested TOC children', () => {
|
|
31
|
+
const store = useDocumentStore()
|
|
32
|
+
store.processMetanormaData(fixture)
|
|
33
|
+
const terms = store.sections.find(s => s.id === 'terms')
|
|
34
|
+
expect(terms).toBeDefined()
|
|
35
|
+
expect(terms!.children.length).toBe(1)
|
|
36
|
+
expect(terms!.children[0].id).toBe('term-rice')
|
|
37
|
+
expect(terms!.children[0].title).toBe('rice')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('extracts numbering from toc', () => {
|
|
41
|
+
const store = useDocumentStore()
|
|
42
|
+
store.processMetanormaData(fixture)
|
|
43
|
+
expect(store.getNumbering('scope')).toBe('1')
|
|
44
|
+
expect(store.getNumbering('normrefs')).toBe('2')
|
|
45
|
+
expect(store.getNumbering('terms')).toBe('3')
|
|
46
|
+
expect(store.getNumbering('term-rice')).toBe('3.1')
|
|
47
|
+
expect(store.getNumbering('test-methods')).toBe('4')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('extracts title from meta', () => {
|
|
51
|
+
const store = useDocumentStore()
|
|
52
|
+
store.processMetanormaData(fixture)
|
|
53
|
+
expect(store.title).toBe('ISO 17301-1:2016 — Cereals and pulses')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('extracts flavor from meta', () => {
|
|
57
|
+
const store = useDocumentStore()
|
|
58
|
+
store.processMetanormaData(fixture)
|
|
59
|
+
expect(store.flavor).toBe('iso')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('extracts docType from meta', () => {
|
|
63
|
+
const store = useDocumentStore()
|
|
64
|
+
store.processMetanormaData(fixture)
|
|
65
|
+
expect(store.docType).toBe('international-standard')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('returns empty numbering for unknown id', () => {
|
|
69
|
+
const store = useDocumentStore()
|
|
70
|
+
store.processMetanormaData(fixture)
|
|
71
|
+
expect(store.getNumbering('nonexistent')).toBe('')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('extracts schema version', () => {
|
|
75
|
+
const store = useDocumentStore()
|
|
76
|
+
store.processMetanormaData(fixture)
|
|
77
|
+
expect(store.documentMeta?.schemaVersion).toBe('v2.1.5')
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('document content structure validation', () => {
|
|
82
|
+
it('contains all expected top-level sections', () => {
|
|
83
|
+
const store = useDocumentStore()
|
|
84
|
+
store.processMetanormaData(fixture)
|
|
85
|
+
const content = store.mirrorDocument!.content!
|
|
86
|
+
const types = content.map(n => n.type)
|
|
87
|
+
expect(types).toContain('foreword')
|
|
88
|
+
expect(types).toContain('clause')
|
|
89
|
+
expect(types).toContain('references')
|
|
90
|
+
expect(types).toContain('terms')
|
|
91
|
+
expect(types).toContain('footnotes')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('clause sections have attrs with id and title', () => {
|
|
95
|
+
const store = useDocumentStore()
|
|
96
|
+
store.processMetanormaData(fixture)
|
|
97
|
+
const content = store.mirrorDocument!.content!
|
|
98
|
+
const clause = content.find(n => n.type === 'clause' && (n as any).attrs?.id === 'scope')
|
|
99
|
+
expect(clause).toBeDefined()
|
|
100
|
+
expect((clause as any).attrs.title).toBe('Scope')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('paragraphs contain text nodes with marks', () => {
|
|
104
|
+
const store = useDocumentStore()
|
|
105
|
+
store.processMetanormaData(fixture)
|
|
106
|
+
const content = store.mirrorDocument!.content!
|
|
107
|
+
// Find scope clause, first paragraph
|
|
108
|
+
const scope = content.find(n => (n as any).attrs?.id === 'scope') as any
|
|
109
|
+
expect(scope).toBeDefined()
|
|
110
|
+
const para = scope.content.find((n: any) => n.type === 'paragraph')
|
|
111
|
+
expect(para).toBeDefined()
|
|
112
|
+
const strongNode = para.content.find((n: any) => n.marks?.some((m: any) => m.type === 'strong'))
|
|
113
|
+
expect(strongNode).toBeDefined()
|
|
114
|
+
expect(strongNode.text).toBe('the test methods')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('contains bullet lists with list_items', () => {
|
|
118
|
+
const store = useDocumentStore()
|
|
119
|
+
store.processMetanormaData(fixture)
|
|
120
|
+
const content = store.mirrorDocument!.content!
|
|
121
|
+
const scope = content.find(n => (n as any).attrs?.id === 'scope') as any
|
|
122
|
+
const list = scope.content.find((n: any) => n.type === 'bullet_list')
|
|
123
|
+
expect(list).toBeDefined()
|
|
124
|
+
expect(list.content.length).toBe(3)
|
|
125
|
+
expect(list.content[0].type).toBe('list_item')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('contains tables with head and body', () => {
|
|
129
|
+
const store = useDocumentStore()
|
|
130
|
+
store.processMetanormaData(fixture)
|
|
131
|
+
const content = store.mirrorDocument!.content!
|
|
132
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
133
|
+
const table = testMethods.content.find((n: any) => n.type === 'table')
|
|
134
|
+
expect(table).toBeDefined()
|
|
135
|
+
expect(table.content.some((n: any) => n.type === 'table_head')).toBe(true)
|
|
136
|
+
expect(table.content.some((n: any) => n.type === 'table_body')).toBe(true)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('contains admonition blocks', () => {
|
|
140
|
+
const store = useDocumentStore()
|
|
141
|
+
store.processMetanormaData(fixture)
|
|
142
|
+
const content = store.mirrorDocument!.content!
|
|
143
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
144
|
+
const admonition = testMethods.content.find((n: any) => n.type === 'admonition')
|
|
145
|
+
expect(admonition).toBeDefined()
|
|
146
|
+
expect(admonition.attrs.type).toBe('warning')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('contains sourcecode with language', () => {
|
|
150
|
+
const store = useDocumentStore()
|
|
151
|
+
store.processMetanormaData(fixture)
|
|
152
|
+
const content = store.mirrorDocument!.content!
|
|
153
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
154
|
+
const code = testMethods.content.find((n: any) => n.type === 'sourcecode')
|
|
155
|
+
expect(code).toBeDefined()
|
|
156
|
+
expect(code.attrs.language).toBe('python')
|
|
157
|
+
expect(code.attrs.text).toContain('moisture_content')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('contains figure with image', () => {
|
|
161
|
+
const store = useDocumentStore()
|
|
162
|
+
store.processMetanormaData(fixture)
|
|
163
|
+
const content = store.mirrorDocument!.content!
|
|
164
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
165
|
+
const figure = testMethods.content.find((n: any) => n.type === 'figure')
|
|
166
|
+
expect(figure).toBeDefined()
|
|
167
|
+
expect(figure.attrs.title).toContain('Grain structure')
|
|
168
|
+
const image = figure.content.find((n: any) => n.type === 'image')
|
|
169
|
+
expect(image).toBeDefined()
|
|
170
|
+
expect(image.attrs.src).toBe('grain.png')
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it('contains ordered list', () => {
|
|
174
|
+
const store = useDocumentStore()
|
|
175
|
+
store.processMetanormaData(fixture)
|
|
176
|
+
const content = store.mirrorDocument!.content!
|
|
177
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
178
|
+
const ol = testMethods.content.find((n: any) => n.type === 'ordered_list')
|
|
179
|
+
expect(ol).toBeDefined()
|
|
180
|
+
expect(ol.content.length).toBe(3)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('contains quote block', () => {
|
|
184
|
+
const store = useDocumentStore()
|
|
185
|
+
store.processMetanormaData(fixture)
|
|
186
|
+
const content = store.mirrorDocument!.content!
|
|
187
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
188
|
+
const quote = testMethods.content.find((n: any) => n.type === 'quote')
|
|
189
|
+
expect(quote).toBeDefined()
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it('contains formula block', () => {
|
|
193
|
+
const store = useDocumentStore()
|
|
194
|
+
store.processMetanormaData(fixture)
|
|
195
|
+
const content = store.mirrorDocument!.content!
|
|
196
|
+
const testMethods = content.find(n => (n as any).attrs?.id === 'test-methods') as any
|
|
197
|
+
const formula = testMethods.content.find((n: any) => n.type === 'formula')
|
|
198
|
+
expect(formula).toBeDefined()
|
|
199
|
+
expect(formula.attrs.text).toContain('m =')
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('contains nested clause (term)', () => {
|
|
203
|
+
const store = useDocumentStore()
|
|
204
|
+
store.processMetanormaData(fixture)
|
|
205
|
+
const content = store.mirrorDocument!.content!
|
|
206
|
+
const terms = content.find(n => (n as any).attrs?.id === 'terms') as any
|
|
207
|
+
const nestedClause = terms.content.find((n: any) => n.type === 'clause')
|
|
208
|
+
expect(nestedClause).toBeDefined()
|
|
209
|
+
expect(nestedClause.attrs.id).toBe('term-rice')
|
|
210
|
+
// Should contain example and note children
|
|
211
|
+
const childTypes = nestedClause.content.map((n: any) => n.type)
|
|
212
|
+
expect(childTypes).toContain('example')
|
|
213
|
+
expect(childTypes).toContain('note')
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it('contains footnotes section', () => {
|
|
217
|
+
const store = useDocumentStore()
|
|
218
|
+
store.processMetanormaData(fixture)
|
|
219
|
+
const content = store.mirrorDocument!.content!
|
|
220
|
+
const footnotes = content.find(n => n.type === 'footnotes')
|
|
221
|
+
expect(footnotes).toBeDefined()
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
describe('fallback behavior (no toc.sections)', () => {
|
|
226
|
+
it('extracts TOC from content when toc.sections absent', () => {
|
|
227
|
+
const store = useDocumentStore()
|
|
228
|
+
const data = {
|
|
229
|
+
type: 'doc',
|
|
230
|
+
content: [
|
|
231
|
+
{ type: 'clause', attrs: { id: 's1', title: 'Scope' }, content: [] },
|
|
232
|
+
{ type: 'paragraph', content: [{ type: 'text', text: 'hello' }] },
|
|
233
|
+
{ type: 'terms', attrs: { id: 't1', title: 'Terms' }, content: [] },
|
|
234
|
+
],
|
|
235
|
+
}
|
|
236
|
+
store.processMetanormaData(data)
|
|
237
|
+
expect(store.sections.length).toBe(2)
|
|
238
|
+
expect(store.sections[0].id).toBe('s1')
|
|
239
|
+
expect(store.sections[1].id).toBe('t1')
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it('extracts title from meta fallback', () => {
|
|
243
|
+
const store = useDocumentStore()
|
|
244
|
+
const data = {
|
|
245
|
+
type: 'doc',
|
|
246
|
+
meta: { title: 'From Meta' },
|
|
247
|
+
attrs: { title: 'From Attrs' },
|
|
248
|
+
content: [],
|
|
249
|
+
}
|
|
250
|
+
store.processMetanormaData(data)
|
|
251
|
+
expect(store.title).toBe('From Meta')
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it('falls back to attrs title', () => {
|
|
255
|
+
const store = useDocumentStore()
|
|
256
|
+
const data = {
|
|
257
|
+
type: 'doc',
|
|
258
|
+
attrs: { title: 'From Attrs' },
|
|
259
|
+
content: [],
|
|
260
|
+
}
|
|
261
|
+
store.processMetanormaData(data)
|
|
262
|
+
expect(store.title).toBe('From Attrs')
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('uses default title when none provided', () => {
|
|
266
|
+
const store = useDocumentStore()
|
|
267
|
+
const data = { type: 'doc', content: [] }
|
|
268
|
+
store.processMetanormaData(data)
|
|
269
|
+
expect(store.title).toBe('Metanorma Document')
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
})
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { setActivePinia, createPinia } from 'pinia'
|
|
3
|
+
import { useDocumentStore } from '../documentStore'
|
|
4
|
+
|
|
5
|
+
describe('useDocumentStore', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
setActivePinia(createPinia())
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
describe('defaults', () => {
|
|
11
|
+
it('has null document before loading', () => {
|
|
12
|
+
const store = useDocumentStore()
|
|
13
|
+
expect(store.mirrorDocument).toBeNull()
|
|
14
|
+
expect(store.documentMeta).toBeNull()
|
|
15
|
+
expect(store.title).toBe('Metanorma Document')
|
|
16
|
+
expect(store.flavor).toBe('')
|
|
17
|
+
expect(store.sections).toEqual([])
|
|
18
|
+
expect(store.numbering).toEqual({})
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('processMetanormaData', () => {
|
|
23
|
+
it('processes a doc with attrs', () => {
|
|
24
|
+
const store = useDocumentStore()
|
|
25
|
+
store.processMetanormaData({
|
|
26
|
+
type: 'doc',
|
|
27
|
+
attrs: { title: 'ISO 9001', flavor: 'iso' },
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'clause',
|
|
31
|
+
attrs: { id: 'scope', title: 'Scope', number: '1' },
|
|
32
|
+
content: [],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'clause',
|
|
36
|
+
attrs: { id: 'defs', title: 'Definitions', number: '3' },
|
|
37
|
+
content: [],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
expect(store.mirrorDocument).not.toBeNull()
|
|
43
|
+
expect(store.title).toBe('ISO 9001')
|
|
44
|
+
expect(store.flavor).toBe('iso')
|
|
45
|
+
expect(store.sections).toHaveLength(2)
|
|
46
|
+
expect(store.sections[0]).toEqual({
|
|
47
|
+
id: 'scope',
|
|
48
|
+
title: 'Scope',
|
|
49
|
+
type: 'clause',
|
|
50
|
+
children: [],
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('processes nested sections for TOC', () => {
|
|
55
|
+
const store = useDocumentStore()
|
|
56
|
+
store.processMetanormaData({
|
|
57
|
+
type: 'doc',
|
|
58
|
+
attrs: { title: 'Test' },
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'clause',
|
|
62
|
+
attrs: { id: 's1', title: 'Section 1' },
|
|
63
|
+
content: [
|
|
64
|
+
{
|
|
65
|
+
type: 'clause',
|
|
66
|
+
attrs: { id: 's1-1', title: 'Subsection 1.1' },
|
|
67
|
+
content: [],
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
expect(store.sections).toHaveLength(1)
|
|
75
|
+
expect(store.sections[0].children).toHaveLength(1)
|
|
76
|
+
expect(store.sections[0].children[0].id).toBe('s1-1')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('ignores non-section blocks in TOC extraction', () => {
|
|
80
|
+
const store = useDocumentStore()
|
|
81
|
+
store.processMetanormaData({
|
|
82
|
+
type: 'doc',
|
|
83
|
+
content: [
|
|
84
|
+
{ type: 'paragraph', content: [{ type: 'text', text: 'Hello' }] },
|
|
85
|
+
{ type: 'clause', attrs: { id: 'scope', title: 'Scope' }, content: [] },
|
|
86
|
+
{ type: 'bullet_list', content: [] },
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
expect(store.sections).toHaveLength(1)
|
|
91
|
+
expect(store.sections[0].type).toBe('clause')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('uses toc data when provided', () => {
|
|
95
|
+
const store = useDocumentStore()
|
|
96
|
+
store.processMetanormaData({
|
|
97
|
+
type: 'doc',
|
|
98
|
+
attrs: { title: 'Has TOC' },
|
|
99
|
+
content: [],
|
|
100
|
+
toc: {
|
|
101
|
+
sections: [
|
|
102
|
+
{ id: 's1', title: 'Section 1', type: 'clause', children: [] },
|
|
103
|
+
],
|
|
104
|
+
numbering: { s1: '1' },
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
expect(store.sections).toHaveLength(1)
|
|
109
|
+
expect(store.numbering).toEqual({ s1: '1' })
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('uses meta fields when present', () => {
|
|
113
|
+
const store = useDocumentStore()
|
|
114
|
+
store.processMetanormaData({
|
|
115
|
+
type: 'doc',
|
|
116
|
+
attrs: {},
|
|
117
|
+
content: [],
|
|
118
|
+
meta: { title: 'Meta Title', flavor: 'iec' },
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
expect(store.title).toBe('Meta Title')
|
|
122
|
+
expect(store.flavor).toBe('iec')
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
describe('getNumbering', () => {
|
|
127
|
+
it('returns numbering for known id', () => {
|
|
128
|
+
const store = useDocumentStore()
|
|
129
|
+
store.processMetanormaData({
|
|
130
|
+
type: 'doc',
|
|
131
|
+
content: [],
|
|
132
|
+
toc: { sections: [], numbering: { scope: '1' } },
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
expect(store.getNumbering('scope')).toBe('1')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('returns empty string for unknown id', () => {
|
|
139
|
+
const store = useDocumentStore()
|
|
140
|
+
expect(store.getNumbering('unknown')).toBe('')
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
})
|