Markdown supports inline HTML, including advanced functionality like Javascript.
Some caveats must be noted when including <script>
tags within your content.
Since loading inline javascript cannot be done the same as regular HTML content, the CMS extracts out any inline scripts and loads them separately in the footer of the page.
These scripts are loaded after the document has been rendered and in the order in which they appear in the document. This allows your scripts to be at the top of the markdown page, middle, or anywhere.
Just like with native HTML, scripts are supported with no additional workarounds required.
This is an amazing article about dogs. [See More](#){#see-more-link}
<script>
document.getElementById('see-more-link').href = 'https://example.com';
</script>
Use of IIFE (() => { ... })()
is not required as inline scripts
will automatically get wrapped prior to rendering to the page to prevent
scope issues.
To support nested HTML tags, the CMS will only match the end tag if it is at the beginning of the line.
eg: if your content is:
<script>
console.log('Hello World');</script>
You will probably have a bad time; DO NOT DO THIS.
Have your </script>
on its own line with no indentation.
To prevent javascript from double-executing, the backend portion of the CMS will
remove any <script>
tags from the page content prior to rendering on the initial page load.
This means that using curl
or similar tools will return the page without the inline
<script>
tags within body content.
If you require scripts to be available via command-line tools and external direct calls, use a dedicated javascript file instead of an inline script.
HTML templates such as index.html
and those within layouts/
are not rendered server-side
and thus their script tags are not modified.
This does mean that their execution is affected by the double-execution issue
of the browser first rendering the server-generated version,
so care must be taken with these to ensure proper execution.
Example: make use of cms:route
or other events as documented in the CMS events