Repository navigation
feat(odt): conditionals for OpenDocument Text templates (#138) - #211
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds conditionals to
OdtTemplateProcessor:{{#if}},{{#elseif}},{{#else}}and{{/if}}, with the full 1.7.0 condition engine. This is the second step of OpenDocument Text support.Part of #138
Design
Follows
docs/superpowers/specs/2026-09-26-odt-support-design.md(phase 2). The spec gains §8.1, which records the list decision below.The ODT engine works like the Word pipeline:
InlineConditionalParserandConditionalEvaluator. Only marker text and non-matching branch text is removed, and kept text retains its spans.{{#if}},{{#elseif}}after{{#else}}, several row markers in one row, and a malformed condition evaluates to false with anExpressionFailedwarning. Messages are unchanged, and errors surface as a failedProcessingResult.Design decision (lists), made conservatively and documented in spec §8.1. In ODF, list items are nested containers, not paragraphs as in Word. So:
{{/if}}" error.Container integrity:
text:p.Changes
OpenDocument/OdtMarkerText: marker text of paragraphs, rows, cells, list items and single-item lists. Text boxes, notes and annotations are excluded.OpenDocument/OdtConditionalBlock,OdtConditionalDetector: block, table-row and list-item detection. This is a port ofConditionalDetectoroverXElement. A container that holds a complete conditional is not treated as a marker.OpenDocument/OdtConditionalProcessor: evaluates branches and resolves inline conditionals. This is the counterpart ofConditionalVisitor.OdtTemplateEngine: conditional step per block sequence, per row container (table, header rows, row groups) and per list, plus the container-integrity rules above.OdtTemplateProcessorupdated to describe what is now supported.No DOCX file was touched.
Tests
Odt/OdtConditionalTests: 31 test methods.elseifchains, nested blocks, removed branches not reporting missing variables.and,in,contains,not,is empty, grouping,exists), conditions containingtext:s, malformed condition → warning.{{#if}}and{{#elseif}}after{{#else}}→ failure; marker paragraphs removed with their other text, as in Word.Conditionals_RoundTripThroughLibreOffice): block, inline with span, table row and list items. All 4 LibreOffice tests passed locally on net8.0, net9.0 and net10.0 (LibreOffice 25, macOS).dotnet format --verify-no-changes.Public API impact: additive
No new public symbols.
OdtTemplateProcessor(unreleased, added in #210) now evaluates conditionals, and its XML docs describe this.PublicAPI.Shipped.txtandPublicAPI.Unshipped.txtare unchanged.