Convert Markdown to Plain Text for Comparison

What Markdown-to-plain-text conversion removes and keeps, how the main stripping approaches compare for formatting-insensitive diffs, and what to check before you rely on the output.

When two versions of a Markdown document differ only in formatting, a line-by-line diff can still flag dozens of changes. Converting both versions to plain text first removes that noise, so the comparison shows changes in wording. This guide explains what the conversion changes, how the common approaches differ, and where the output stops being reliable.

What converting Markdown to plain text changes

Markdown source is already plain text. Converting it means removing the syntax characters that tell a renderer how to display the content. Examples include asterisks and underscores for emphasis, hash marks before headings, list markers, blockquote markers, backticks and code fences, table pipes, and the brackets and targets around links. The result is a new sequence of stored characters. The conversion is not a visual effect: it does not reverse character order, mirror glyphs, swap letters for Unicode lookalikes, or depend on CSS or bidirectional display rules.

Some things fall outside the conversion. Styling that exists only in a rendered view, such as fonts and colors applied by a stylesheet, is not in the source, so there is nothing to strip. Characters that look like formatting but are ordinary content also stay. Mathematical bold or italic letters copied from a font generator are distinct Unicode code points, not Markdown, so a converter leaves them as they are. Invisible characters also survive unless you normalize them separately. These include zero-width spaces, non-breaking spaces and bidirectional control marks, and any of them can make two visually identical lines compare as different.

Every converter has to decide what to do with each element type. Two outputs are only comparable if both were produced with the same decisions:

  • Links: keep only the visible link text, keep the text and the target, or drop both
  • Images: keep the alt text, insert a placeholder, or remove them
  • Code: keep inline code and code block contents and drop the backticks and fences, or exclude code entirely
  • Tables: drop the pipes and alignment row, and choose how cells are separated, such as tabs, spaces or one cell per line
  • Lists: drop bullets and numbers but keep one item per line, or merge items into running text
  • Headings: drop the hash marks or underline rules and keep the heading as its own line
  • Escapes and entities: turn a backslash-escaped asterisk into a literal asterisk, and decode entities such as the ampersand entity into the character they represent
  • Embedded HTML: strip tags, keep tag contents, or leave the HTML in place
  • Line breaks: keep the source wrapping, or join each paragraph onto a single line

Illustrative example, not output from a tested tool. The input is a short Markdown snippet. In the output, link text is kept, the link target is dropped, and list items stay on separate lines. The word TARGET stands in for a link destination.

## Setup

Install the **CLI** and read the [release notes](TARGET).

- Run `init`
- Edit *config*
Setup

Install the CLI and read the release notes.

Run init
Edit config

Why strip formatting before comparing

Diff tools usually report changes line by line. Many edits that leave the wording untouched still change lines:
• switching emphasis from asterisks to underscores
• rewrapping a paragraph at a different width
• renumbering a list
• converting inline links to reference-style links
Converting both versions with identical settings removes these changes, so the remaining differences are mostly wording changes.

The tradeoff is that formatting-only changes become invisible, and sometimes they matter. A link target can change while its text stays the same. A warning can lose its bold emphasis. A code span can become ordinary prose. If any of these would count as a real change for your review, either keep link targets in the converted output or run a second comparison on the raw Markdown.

Which approach suits your comparison

The approaches below differ in several ways:
• how accurately they handle edge cases
• how much control you have over what is kept
• whether the same input always produces the same output
• how much setup they need
None of them is reversible. Plain text cannot regenerate the original Markdown, so keep the source files and treat the converted text as a comparison artifact only.

Approach | How it works | Strengths | Tradeoffs | Best suited to
Pattern-based stripping | Search-and-replace rules or regular expressions remove syntax characters | Quick to set up, easy to run in a script, no parser needed | Cannot tell Markdown syntax from literal characters, so it can damage underscores in identifiers, arithmetic asterisks, nested emphasis and code | Simple, consistently formatted documents where occasional errors are acceptable
Parser-based conversion | A Markdown parser builds a document tree, and only its text content is written out | Follows the parsing rules of the chosen Markdown flavor, handles nesting and escapes, and lets you decide per element what to keep | Needs a parser for the flavor you use, and different parsers may disagree on edge cases | Most comparison work, especially technical or mixed-content documents
Render to HTML, then extract text | The Markdown is rendered to HTML and the visible text is taken from the HTML | Reuses an existing rendering pipeline and gives text close to what readers see | Adds a step, and spacing between block elements depends on the extraction method | Pipelines that already produce HTML
Diff options without conversion | The raw Markdown is compared with the diff tool's whitespace or ignore options turned on | No conversion step, and formatting changes stay visible if wanted | Whitespace options do not remove syntax characters, so emphasis or list-marker changes still show | Reviews where formatting changes are mostly whitespace and rewrapping
Manual cleanup | A person removes the formatting by hand | Full judgment over ambiguous cases | Slow, inconsistent between versions, and hard to repeat | One-off comparisons of very short passages

Recommendation: use a parser-based converter set to the same Markdown flavor as your documents. Pattern-based stripping is fine for quick checks on simple prose. Avoid it when the text contains code, identifiers or literal symbols.

Illustrative comparison using the same input line. This shows what a naive pattern could produce, not the observed output of any particular tool. The naive rules remove any text wrapped in single underscores or single asterisks.

Input:
Use **snake_case** names like my_var_name and 2 * 3 * 4.

Naive pattern stripping (illustrative):
Use snake_case names like myvarname and 2  3  4.

Parser following CommonMark emphasis rules (illustrative):
Use snake_case names like my_var_name and 2 * 3 * 4.

Two parsing rules explain the difference. Under CommonMark, underscores inside a word do not create emphasis. Asterisks surrounded by spaces cannot open or close emphasis either. A parser that follows those rules keeps the characters, while the naive pattern deletes them. The naive output therefore introduces a false difference and also changes what the text says.

Converting removes the syntax, but stray differences can remain. A normalization pass after conversion reduces them further:

  • Use the same line endings and character encoding for both files, for example UTF-8 with LF line endings
  • Collapse runs of spaces and remove trailing whitespace
  • Put each paragraph, or each sentence, on its own line so that rewrapping does not create differences
  • Decide whether curly and straight quotes and different dash types should count as different
  • Apply the same Unicode normalization form to both files. NFC merges different encodings of the same accented letter. NFKC also folds compatibility characters, such as mathematical bold letters, into ordinary letters, but it changes other characters too, such as ligatures and superscript digits
  • Remove or make visible zero-width and bidirectional control characters

Will the plain-text output remain readable and usable

Copying and pasting: the output consists of ordinary characters, so it pastes unchanged into plain-text fields and diff tools. Other destinations may treat the text as markup again. A Markdown-aware editor, chat box or wiki may reformat lines that still begin with a number and a period, a hash mark, or a greater-than sign. Before you rely on pasted text, check how the destination handles it, or paste into a field that accepts only plain text.

Readability and accessibility: removing syntax also removes structure. Headings, list nesting, table relationships and the difference between code and prose become plain lines. Screen readers depend on that structure to navigate rendered documents. The stripped text is fine as a working file for comparison, but it should not replace an accessible document for readers. If your source contains Unicode styled letters instead of Markdown emphasis, screen readers may announce them unpredictably, depending on the screen reader and its settings. Test with the assistive technology your readers use instead of assuming one behavior.

Compatibility: both converted files must come from the same converter, version and settings. Markdown flavors differ. GitHub Flavored Markdown, for example, adds tables, task lists and strikethrough to CommonMark, and a converter built for one flavor may leave syntax from another flavor in place. If the two documents were written for different flavors, check the converted output for leftover syntax before comparing.

Sensitive input: an online Markdown-to-text converter may send your document to a remote server unless the service clearly states that processing happens in your browser. This guide has not verified the handling practices of any specific service. For confidential drafts, contracts, credentials or personal data, use a converter that runs on your own machine. If you do use an online tool, read its privacy and retention terms first.

A repeatable comparison workflow

  • Keep both original Markdown files unchanged
  • Choose one converter and one set of rules for links, images, code, tables and lists
  • Convert both files with exactly the same settings
  • Apply the same normalization pass to both outputs
  • Run the diff on the normalized plain text
  • If link targets or emphasis could matter, also diff the raw Markdown and review those changes separately
  • Trace each meaningful difference back to the source files before acting on it

Limits of this guide

No specific converter, website or diff tool was tested for this guide, so all sample outputs above are illustrative. This guide also includes no measurements of accuracy, speed or compatibility. Edge-case behavior depends on the parser and Markdown flavor you use. Before adopting a converter, run it on a few of your own documents, including ones with code, tables and literal symbols.