Repository navigation
Keep the Liquid of an MJML file imported into the visual editor, and read it as MJML does - #651
Merged
Merged
Conversation
…read it as MJML does The visual editor's MJML import read the file with a strict XML parser: a bare &, a < in a Liquid condition, an unclosed <p> or an HTML entity such as − made it fail. It now reads with htmlparser2, as MJML does, and takes the content of text-like blocks as written. Liquid written between blocks is no longer dropped. The MJML export marks Liquid blocks and display conditions with Liquid comments, which render to nothing (liquid_markers on templates.compile), and the import gives them back. In a file without marks, a passage with Liquid between blocks becomes a Liquid block holding its code, with the blocks that read the variables it assigns; the import says how many. The gallery's Blank model is renamed Simple: it holds a logo, a paragraph and the footer.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #651 +/- ##
==========================================
- Coverage 90.46% 90.45% -0.01%
==========================================
Files 391 392 +1
Lines 76439 76454 +15
==========================================
+ Hits 69148 69156 +8
- Misses 4736 4740 +4
- Partials 2555 2558 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What changes
Reading the file. The visual editor's « Import MJML » read the file with a strict XML parser (
DOMParser,text/xml). A bare&, a<in a Liquid condition, quotes in a Liquid filter inside an attribute, an unclosed<p>, an attribute without quotes or an HTML entity such as−made it fail with a syntax error. It now reads with htmlparser2, as MJML does. The content of text-like blocks (mj-text,mj-button,mj-raw…) is taken as written, not parsed. A syntax error names the line where the unclosed tag opens, and the console shows it translated.Liquid between blocks. It used to be dropped (display conditions came back as a warning, loops and
assigns silently).mj-liquidblock and each block's display condition with Liquid comments ({% comment %}notifuse:liquid{% endcomment %},{% comment %}notifuse:condition {JSON}{% endcomment %}). They render to nothing: the marked MJML sends as the unmarked one. The import reads them back. The marks are asked for with the newliquid_markersfield oftemplates.compile, which only the export button sends, so the text version seed (preserve_liquidtoo) sees none.mj-liquidblock holding its exact source, together with the later blocks that read a variable it assigns. Without them, a section showing{{ subtotal_cents }}would lose the value at send, since ordinary blocks render before Liquid blocks. The import says how many passages it kept that way.Gallery. The « Blank » model is renamed « Simple »: it holds a logo, a paragraph and the footer.
Where
console/src/components/mjml-converter/mjml-to-json-browser.ts: the importer, rewritten.pkg/notifuse_mjml/liquid_markers.goandconverter.go: the marks;template_compilation.go:LiquidMarkers.console/src/components/templates/importTemplateFile.ts,ImportExportButton.tsx: the warning, translated errors, the export flag and label.openapi/andopenapi.json:liquid_markers.Flows touched: Liquid rendering (Notifuse/architecture#62).
Tests
console/src/components/mjml-converter/__tests__/mjml-import.test.ts: the cases above, the marks round trip, the fallback rules, and the abandoned-cart export from mjml_builder as a fixture.pkg/notifuse_mjml/liquid_markers_test.go: the mark layout, the escaped JSON, unchanged output without the field, and the HTML of the marked MJML identical to the unmarked one.tests/integration/template_api_test.go:TestTemplateCompileLiquidMarkers.notifuse_mjmlandinternal/httppackages, and the integration test above pass locally.