MDX JS Library
A browser JavaScript library for turning Markdown into sanitized, static HTML. Add it to any web page, render content with MDX.renderPreview(), and optionally apply themes or presentation-slide formatting.
Quick start
Load the standalone bundle, add a target element, and render a Markdown string.
<script src="https://mdx.openlib.in/js/mdx.min.js" defer></script>
The single bundle includes Marked, DOMPurify, the Markdown renderer, and the export helper. Once loaded, it exposes window.MDX; no separate dependency or export scripts are needed.
document.addEventListener("DOMContentLoaded", () => {
const markdown = "# Hello\n\nRendered with **MDX**.";
const html = MDX.renderPreview(markdown);
document.querySelector("#preview").innerHTML = html;
});
<div id="preview"></div>
Render static HTML
renderPreview returns an HTML string you can insert into your page.
const html = MDX.renderPreview(markdown);
document.querySelector("#preview").innerHTML = html;
The generated HTML is sanitized before it is returned. Your page controls the container layout and typography; load the MDX theme stylesheet if you want the built-in preview themes.
Apply a theme
Load the theme stylesheet and pass the theme name as the third argument.
<link rel="stylesheet"
href="https://mdx.openlib.in/css/mdx.theme.css">
const html = MDX.renderPreview(markdown, "pdf", "warm");
document.querySelector("#preview").innerHTML = html;
Use this themed call in place of the render call above. The stylesheet applies typography and colors; your site controls the surrounding layout, width, and spacing.
Render presentation slides
Use "ppt" mode to split Markdown into slide sections.
const slides = MDX.renderPreview(markdown, "ppt", "executive");
document.querySelector("#deck").innerHTML = slides;
Separate slides with a line containing ---. The result is a sequence of .slide sections; add your own navigation and presentation controls if needed.
Export the MDX preview
The bundle includes an export helper that sends the prepared MDX preview to the browser print dialog.
<script src="https://mdx.openlib.in/js/mdx.min.js" defer></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
MDX.exportPreview({ mode: "pdf", scope: "all" });
});
</script>
Use this helper with the MDX app's preview markup and print styles. Choose “Save as PDF” in the browser's print dialog. For a custom page layout, use your own print CSS or export workflow.
Functions
Core renderer functions and the optional MDX preview export helper.
MDX.renderPreview(markdown, mode, theme)Returns sanitized HTML. Use "pdf" (default) for normal Markdown or "ppt" for slide sections. Theme is optional.MDX.splitSlides(markdown)Returns Markdown slide sections, split on horizontal rules or headings.MDX.registerFolderFiles(fileList)Registers local folder images so matching relative Markdown image paths can resolve.MDX.imageCount()Returns the number of registered image path entries.MDX.exportPreview(options)Opens the browser print dialog for a prepared MDX preview. Options include mode ("pdf"/"ppt"), slide scope ("all"/"current"), and PPT layout ("landscape"/"portrait").READY TO RENDER?
Bring your Markdown.
Open the MDX editor to preview a document or turn it into a presentation.