Insert html/svg markup from .json data source #863
Replies: 4 comments 2 replies
-
Hello there and welcome! 👋🏻 AFAIK, you are not doing anything wrong: for now, there is no way to insert arbitrary HTML into mavo app. And you are right, in Mavo, everything is done through However, this question arises from time to time. I think we'd better ask Lea (@LeaVerou) whether we should provide a way for authors to insert arbitrary HTML (via plugin, might be) or is it a bad idea in general (because of possible XSS attacks)? Is it appropriate for you, as a workaround, to provide <svg>
<path property="path" mv-attribute="d" />
</svg> {
"path": "M 0 100 C 10 50 10 30 50 20 L 50 10 L 100 30 L 50 50 L 50 40 C 25 40 25 50 20 90 z"
} |
Beta Was this translation helpful? Give feedback.
-
When I've needed this before, I used an
There are some questions about how all these interact (e.g. what happens if you set XSS is already possible if someone is not careful with what they throw into expressions, so I don't think this opens up much of an additional attack vector. One potential issue with this is that IIRC we use mutation observers to monitor attribute changes, and a JS property would not fire those, so how do we observe when it changes? Though I think we also propagate changes through the data model. @DmitrySharabin do you want to investigate how feasible it would be to implement this? If it turns out that general JS properties are tough, we could also fall back to only implementing |
Beta Was this translation helpful? Give feedback.
-
Hi there, Seems we all need to integrate external html + properties inside mavo (see #849 and #840) An answer wrotten by @LeaVerou explaining "by the time mavo resolves", give me the idea to try something: 1/ Before mavo executes on the page, I integrate an external page (with properties) using a simple js script
where external.js is:
2/ than as I encapsulate this script with a mv-if condition, mavo will remove it
-> Works fine, but the browser will load all (!) external content , then mavo will hide it behind I also tried using templates + slots,a s explained on #840: where properties need to be declared in main.html (and than passed to exteernal template trought slots): I certainly prefer something with proposed |
Beta Was this translation helpful? Give feedback.
-
I tried writing a plugin but even tho I got access to the element, any attempt to change its content (or any attributes) in either way had no effect. I tried several Hooks and learned the hard way, that debugging in DevTools while also having a Those were my ideas to render the <span mv-raw="label"></span>
<span>[ raw(label) ]</span> and these are the hooks I filled with a buttload of console logs on Mavo.Plugins.register("raw", {
"init-end": (root) => { /* too soon? */ },
"node-render-end": (env) => { /* too late? */ },
/* those can be busy */
"domexpression-init-start": (env) => { /* interesting one */},
"domexpression-init-end": (env) => { },
"node-init-start": (env) => { },
"node-init-end": (env) => { },
"expression-eval-beforeeval": (env) => { }
})
Mavo.attributes.push('mv-raw');
Mavo.Functions.raw = (array, ...properties) => {} Lots of it was from the demos and samples and several of @DmitrySharabin's repos and codepens. Anyhow, I'd like to give this another try just to understand what the hell is going on. I'd love to use Mavo to quickly create interactive design POCs and prototypes I could show off to colleagues and clients :D Is there some explainer how Mavo's processing the DOM? and at what point can I "safely" mess with a node/element that either contains the Thanks - back to RTFM :-) |
Beta Was this translation helpful? Give feedback.
-
Hello,
this is my 2nd day toying with Mavo and I like it! tho I spent a lot of the time reading the docs and studying some demos.
I have an external .json file to mv-init the app with some html and SVG snippets I'd like to use, but I always see the literal markup (like with .textContent) not rendered (like with .innerHTML).
I could not find any info in the docs whether this is prevented by default or needs some "raw" attribute/setting to allow the display of external HTML. (i.e. like Vue's
v-html
directive)Maybe I was also looking in the wrong place. 🤷♂️
Then in the html:
I see this inside the literal html from
label
inside the buttoninstead of just the price , the "italic" element with the emoji inside, the
wbr
and the stringThis is the "app" element:
I want to replace the emojis with SVG later, but given that HTML rendering doesn't work for me...
What am I doing wrong?
Any hint and help appreciated.
Beta Was this translation helpful? Give feedback.
All reactions