-
Hi! I usually export my slides to PDF, making them static, but I've been thinking recently about using the HTML export to take advantage of the interaction with the content (like form components). An idea came to my mind, and I wonder if Marp supports adding JS to, let's say... take data from an API and populate a dynamic table OR make a chart using Chart JS OR using a canvas and D3 JS to create some fancy graph... all inside the HTML slide. Something like MDX on Astro, don't take me wrong, I've used Marp and Markdown for a year or more and I love ❤️ the simplicity of just writing my ideas on a text editor (VS Code) without worrying about styling (with a custom theme, previously made)... but the idea of using Markdown with JS seems interesting in some scenarios. Given that I use Marp to make my slides to teach Computer Sciences topics like Data Structures, OOP, Discrete Mathematics and other related subjects, having the chance to use JS libraries like GoJS or SigmaJS to make interesting diagrams, charts and graphs, could be really cool 👍 I understand clearly that the idea behind Marp is to keep it compatible the Common Markdown Specification, but let's get wild thinking WHAT IF...
I'll try some experiments 🥽⚗️later... and if it work I'll inform you 👍 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
CommonMark has HTML tag transparency for using JavaScript through Just as you thought, Marp allows putting client-side JavaScript into Markdown to render dynamic contents on the browser, and injecting server-side JavaScript as Marp plugin to provide new syntax into Markdown. Our slides output is not depending on any frontend frameworks, so you can start from vanilla JavaScript (or integrate Marp Core with the framework you like). A following example is using Chart.js in Marp. By enabling HTML in Marp tools, you can render chart within Marp slides. ---
marp: true
---
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
<div style="width:80%"><canvas id="bar-chart"></canvas></div>
<script type="module">
const data = [
{ year: 2010, count: 10 },
{ year: 2011, count: 20 },
{ year: 2012, count: 15 },
{ year: 2013, count: 25 },
{ year: 2014, count: 22 },
{ year: 2015, count: 30 },
{ year: 2016, count: 28 },
];
new Chart(
document.getElementById('bar-chart'),
{
type: 'bar',
data: {
labels: data.map(row => row.year),
datasets: [
{
label: 'Acquisitions by year',
data: data.map(row => row.count)
}
]
}
}
);
</script> |
Beta Was this translation helpful? Give feedback.
CommonMark has HTML tag transparency for using JavaScript through
<script>
element. For security reason, Marp is blocked HTML tags for executing scripts by default, but it's up to you to allow that. :)Just as you thought, Marp allows putting client-side JavaScript into Markdown to render dynamic contents on the browser, and injecting server-side JavaScript as Marp plugin to provide new syntax into Markdown. Our slides output is not depending on any frontend frameworks, so you can start from vanilla JavaScript (or integrate Marp Core with the framework you like).
A following example is using Chart.js in Marp. By enabling HTML in Marp tools, you can render chart within Marp slides.