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

extend functionality to handle "welcome-email" from email-templates repo #3

Closed
FelixSchwarz opened this issue Jan 13, 2021 · 2 comments
Assignees

Comments

@FelixSchwarz
Copy link
Owner

FelixSchwarz commented Jan 13, 2021

The upstream project also hosts a couple of example templates in the email-templates repo. One of these examples is welcome-email.mjml but that template can not processed currently due to shortcomings (even after PR #2) in this Python port:

  File "…/mjml/mjml2html.py", line 168, in mjml_to_html
    content = processing(mjBody, bodyHelpers, applyAttributes)
  File "…/mjml/mjml2html.py", line 74, in processing
    return component.render()
  File "…/mjml/elements/mj_body.py", line 37, in render
    children_str = self.renderChildren()
  File "…/mjml/elements/_base.py", line 144, in renderChildren
    output += renderer(component)
  File "…/mjml/elements/_base.py", line 86, in <lambda>
    renderer = lambda component: component.render()
  File "…/mjml/elements/mj_section.py", line 92, in render
    return self.renderSimple()
  File "…/mjml/elements/mj_section.py", line 98, in renderSimple
    section = self.renderSection()
  File "…/mjml/elements/mj_section.py", line 145, in renderSection
    {self.renderWrappedChildren()}
  File "…/mjml/elements/mj_section.py", line 188, in renderWrappedChildren
    {self.renderChildren(children, renderer=render_child)}
  File "…/mjml/elements/_base.py", line 144, in renderChildren
    output += renderer(component)
  File "…/mjml/elements/mj_section.py", line 178, in render_child
    {component.render()}
  File "…/mjml/elements/mj_column.py", line 122, in render
    column_str = self.renderColumn() if (not self.hasGutter()) else self.renderGutter()
  File "…/mjml/elements/mj_column.py", line 233, in renderColumn
    {self.renderChildren(children, renderer=render_child)}
  File "…/mjml/elements/_base.py", line 144, in renderChildren
    output += renderer(component)
  File "…/mjml/elements/mj_column.py", line 220, in render_child
    {component.render()}
  File "…/mjml/elements/mj_text.py", line 54, in render
    return self._render_content()
  File "…/mjml/elements/mj_text.py", line 69, in _render_content
    content_html = self.getContent() + children_html
  File "…/mjml/core/api.py", line 62, in getContent
    return self.content.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

I noticed the upstream JS code complains about some illegal attributes and the mjml template in general looks pretty convoluted:

Line 2 of welcome-email.mjml (mj-body) — Attribute font-size is illegal
Line 8 of welcome-email.mjml (mj-section) — Attribute vertical-align is illegal
Line 10 of welcome-email.mjml (mj-text) — Attribute padding-top has invalid value: 50 for type Unit, only accepts (px, %) units and 1 value(s)
Line 13 of welcome-email.mjml (mj-section) — Attribute padding-top has invalid value: 20 for type Unit, only accepts (px, %) units and 1 value(s)

Nevertheless I think the Python code should be able to handle that (unless the Python code becomes too messy).

Also there is an upstream pull request to clean up that template by @willhertz but even after applying that change the Python code fails.

  File "…/mjml/mjml2html.py", line 167, in mjml_to_html
    globalDatas.headRaw = processing(mjHead, headHelpers)
  File "…/mjml/mjml2html.py", line 72, in processing
    return component.handler()
  File "…/mjml/elements/head/mj_head.py", line 9, in handler
    return self.handlerChildren()
  File "…/mjml/elements/head/_head_base.py", line 28, in handlerChildren
    return tuple(map(handle_children, childrens))
  File "…/mjml/elements/head/_head_base.py", line 22, in handle_children
    component.handler()
  File "…/mjml/elements/head/mj_attributes.py", line 14, in handler
    tagName = child['tagName']
TypeError: 'NoneType' object is not subscriptable

The Python code must be able to handle the updated template as the upstream validator does not complain about any invalid attributes there.

@FelixSchwarz
Copy link
Owner Author

welcome-email.mjml (current version in the repo) is now rendered correctly, mostly due to commits b4d7d13 and eab6cc4.

@FelixSchwarz FelixSchwarz self-assigned this Jan 14, 2021
@FelixSchwarz
Copy link
Owner Author

FelixSchwarz commented Jan 14, 2021

With 21b2234 I can also render the updated welcome-email.mjml from the mentioned pull request if I remove the style inlining manually (CSS inlining will be implemented in #1).

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

No branches or pull requests

1 participant