Hi there,
Cannot label it myself but this is a suggestion.
Building a custom tool based on MJML, I need to include to metadata inside this document.
My way of doing this for now is to include custom attributes in MJML nodes, based on this idea of a soft validation: https://documentation.mjml.io/#validating-mjml
As far as I understand this module, it's currently hardwired to be a strict validator, and rejects any custom attribute:
package main
import (
"fmt"
"github.com/preslavrachev/gomjml/mjml"
)
const m = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text custom-attr="some-value" font-family="Helvetica" color="#F45E43">
<h1>Title</h1>
<p>Paragraph</p>
<p style="font-family:Comic Sans Ms">Another paragraph</p>
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`
func main() {
r, err := mjml.Render(m)
if err != nil {
panic(err)
}
fmt.Printf("Rendered:\n%.100s\n", r)
}
results in
panic: MJML compilation error:
- Line 5 of (mj-text) - Invalid attribute 'custom-attr' for tag <mj-text>
…
I saw that one can add a hook on unknown attribute using
r, err := mjml.Render(m, func(ro *mjml.RenderOpts) {
ro.InvalidAttributeReporter = func(tagName, attrName string, line int) {
// do something
}
})
but this cannot signal an acceptance.
I would have loved to put a return strings.HasPrefix(attrName, "custom-") in there to make it valid.
Is this a kind of feature you would accept?
If so, in what form? This is quite open as it can be this signature change just wrote (returning a bool), accept a whitelist somehow, implement global validation levels as shown in the first link, …
Hi there,
Cannot label it myself but this is a suggestion.
Building a custom tool based on MJML, I need to include to metadata inside this document.
My way of doing this for now is to include custom attributes in MJML nodes, based on this idea of a soft validation: https://documentation.mjml.io/#validating-mjml
As far as I understand this module, it's currently hardwired to be a strict validator, and rejects any custom attribute:
results in
I saw that one can add a hook on unknown attribute using
but this cannot signal an acceptance.
I would have loved to put a
return strings.HasPrefix(attrName, "custom-")in there to make it valid.Is this a kind of feature you would accept?
If so, in what form? This is quite open as it can be this signature change just wrote (returning a
bool), accept a whitelist somehow, implement global validation levels as shown in the first link, …