I’m working on an email client and trying to keep the css styling that comes in the body data of the email from conflicting with the rest of my app.
There are three potential solutions.
- web component with shadow dom
- iframe
- Parse the body html and customize all class and ids throughout the html so they are unique.
I feel going the shadow dom route is the best option and I’m almost there, but I’m running into an issue with dmx-html. For some reason it is adding the code to the page, but it’s not being displayed. I think it’s because dmx-html doesn’t work in the way I want it. It adds the code below the #shadow-root instead of in it.
If I hardcode it with some test html, then it displays fine.
Here’s an example where I’ve hardcode the container.innerHTML
const template = document.createElement('template');
template.innerHTML = '<div id="email-body-container"></div>';
class EmailBodyComponent extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
shadowRoot.appendChild(template.content.cloneNode(true));
}
connectedCallback() {
const container = this.shadowRoot.getElementById('email-body-container');
const htmlContent = this.getAttribute('html-body');
container.innerHTML = '<div><p>hello world</p></div>';
}
}
customElements.define('email-body', EmailBodyComponent);
So, is there a way to use something like dmx-html to pass an expresssion into the shadow dom?
This is an example of what I’ve used prior to attempting to use a shadow dom.
<email-body dmx-show="payload.parts.where('mimeType', 'text/html', '==')[0].mimeType" dmx-html="payload.parts.where('mimeType', 'text/html' , '==' )[0].body.data.decodeBase64()"></email-body>