Skip to content

Keep the Liquid of an MJML file imported into the visual editor, and read it as MJML does - #651

Merged
pierre-b merged 1 commit into
devfrom
feat/mjml-import-liquid
Nov 19, 2026
Merged

pierre-b merged 1 commit into
devfrom
feat/mjml-import-liquid

Conversation

@pierre-b

Copy link
Copy Markdown
Contributor

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 &minus; 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).

  • The MJML export marks each mj-liquid block 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 new liquid_markers field of templates.compile, which only the export button sends, so the text version seed (preserve_liquid too) sees none.
  • In a file without marks, a passage with Liquid between blocks becomes one mj-liquid block 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.go and converter.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/ and openapi.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.
  • The whole console suite, the notifuse_mjml and internal/http packages, and the integration test above pass locally.
  • By hand: the fixture compiled in code mode, and imported into the visual tree then compiled by the server, gives the same totals (138.00, discount 13.80, total 124.20) with no Liquid left.

…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 &minus; 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

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.45%. Comparing base (1aadcf3) to head (fb9478d).

Files with missing lines Patch % Lines
pkg/notifuse_mjml/liquid_markers.go 60.00% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
unit 90.45% <89.47%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pierre-b
pierre-b merged commit d5da9f5 into dev Nov 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant