Script tags in markdown

Dropping script tags into a markdown file I’ve been able to trigger a simple alert() by way of checking to see if it works in principle but now document.innerHTML = "xxx" does not very much at all. So my question is, is this a realistic way to approach creating or modifying document content or am I barking up the wrong tree

If I’m reading your post correctly, you say that something used to work with script tags and now it doesn’t. Could you expand on what used to work? Do you have a sample file you can share?

(I think you might be calling the JS element before it has a chance to get the expected data loaded.)

First time trying this so no, I can’t be sure this actually works.

<script>
InnerHTML = “xxxxx”
</script>

Something a bit more thorough:

<script>
document.addEventListener("load", (event) => {
   let x = document.body.innerHTML;
   document.getElementById("aaa").innerHTML =  "Display the body content:<br>" + x;
 }	
});
</script>

<div id="aaa"> ppppp </div>

Try

window.addEventListener …

instead of

document.addEventListener …

Just what are you trying to accomplish? You want the document to tell you when it is loaded? When it is changed? Something else?

2 Likes

I posted several code samples here. Just search for addEventListener in the forum. The approach works in principle.

Long as I know it should work I’ll be good.

Thanks for your input.

Returning to this; it seems DT is very sensitive to empty lines in between script tags. Anything. more than two empty lines and it won’t run.

The following works:

<script>
alert( "a");
</script>

but this doesn’t:

<script>

alert( "a");

</script>

That’s well-defined behavior for Multi Markdown: empty lines inside HTML elements will introduce p elements that you don’t want. The same happens with CSS inside the MD, btw. And it’s easy to see when you convert the MD to HTML and look at that’s source.

No, DT is not sensitive here. It’s just how MMD works.

3 Likes