Class MjmlPreprocessor

java.lang.Object
dev.jcputney.mjml.parser.MjmlPreprocessor

public final class MjmlPreprocessor extends Object
Preprocesses MJML source before XML parsing.

MJML ending tags (mj-text, mj-button, mj-table, mj-raw, mj-navbar-link, etc.) can contain arbitrary HTML which is not valid XML. This preprocessor wraps the content of these tags in CDATA sections so the JDK XML parser can handle them.

Also replaces HTML named entities with numeric character references since the XML parser only supports the 5 XML entities.

  • Method Details

    • preprocess

      public static String preprocess(String mjml)
      Preprocesses MJML source for XML parsing. Wraps ending tag content in CDATA sections and replaces HTML entities.
      Parameters:
      mjml - the raw MJML source string to preprocess
      Returns:
      the preprocessed MJML string ready for XML parsing