Safe Markdown Preview
Render Markdown with GFM tables and footnotes to sanitised HTML and see what was removed.
How it works
Renders Markdown with headings, emphasis, lists, task lists, code, GFM tables, links, images, blockquotes and footnotes into HTML built from a strict allow-list. Raw HTML can be escaped, stripped or sanitised; scripts, event handlers, style attributes and javascript:/vbscript:/data: URLs are removed and listed in a security report. Shows a preview, the sanitised HTML source and a plain-text version.
- A two-pass parser written for this tool: link-reference and footnote definitions are collected first, then blocks (ATX/setext headings, fenced and indented code, blockquotes, nested bullet/ordered lists with task items, GFM tables with alignment, thematic breaks, HTML blocks, paragraphs) and inline syntax (code spans, emphasis, strikethrough, links, images, autolinks, hard breaks, backslash escapes). It follows CommonMark closely but is not a full conformance implementation; rare edge cases (complex emphasis nesting, lazy continuation inside nested lists) can differ.
- All output HTML is generated by the renderer from an allow-list (p, h1–h6, lists, tables, code, a, img, blockquote, …). Text and attribute values are always escaped. Raw HTML is escaped, stripped or passed through a tokenizer that rebuilds only allow-listed tags with allow-listed attributes; script/style/iframe/object/svg and similar elements are removed with their content; on* handlers, style, id and class attributes are dropped.
- URLs (Markdown links, images, href/src attributes) are decoded (entities, escapes) and stripped of control and whitespace characters before the scheme check, so obfuscations like “java	script:” are caught. Allowed: http, https, mailto, tel and relative URLs; data: only for base64 raster images when enabled. Links get rel="nofollow noopener noreferrer".
- Finally the HTML is balanced (stray closing tags dropped, open tags closed) so raw HTML cannot break out of the preview container. The page’s Content-Security-Policy blocks scripts and external images anyway; the preview is rendered from the sanitised HTML only.
Sources
Use this tool in an app
These free programs for your browser have this tool built in, next to everything else the task needs.
Related tools
- Crypto Kitchen – CyberChef-style recipes: chain encodings, compression, hashes, AES, JWT and more, step by step.
How to use Safe Markdown Preview
Render Markdown with GFM tables, task lists and footnotes to sanitised HTML, choose how raw HTML is handled and read the security report of what was removed.
What it is for
Markdown shows up wherever users type: READMEs, comments, tickets, CMS fields, chat bots. Two questions keep coming up: what will this look like? and is the HTML safe to show? This tool answers both. It renders headings, emphasis, lists, task lists, code, GFM tables, links, images, blockquotes and footnotes. It builds the output only from an allow-list of tags. Anything dangerous (scripts, event handlers, style attributes, javascript:/vbscript:/data: URLs) is removed and listed in a security report.
You get a preview, the sanitised HTML and a plain-text version, handy for checking a document or seeing what an attacker's input turns into.
The parser follows CommonMark and GFM closely but isn't a full conformance implementation. It's a preview and audit tool, not a drop-in library for your app.
Worked example
Release notes with table, tasks and footnote renders cleanly: one <h1>, <strong>, <em>, <code> and <del> inline, two task items (one done ☑, one open ☐), three links with rel="nofollow noopener noreferrer", an aligned table, a blockquote with a reference link, an escaped code block (<b> inside it stays literal text) and a footnote. The stats show 46 words, 1 heading, 3 links, 1 table, 2 tasks (1 done) and 1 footnote. Removed or escaped: 0.
XSS attempts (default policy sanitize): the input contains an <img onerror>, a <script>, two javascript: links (one written as JaVaScRiPt:), an SVG data: image, a <div> with onclick and style, a vbscript: link, an <iframe> and an onmouseover handler. Result: removed or escaped: 10, potentially dangerous: 10. That's 3 event handlers, 3 javascript-type URLs, 1 script, 1 data URL, 1 style attribute and 1 iframe. The harmless parts survive: the <b>bold</b> text, the link text, and the https://example.com link without its handler.
*The same input with raw HTML set to escape***: every raw tag is shown as literal text (<script>…). The report lists 8 items, of which only 3 are dangerous: the two javascript links and the data image, which come from Markdown syntax rather than raw HTML.
How to read the result
- html: the sanitised HTML, safe to inspect or copy.
- text: a plain-text version for search indexes, notifications or word counts.
- removed and removedCounts: the security report, one entry per removed element, attribute or URL, with its kind (event-handler, script-element, javascript-url, data-url, style-attribute, disallowed-element, raw-html-escaped).
- stats: counts of headings, links, images, tables, tasks, footnotes and words.
- policy: the settings and allow-listed tags that produced this output.
Tips and common mistakes
- Choose sanitize when users legitimately use a little HTML (
<b>,<br>), escape when you want to show exactly what they typed, and strip to silently drop raw HTML. - Obfuscated URLs such as
java	script:are decoded before the scheme check. Test your own sanitiser against the same examples. idandclassattributes in raw HTML are dropped, so don't rely on them for styling user content.- Data images are off by default. When enabled, only base64 raster formats (PNG, JPEG, GIF, WebP, AVIF) are allowed, never SVG, which can carry scripts.
- Code blocks are always escaped. That's the right place for HTML samples you want to show.
FAQ
Is the preview itself safe to open?
Yes. The preview is built from the sanitised HTML only, and the page's Content-Security-Policy also blocks scripts and external images.
Why is my <div style="…"> styling gone?
style attributes are removed on purpose, because they can be used to overlay fake login forms or hide content. Only allow-listed tags and attributes are kept.
Does it render exactly like GitHub?
Mostly. Tables, task lists, strikethrough, autolinks and footnotes follow GFM, but rare edge cases can differ, so check unusual nesting on GitHub itself.
What counts as "potentially dangerous"?
Items that could run code or load content in a reader's browser: scripts, event handlers, script-type URLs, data URLs, style attributes and embedded frames. Harmless escaped tags are counted as removed but not as dangerous.
Guide last updated:
For scripts and AI agents
- JSON API:
POST https://safemarkdownpreview.usefulweb.site/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://safemarkdownpreview.usefulweb.site/mcp· tool namesafe_markdown_preview
Example request
curl -s -X POST https://safemarkdownpreview.usefulweb.site/api/v1/calculate \
-H 'content-type: application/json' \
-d '{"markdown":"# Release notes\n\nVersion **2.4** brings _faster_ parsing, `inline code` and ~~old bugs~~ fixes.[^perf]\n\n- [x] Tables (GFM)\n- [ ] Footnotes\n- Links: [docs](https://example.com/docs \"Documentation\") and <https://usefulweb.site>\n\n| Feature | Status | Notes |\n|:--------|:------:|------:|\n| Tables | ✓ | GFM |\n| Images | ✓ | allow-listed |\n\n> Quote with a [reference link][ref].\n\n```js\nconsole.log(\"code is escaped: <b>\");\n```\n\n[ref]: https://commonmark.org/\n[^perf]: Measured on a 1 MB document.\n"}'