Convert a Note to Plain Text and the Links Lose Their URLs — What Four Converters Kept, and How to Keep Them
Convert a Markdown note to plain text and the link text survives while the URL does not. In a test on 13 November 2026, all four converters tried — pandoc 3.13, remove-markdown 0.8.0, strip-markdown 6.0.0 and the accepted Stack Overflow recipe — turned [booking page](https://example.com/booking?id=42) into "booking page". Each one has a fix.
None of this is a bug. Plain text has no syntax for a link, so a converter has to decide what a link becomes, and the common default is the words you can read. The URL sits in an attribute, not in the text — a tool that keeps "the text" leaves it behind.
For a page summary that is exactly right. For an email body, a support ticket or an SMS, the URL was the point — the booking ID lived in it.
The question is old and well-trafficked. Four Stack Overflow questions on it have 105,685 views between them, led by "Python : How to convert markdown formatted text to text" at 72,570 1. What follows is one measured receipt: a fixed test note through four default converters, then each tool's own fix, the mechanism read from its source or documentation, and a ten-second test for whatever command you use.
The problem in concrete terms: one note, four converters
The test note is nineteen lines of ordinary Markdown: a heading, one link with a query string, a footnote, an image with alt text, a table, two tasks and a code block. At default settings, all four converters printed the link's words and no URL. The other elements came back four different ways, and some did not come back.
Here is the input, byte for byte:
# Trip plan
Book the table on the [booking page](https://example.com/booking?id=42) before Friday.[^1]

| Day | Stop |
|-----|------|
| Mon | Lyon |
| Tue | Nice |
- [x] passport
- [ ] charger
```
ssh [email protected]
```
[^1]: The restaurant closes early on Friday.
The link is written the portable way — [text](url), the form that survives every renderer — and this is what happens to it when it leaves Markdown altogether.
The four converters were pinned and installed locally: pandoc 3.13 from the official static release, run as -f gfm -t plain; remove-markdown 0.8.0; strip-markdown 6.0.0 on remark 15.0.1, with and without remark-gfm 4.0.1; and Python-Markdown 3.11.3 with Beautiful Soup 4.15.0, running the accepted Stack Overflow answer exactly as posted 2.
The footnote marker after "Friday." varied from tool to tool. The link did not — every one of them printed this:
Book the table on the booking page before Friday.
Counting strip-markdown with and without remark-gfm, and the Python recipe both as posted and with extensions, that is six default outputs. None contained the string example.com/booking 2.
The naive approach: the accepted answer from 2009
The accepted answer on the most-viewed question renders Markdown to HTML, then keeps only the HTML's text. It was posted on 17 April 2009, still carries the green tick, and still runs. On the test note it dropped the URL, deleted the image line, alt text included, and left the table and footnote as raw Markdown.
The answer, by Jason Coon, has a score of 60 and was last edited in July 2021 3. Its reasoning is one sentence: "Once you have converted the markdown to HTML, you can use a HTML parser to strip out the plain text." 3 The code is one line on top of the markdown() call:
text = ''.join(BeautifulSoup(html).findAll(text=True))
The approach is sound. An answer signed Waylan — the name of Python-Markdown's maintainer — on a sibling question calls it "probably the most reliable and consistent solution cross-platform." 4 The weak point is what "text" means to an HTML parser — and it is not the URL.
Beautiful Soup's documentation is precise about it: "If you only want the human-readable text inside a document or tag, you can use the get_text() method. It returns all the text in a document or beneath a tag, as a single Unicode string:" 5 Its own example passes in a document containing <a href="http://example.com/"> and gets back '\nI linked to example.com\n' — the words inside the link, and nothing from its href 5.
That one example is the whole failure — a URL is an attribute. An image's alt text is an attribute too, which is why the image line vanished rather than shrinking to its description 2.
Run exactly as posted, the line now prints three warnings on Beautiful Soup 4.15.0: two DeprecationWarnings (findAll is now find_all, and text= is now string=) and a GuessedAtParserWarning for the missing parser name 2. It still works. It is seventeen years old.
Adding the tables and footnotes extensions and calling get_text() — a common variant — changes the shape but not the link. The table becomes one cell per line, and the footnote marker fuses onto the word before it 2:
Book the table on the booking page before Friday.1
Friday.1 is not a typo in this post. It is the converter's output.
The architecture: where a URL goes when the syntax goes
Every converter here follows one path. It parses the note into a tree, then walks the tree and writes out the parts it considers text. A link node holds two things — its visible words as children, its URL as a property. Write the children, skip the properties, and the URL is gone without any code deciding to delete it.
note.md ──parse──▶ tree ──write the text──▶ note.txt
Link
├── children: "booking page" ──▶ written
└── url: https://…/booking?id=42 ──▶ never visited
Image
├── alt: "map of the route" ──▶ depends on the tool
└── url: route.png ──▶ never visited
pandoc makes the choice explicitly, and its source shows it. In the 3.13 Markdown writer, which also produces plain, the link case has a PlainText branch with two lines. If the link's text is its own URL, it prints the URL: | useAuto -> return $ literal srcSuffix. Otherwise it prints the words: | otherwise -> return linktext 6.
There is no third line. Left to the plain writer alone, a [text](url) link loses its URL every time, and a bare <https://…> autolink keeps it.
The plain writer has a stated model. pandoc's manual says "Use [Project Gutenberg] conventions for plain output:" 7, and a 2015 Stack Overflow answer signed John MacFarlane — the name on pandoc's manual — explains the choice: "The plain text writer was changed to use the general format of Project Gutenberg plain text books. Of course, no choice will please everyone." 8 A Gutenberg book is prose for a reader. It has no hyperlinks to keep.
strip-markdown states its intent in its first line: "This essentially removes everything but paragraphs and text." 9 remove-markdown documents the link case in its own usage example, which turns This is a paragraph with [a link](http://www.disney.com/) in it. into a comment that reads plainText is now 'This is a heading\n\nThis is a paragraph with a link in it.' 10
Nothing is hidden — each tool documents that it keeps link text. The gap is between the documentation and the expectation of someone who wanted the note, without the asterisks.
Not every converter makes this choice. html2text, which turns HTML into Markdown-flavoured text, kept the URL by default in the same test — [booking page](https://example.com/booking?id=42) — and treats dropping links as an opt-in flag, --ignore-links, described as "Don't include any formatting for links" 11 2. The trade is that its output still contains Markdown syntax.
The measurement: what survived at default settings
Five default configurations, one note. All five printed "booking page" with no URL. Beyond the link, pandoc kept the most structure, remove-markdown left table and task syntax in place, strip-markdown deleted the most, and the 2009 recipe deleted the image. Bold marks content that was removed outright 2.
| Element | pandoc 3.13 -t plain | remove-markdown 0.8.0 | strip-markdown 6.0.0 | strip-markdown + remark-gfm | 2009 SO recipe |
|---|---|---|---|---|---|
[booking page](…?id=42) | URL gone | URL gone | URL gone | URL gone | URL gone |
 | [map of the route] | map of the route | map of the route | map of the route | line deleted |
| table | aligned plain table | raw pipes | raw pipes | deleted, with its cells | raw pipes |
- [x] / - [ ] tasks | ☒ / ☐ | [x] / [ ] | \[x] / \[ ] | state lost | [x] / [ ] |
footnote [^1] + definition | [1] + [1] The restaurant… | marker dropped; : The restaurant… | \[^1] (escaped) | marker and definition deleted | [^1] raw |
code block ssh [email protected] | kept, indented | kept | deleted | deleted | kept |
The strip-markdown columns need a word. With remark-gfm loaded — the normal setup for notes with tables and tasks — strip-markdown deleted the six-cell table, the code block, the footnote and both checkbox states 2. Its readme says it will "remove code, html, horizontalRule, table, toml, yaml, and their content" 9.
Without remark-gfm the table survived, but only because remark never parsed it as a table. It stayed a paragraph of pipes. The code block was deleted in both configurations — and in this note, the code block was the server address.
remove-markdown's footnote result is easy to miss. The marker [^1] vanished from the sentence and the definition became a line starting with a colon, so the footnote is still there, unattached to anything 2.
pandoc's footnote is the best of the five: [1] in the text, [1] The restaurant closes early on Friday. at the end. Its image becomes [map of the route] and its table stays a table 2. The link still loses its URL.
A converter that keeps more structure does not keep more links. Structure and URLs are separate decisions.
Code walkthrough: keep the URL, tool by tool
Every converter tested has a way to keep the URL. remove-markdown ships an option that is off by default, strip-markdown can leave links alone, pandoc takes a three-line Lua filter, and the Python recipe needs a short loop over the <a> tags before it takes the text. Each fix has a side effect worth reading first.
The receipt ran each of these against the same test note 2:
| Fix | What the link became | Side effect |
|---|---|---|
remove-markdown {separateLinksAndTexts: ': '} | booking page: https://example.com/booking?id=42 | image became !map of the route: route.png |
remove-markdown {replaceLinksWithURL: true} | https://example.com/booking?id=42 | the words "booking page" are gone |
pandoc --lua-filter link.lua | booking page <https://example.com/booking?id=42> | none seen |
pandoc --reference-links | body still booking page; URL in an end list | undocumented for plain |
strip-markdown {keep: ['link', 'code']} | [booking page](https://…?id=42) | that is Markdown, not plain text |
Python: append href before get_text() | booking page <https://example.com/booking?id=42> | table still one cell per line |
remove-markdown: turn on the option it already has
remove-markdown's readme lists both link options with their defaults: replaceLinksWithURL: true, // remove inline links, if present (default: false) and separateLinksAndTexts: ': ', // replace inline links with text, separator and link, if present (default: null) 10. These are the maintainers' own fix — they are simply off.
// remove-markdown 0.8.0
import removeMd from 'remove-markdown'
const plain = removeMd(markdown, { separateLinksAndTexts: ': ' })
// "Book the table on the booking page: https://example.com/booking?id=42 before Friday."
The readme comment for replaceLinksWithURL says "remove inline links". In the receipt it replaced the link with its URL and dropped the words, which reads well for a bare list of addresses and badly in a sentence 2. separateLinksAndTexts keeps both. Its catch is the image, which printed as !map of the route: route.png, with the exclamation mark left over from ![…] 2.
pandoc: a three-line Lua filter
The plain writer has no switch for this, so the fix is to rewrite links before the writer sees them. A Lua filter replaces each link with its words, a space and the URL in angle brackets:
-- link.lua — pandoc 3.13
function Link(el)
return {pandoc.Str(pandoc.utils.stringify(el.content)), pandoc.Space(), pandoc.Str('<' .. el.target .. '>')}
end
pandoc -f gfm -t plain --lua-filter link.lua note.md
# Book the table on the booking page <https://example.com/booking?id=42>
# before Friday.[1]
Apart from where the line wrapped, the rest of the note came out as it did without the filter 2. The angle brackets earn their place: they mark where the URL ends, which matters because the edge of a bare URL is a guess for whatever reads it next.
pandoc's --reference-links flag also kept the URLs in 3.13, in an unexpected place. The body still read "booking page", and two lines appeared at the end of the output: [booking page]: https://example.com/booking?id=42 and [map of the route]: route.png 2.
The manual documents the flag only for "writing Markdown or reStructuredText" 7. In the 3.13 source, the reference is registered before the plain-text branch returns the bare words, which explains the list 6. Re-run on pandoc 3.14, released on 12 November 2026, the output was byte-identical, and its manual still describes the flag for Markdown and reStructuredText only 2. Treat it as observed behaviour, not a documented feature, and re-test it after every upgrade.
strip-markdown: leave links alone
strip-markdown's keep option is a "list of node types to leave unchanged" 9. Passing ['link'] keeps the URL — by keeping the Markdown link:
// remark 15.0.1, remark-gfm 4.0.1, strip-markdown 6.0.0
import {remark} from 'remark'
import remarkGfm from 'remark-gfm'
import stripMarkdown from 'strip-markdown'
const file = await remark()
.use(remarkGfm)
.use(stripMarkdown, {keep: ['link', 'code']})
.process(markdown)
// "Book the table on the [booking page](https://example.com/booking?id=42) before Friday."
Adding 'code' brought the code block back, fences and all; the table and the footnote were still deleted 2. That output is Markdown with fewer kinds of syntax, not plain text. It suits a destination that tolerates brackets. For one that does not, rewrite the link nodes yourself before stripping, the way the pandoc filter does.
Python: put the URL into the text before taking the text
The 2009 recipe loses the URL because it lives in an attribute. Moving it into the text first fixes that, and the same loop can rescue image alt text and keep footnote numbers bracketed. This version ran against the test note with Python-Markdown 3.11.3 and Beautiful Soup 4.15.0 2:
import sys
from markdown import markdown
from bs4 import BeautifulSoup
md = open(sys.argv[1], encoding='utf-8').read()
html = markdown(md, extensions=['tables', 'footnotes'])
soup = BeautifulSoup(html, 'html.parser')
for a in soup.find_all('a', href=True):
href = a['href']
if href.startswith('#'): # footnote marker or back-link
if 'footnote-backref' in a.get('class', []):
a.decompose()
else:
a.string = f'[{a.get_text()}]'
continue
if a.get_text() != href: # skip bare autolinks
a.append(f' <{href}>')
for img in soup.find_all('img'):
img.replace_with(img.get('alt', ''))
sys.stdout.write(soup.get_text())
It printed Book the table on the booking page <https://example.com/booking?id=42> before Friday.[1], followed by map of the route on its own line 2. The table still came out one cell per line. Tables in plain text are a separate problem.
Waylan's answer points at the cleaner long-term route: "you can create your own renderer which outputs whatever format you want." 4 A renderer that writes text <url> for every link is the durable version of this loop.
Autolinks are not a universal fix
Writing the URL itself into the note, as <https://…>, kept it in most configurations, but not all. A bare autolink survived pandoc, plain strip-markdown, both Python variants and html2text. remove-markdown 0.8.0 deleted it entirely, and strip-markdown with remark-gfm kept it with a backslash inserted. The fix belongs in the converter.
The second test file was one line: See <https://example.com/booking?id=42> now. Here is what came back 2:
pandoc 3.13 See https://example.com/booking?id=42 now.
strip-markdown See https://example.com/booking?id=42 now.
strip-markdown + remark-gfm See https\://example.com/booking?id=42 now.
remove-markdown 0.8.0 See now.
remove-markdown's result is a side effect, not a decision about links. Its 0.8.0 source strips HTML with /<[^>]*>/g, and an autolink's angle brackets look like a tag 10.
A contributor's pull request in October 2026, #136, described the regex — "The HTML-stripping regex /<[^>]*>/ removes everything between any < and the next >" — and noted that, even with the proposed change, "Autolinks (<https://example.com>, <[email protected]>) are still removed entirely, as before." 12 The pull request was closed without being merged on 12 November 2026 12.
The remark-gfm result is subtler. https\:// looks like a URL to a reader — paste it into a browser and it fails. No upstream report was searched for this one; it is recorded here as observed in these versions.
Rewriting every link in your notes as an autolink — to suit one converter — also trades the readable words for a raw address. The link form is right; the converter's setting is what needs to change.
The ten-second test for your converter
The test needs one line of Markdown and one grep. Write a note containing a single link, convert it with the exact command you use in production, and count the lines containing http. Zero means your converter drops URLs. One means it keeps them. Run it again after every upgrade.
printf 'See the [booking page](https://example.com/booking?id=42).\n' > /tmp/linktest.md
# Replace this line with your own converter, exactly as you run it
pandoc -f gfm -t plain /tmp/linktest.md > /tmp/linktest.txt
grep -c 'http' /tmp/linktest.txt
With pandoc 3.13's defaults, the output is See the booking page. and the count is 0. With --lua-filter link.lua added, the output keeps the URL and the count is 1 2.
Swap in remove-markdown, a Python script or any export step that writes a file — the grep does not care which. If the destination is a form field or a chat message, paste the output there as well, because the next system may have opinions of its own. Pasting Markdown into chat apps fails in the other direction, as italics that turn bold in Slack, Teams and Telegram shows.
The same loss happens when software, not a person, reads the notes. An AI index built from Markdown files can arrive at the same "booking page" with no address behind it, which is the subject of the companion post on loaders that strip the links out of your notes.
Trade-offs: what this measurement does not show
This is one machine, one note and one autolink line, run on 13 November 2026 with the pinned versions above. It shows what four converters did at their defaults and with their documented options. It does not show every option combination, other converters, or how later releases behave.
Dropping the URL is sometimes the correct result. The asker of "Convert rich MarkDown to plain text" wanted exactly that: the expected output reads "One of the earliest pictures of monorail cat found is from the website catmas.com’s blog section, dated from November 2, 2006." — link words, no address 13. For a search snippet, a preview card or a word count, that is the right default.
The claim here is narrower: know which one you are getting.
pandoc's --reference-links result is undocumented for plain output; it was observed in 3.13 and 3.14, and nothing promises it in the next release. The Lua filter relies on pandoc's documented filter API, but its output format, text <url>, is a choice, not a standard.
Two quotations rest on Stack Overflow display names. The answers signed John MacFarlane and Waylan match pandoc's author and Python-Markdown's maintainer by name and subject; neither profile links to the project 8 4.
No Ruby library was tested, although one of the four questions asks about Ruby. pandoc runs from any language as a command, so its row applies; a Ruby-native converter needs its own test.
The receipt does not rank the tools — each did what its documentation says. The maintainers of remove-markdown and strip-markdown already ship the options that keep links, and pandoc's filter system exists for exactly this kind of change.
Frequently asked questions
Python : How to convert markdown formatted text to text
Render the Markdown to HTML, then take the text — but move each link's URL into the text first. The accepted 2009 recipe drops the URL and deletes images, because both live in HTML attributes. Appending each href to its <a> tag before calling get_text() keeps the address, and replacing each <img> with its alt text keeps the description.
Pandoc Markdown to Plain Text Formatting
pandoc's plain writer follows Project Gutenberg conventions, so a [text](url) link prints as its words alone, while a bare <url> autolink prints the URL. To keep URLs, add a short Lua filter that rewrites each link as text <url>. In pandoc 3.13 and 3.14, --reference-links was also observed to list the URLs at the end, though that is undocumented for plain output.
Convert rich MarkDown to plain text
Decide first whether the URLs should survive. For a summary or preview, dropping them is right, and every default tested here does that. For an email or an export, they should stay. Converting to HTML and then to text is a reliable route, provided the step that takes the text also writes out each link's address.
Markdown to plain text in Ruby?
This test did not cover a Ruby library. The mechanism is the same in any language: a converter that writes only a link's visible text loses the URL. pandoc can be called from Ruby as a command, and its Lua filter works the same way there. Whatever you choose, convert a one-link note and grep the output for http.
Is there a markdown-to-plain-text method?
Several, and they keep different things. pandoc 3.13 kept tables and footnotes, remove-markdown 0.8.0 left table and task syntax in place, and strip-markdown 6.0.0 deleted tables and code blocks. All four tested dropped link URLs by default. remove-markdown's separateLinksAndTexts option and a pandoc Lua filter keep the URL in the text.
I need to convert markdown text to plain text format to display summary in my website.
For a summary, the default behaviour is usually what you want: link words read naturally and URLs would clutter the snippet. Check two other losses first. strip-markdown deletes code blocks and, with remark-gfm, tables, and the accepted Python recipe deletes images entirely. Convert one representative note and read the output before shipping it.
A converter in production will meet notes with constructs this test never contained, and converters change between releases — remove-markdown's autolink handling was the subject of a pull request, #136, closed in November 2026 without a merge. Re-run the one-line test after every upgrade. The round trip has its own version of this problem, covered in what a Markdown formatter rewrites in your notes.
Plain text has room for a URL. Whether it gets one is the converter's decision, until you make it yours.
If you keep notes as open Markdown files on your own device, mnmnote.com is a local-first editor built around that — and a Markdown link keeps its URL until something converts it away.
References
Footnotes
-
Stack Overflow, via the Stack Exchange API 2.3: Q761824 "Python : How to convert markdown formatted text to text" (72,570 views, asked 2009-04-17); Q34132549 "Pandoc Markdown to Plain Text Formatting" (14,304); Q34474813 "Convert rich MarkDown to plain text" (13,078); Q2547343 "Markdown to plain text in Ruby?" (5,733). https://api.stackexchange.com/2.3/questions/761824;34132549;34474813;2547343?site=stackoverflow (accessed 2026-11-13). ↩
-
Own measurement, 13 November 2026 — Node v20.20.2, Python 3.14.4, Linux x86_64. pandoc 3.13 (official static linux-amd64 release,
-f gfm -t plain); remove-markdown 0.8.0; remark 15.0.1 + strip-markdown 6.0.0, with and without remark-gfm 4.0.1; Python-Markdown 3.11.3 + Beautiful Soup 4.15.0 (the accepted Stack Overflow answer run as posted, and atables+footnotes+get_text()variant); html2text 2025.4.15. Exact-pinned local installs; two fixed inputs (a 19-line note and a one-line autolink file); every output counted forexample.com/booking. The Python link fix and the one-line self-test were run the same day with the same pinned tools. The pandoc rows (default,--reference-links, Lua filter, autolink) were re-run the same day on pandoc 3.14 (official static linux-amd64 release, published 2026-11-12) with byte-identical output; MANUAL.txt at tag 3.14 still documents--reference-linksfor Markdown and reStructuredText only. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15 ↩16 ↩17 ↩18 ↩19 ↩20 ↩21 -
Jason Coon. Accepted answer to "Python : How to convert markdown formatted text to text," 2009-04-17, edited 2021-07-22, score 60. https://stackoverflow.com/a/761847 (accessed 2026-11-13). ↩ ↩2
-
Waylan (Stack Overflow user 866026). Answer to "Convert rich MarkDown to plain text," 2015-12-28. https://stackoverflow.com/a/34486818 (accessed 2026-11-13). ↩ ↩2 ↩3
-
Richardson, L. Beautiful Soup Documentation, "get_text()" (covers version 4.15.0). https://www.crummy.com/software/BeautifulSoup/bs4/doc/ (accessed 2026-11-13). ↩ ↩2
-
jgm/pandoc.
src/Text/Pandoc/Writers/Markdown/Inline.hs, tag 3.13,Linkcase,PlainTextbranch. https://github.com/jgm/pandoc/blob/3.13/src/Text/Pandoc/Writers/Markdown/Inline.hs (accessed 2026-11-13). ↩ ↩2 -
MacFarlane, J. Pandoc User's Guide, MANUAL.txt at tag 3.13 —
--reference-linksand thegutenbergextension. https://raw.githubusercontent.com/jgm/pandoc/3.13/MANUAL.txt (accessed 2026-11-13). ↩ ↩2 -
John MacFarlane (Stack Overflow user 1261777). Answer to "Pandoc Markdown to Plain Text Formatting," 2015-12-07. https://stackoverflow.com/a/34139581 (accessed 2026-11-13). ↩ ↩2
-
remarkjs/strip-markdown. readme, top description, behaviour list and
keepoption (6.0.0). https://github.com/remarkjs/strip-markdown (accessed 2026-11-13). ↩ ↩2 ↩3 -
zuchka/remove-markdown. README, "Usage" and "Options" (0.8.0, published to npm 2026-10-04), and
index.jsline 63,htmlReplaceRegex. https://github.com/zuchka/remove-markdown (accessed 2026-11-13). ↩ ↩2 ↩3 -
Alir3z4/html2text. README, command-line options,
--ignore-links. https://github.com/Alir3z4/html2text (accessed 2026-11-13). ↩ -
OsamaAnsar. fix: only treat "<" as HTML when it can start an HTML construct. zuchka/remove-markdown pull request #136, opened 2026-10-15, closed unmerged 2026-11-12. https://github.com/zuchka/remove-markdown/pull/136 (accessed 2026-11-13). ↩ ↩2
-
Stack Overflow Q34474813, "Convert rich MarkDown to plain text," asked 2015-12-26, question body. https://stackoverflow.com/questions/34474813 (accessed 2026-11-13). ↩