- What does it convert?
- Headings, paragraphs, bold, italic, strikethrough, inline code, fenced code blocks with the language kept from a language- class, links, images, ordered and unordered lists including nested ones, blockquotes, horizontal rules and tables. Scripts, styles and template tags are dropped, since none of them are content.
- How does it parse the HTML?
- With DOMParser, the browser's own HTML parser. That matters for messy markup: unclosed tags, implied elements and entities are resolved exactly the way the browser resolves them on a live page, which a regex based converter cannot do. It also means the conversion needs no library and no server.
- Is pasting HTML from a page safe?
- Yes. Parsing with DOMParser produces an inert document: scripts in the markup never execute, and images, iframes and stylesheets are never fetched. The parsed document is read for its structure and then discarded. It is also never attached to the page you are looking at.
- Why are some characters escaped with a backslash?
- Because asterisks, backticks and square brackets in your text would otherwise be read as markdown syntax. They are escaped so the text survives a round trip. Underscores are deliberately left alone: they do not create emphasis inside a word, and escaping them wrecks ordinary file names and identifiers.
- What about a table with no header row?
- The first row becomes the header. Markdown has no headerless table syntax, so there is no alternative that stays valid. If your first row is data, you will want to add a header line yourself.
- Why convert HTML to markdown at all?
- Usually to move content between systems, or to feed a page to a language model. Markdown carries the structure that matters, headings, lists and links, in a fraction of the tokens HTML costs, and without the navigation and styling noise.