How can I insert naive javescript in Markdown

Hi all,

I want to insert some Javascript code in Markdown to make a dynamic figure in the content.

But I found it doesn’t work by simply adding

<script> alert('test javascript') </script>

into Markdown.

So what is the right way to inject javascript/HTML code while writing in Markdown?

I know a shortcode is an option but my need is quite simple shortcode is not necessary.

There is no way -at least that I know of- to insert javascript without a shortcode in Hugo.

If this is something you want to use on selected posts and not on every single one, you can make an empty shortcode, call it in the single.html template and then insert whatever script you need in a Markdown file within the empty shortcode’s brackets.

@zeakey Code blocks are supported in markdown with blackfriday but writing executable code is something different. This is something you’ll probably want to do at the templating layer…if for no other reason than separation of concerns is a sound engineering principle. Check out the safeJS templating function in the docs.

2 posts were split to a new topic: Javascript in shortcodes