Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mj-html-attributes support #3

Open
sitepark-veltrup opened this issue Mar 6, 2024 · 2 comments
Open

mj-html-attributes support #3

sitepark-veltrup opened this issue Mar 6, 2024 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@sitepark-veltrup
Copy link

The README says:

mj-html-attributes: will not be supported, as it requires a css selector

Could it be supported by using a different HTML parser?

Jsoup also supports CSS selectors. See Use CSS selectors to find elements

@syjer
Copy link
Member

syjer commented Mar 6, 2024

Hi @sitepark-veltrup , about using jsoup: unfortunately, as mjml is a mix of xml/html, you can't really use a standard html parser: I did extend my own one with a series of custom hacks for handling some non intuitive cases:

var nodes = JFiveParse.parseFragment(template, EnumSet.of(Option.DISABLE_IGNORE_TOKEN_IN_BODY_START_TAG, Option.INTERPRET_SELF_CLOSING_ANYTHING_ELSE, Option.DONT_TRANSFORM_ENTITIES));
. ( see https://github.com/digitalfondue/jfiveparse?tab=readme-ov-file#special-parsing-options for a more in depth description)

My initial goal was to have a swappable html parser, but from some initial testing, it was not really possible as the parsed html was not generating the same DOM structure (you need some special handling for "tr/td" elements outside of tables and also for custom self closing elements).

If there is enough interest, what I'll most likely do is implement a subset of the css selector rules (the most common ones).

My html parser already has a Java api for selectors, I would "only" need to do a "css rules" string to java api conversion.

If you have some css rules that you consider to use / you are using in your templates, it would be nice if you could share them so I can understand how much effort I would need for covering your case.

@syjer syjer added enhancement New feature or request question Further information is requested labels Mar 6, 2024
@sitepark-veltrup
Copy link
Author

Hi @syjer,

thanks for the quick feedback.
First of all, that's great that you have created a pure Java implementation for MJML.

I am still evaluating to what extent this could be used productively for us and don't have any concrete cases yet. The limitation just caught my eye and I wondered if there might be a way forward in the future.

I'll be happy to get back to you if I have any cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants