How to use the markdown cleaner
- Paste your Markdown source into the Markdown input text area.
- Toggle the checkboxes to choose whether to escape raw HTML, trim trailing spaces, or collapse blank lines.
- The cleaned result appears instantly below as you type or change options.
- Copy the output and use it safely in any renderer or documentation system.
What this markdown cleaner does
This markdown cleaner normalizes your document by applying three optional transformations. First, it can escape raw HTML: every less-than sign that would start a tag, comment or declaration is written as <, so scripts cannot run when the text is rendered. Greater-than signs, ampersands, quotes, autolinks such as <https://example.com> and blockquote markers are left alone, so the Markdown keeps working. Second, it trims trailing whitespace from every line (outside code blocks), which also removes the two trailing spaces that Markdown reads as a hard line break, so turn this option off if your text relies on them. Third, it collapses runs of three or more consecutive newlines down to exactly two, enforcing a single blank line between blocks.
The tool recognizes fenced code blocks (delimited by three or more backticks or tildes) and inline code spans (delimited by backticks). Content inside these structures is never modified, even if HTML escaping is enabled. This ensures your code examples remain intact while the surrounding prose is sanitized.
Supported CommonMark subset
The parser understands a practical subset of the CommonMark specification. It correctly identifies and preserves the following block-level elements: headings (ATX style with one to six hashes), fenced code blocks, unordered lists (using hyphens, asterisks, or plus signs), ordered lists, blockquotes (starting with a greater-than sign), horizontal rules (three or more hyphens, asterisks, or underscores), and simple tables (rows separated by pipes).
For inline formatting, it tracks backtick-delimited code spans so they are not altered. Other inline elements such as emphasis, strong text, links, and images pass through unchanged because the cleaner operates on the raw text rather than building an abstract syntax tree. If you need to convert your document to another format entirely, consider using markdown to html or markdown to text instead.
Why escape raw HTML in Markdown
Many Markdown renderers allow raw HTML to pass through directly into the output. While convenient, this creates a cross-site scripting risk if the Markdown comes from untrusted users. By converting the less-than sign that opens a tag to <, the HTML is displayed as literal text rather than being interpreted by the browser.
For example, the input <img src=x onerror=alert(1)> becomes <img src=x onerror=alert(1)> after cleaning, where the entity at the start is what stops it from being an element. The malicious payload is neutralized. Fenced code blocks and inline code spans are excluded from every transformation, including blank-line collapsing, because code examples must remain exactly as written. Indented code blocks are not detected, so keep code in fences if you use the HTML option.
How the processing works
The algorithm walks the lines in order and tracks fenced code blocks, including fences inside blockquotes and list items. When it encounters a line starting with three or more backticks or tildes, it enters a protected state where no transformations are applied. Once the matching closing fence is found, normal processing resumes.
Outside of fenced blocks, each line is evaluated individually. Inline code spans are located using a secondary scan so that backtick-enclosed text is skipped during HTML escaping. After all line-level operations complete, the global transformations (collapsing blank lines and trimming the final output) are applied. This layered approach keeps the logic simple while avoiding unintended modifications to code.
Combining with other Markdown tools
Cleaning your Markdown is often the first step in a larger workflow. After sanitizing the source, you might want to check it for style issues using a markdown linter, generate a table of contents with a markdown toc generator, or escape special characters for API payloads via markdown escape. If your source material starts as HTML, run it through html to markdown first, then clean the result here. For platform-specific needs, converters like markdown to slack or markdown to bbcode handle the final translation.
Worked examples
| Example | Input | Result |
|---|---|---|
| HTML script tag | Markdown input: # Hello / <script>alert('xss')</script> / Some text.; Escape raw HTML tags: yes; Trim trailing spaces on each line: yes; Collapse multiple blank lines: yes | # Hello / <script>alert('xss')</script> / Some text. |
| Extra blank lines | Markdown input: Line one. / Line two.; Escape raw HTML tags: no; Trim trailing spaces on each line: yes; Collapse multiple blank lines: yes | Line one. / Line two. |
| Trailing spaces | Markdown input: Hello world / Next line ; Escape raw HTML tags: no; Trim trailing spaces on each line: yes; Collapse multiple blank lines: no | Hello world / Next line |
FAQ
Does this markdown cleaner change my formatting?
It only applies the transformations you select: escaping HTML, trimming trailing spaces, and collapsing extra blank lines. Headings, lists, emphasis, links, and other Markdown syntax are left untouched.
Will code inside fenced blocks be escaped?
No. The cleaner detects fenced code blocks and inline code spans, skipping them entirely so your code examples remain valid.
Is my text uploaded to a server?
No. All processing happens locally in your browser. Nothing is transmitted over the network.
Can I use this to remove all Markdown syntax?
This tool cleans and normalizes Markdown but keeps the syntax intact. To strip formatting entirely, use a dedicated markdown to text converter.
What happens if I disable all three options?
The output will be identical to the input. At least one option must be enabled for the cleaner to make changes.
Does it support GitHub Flavored Markdown tables?
Yes. Simple pipe-delimited tables are recognized as block content and preserved without modification.