adam-p/markdown-here · error · Error
convertHTMLtoMarkdown: <tag> is not a supported tag
Error message
convertHTMLtoMarkdown: <tag> is not a supported tag
What it means
convertHTMLtoMarkdown(tag, html) converts inline HTML to Markdown but intentionally implements only one tag: 'a' (anchor links, handled at line 316 with its negative-lookbehind regex). Any tag value that is not exactly the string 'a' falls through to the else branch and throws. The function is narrow by design — Markdown Here's wider HTML-to-MD conversion happens through marked.js; this helper exists specifically to turn <a href> into [text](url) without corrupting Markdown links already present in the source (cf. issue #69 cited in the comment).
Source
Thrown at src/common/mdh-html-to-text.js:357
groups to create the desired MD link.
*/
html = html.replace(
/((?:\]\([^\)]*)|(?:\[[^\]]*)|(?:\[.*\]:.*))?<a\s[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/ig,
function($0, $1, $2, $3) {
return $1 ? $0 : '['+$3+']('+$2+')';
});
for (var i = 0; i < htmlToRestore.length; i++) {
html = html.replace(htmlToRestore[i][0], function() {
// The replacement argument to `String.replace()` has some magic values: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
// Because we don't control the content of that argument, we either
// need to escape dollar signs in it, or use the function version.
return htmlToRestore[i][1];
});
}
}
else {
throw new Error('convertHTMLtoMarkdown: ' + tag + ' is not a supported tag');
}
return html;
}
exports.MdhHtmlToText = MdhHtmlToText;
exports._testExports = {
convertHTMLtoMarkdown: convertHTMLtoMarkdown
};
var EXPORTED_SYMBOLS = ['MdhHtmlToText'];
if (typeof module !== 'undefined') {
module.exports = exports;
} else {
this.MdhHtmlToText = exports;View on GitHub (pinned to e00d005299)
Solutions
- Only call convertHTMLtoMarkdown('a', html) — it is the sole supported tag.
- If you received tag from a DOM node, normalize first: convertHTMLtoMarkdown(node.tagName.toLowerCase(), html) and ensure the node is actually an anchor.
- If you need to convert other tags to Markdown, route through marked.js (src/common/marked.js) instead of this helper.
- If you must extend it, add a new if/case branch above the else and implement the conversion; do not bypass the guard.
Example fix
// before
convertHTMLtoMarkdown(node.tagName, node.outerHTML); // throws for 'DIV','IMG', etc.
// after
if (node.tagName.toLowerCase() === 'a') {
convertHTMLtoMarkdown('a', node.outerHTML);
} else {
// route non-anchor HTML through marked.js instead
} Defensive patterns
Strategy: validation
Validate before calling
// Only 'a' is supported — check before calling.
function tryConvert(tag, html) {
const normalized = String(tag).toLowerCase();
if (normalized !== 'a') {
// not supported by this helper; use marked.js for other tags
return html;
}
return convertHTMLtoMarkdown('a', html);
} Type guard
// Runtime guard matching the function's true capability.
function isSupportedConversionTag(tag) {
return typeof tag === 'string' && tag.toLowerCase() === 'a';
} Prevention
- Treat convertHTMLtoMarkdown as anchor-only; never pass arbitrary tagNames.
- When sourcing tag from a DOM node, normalize with .tagName.toLowerCase() and gate on === 'a'.
- For non-anchor HTML, route through marked.js instead of extending this helper ad hoc.
When it happens
Trigger: Calling convertHTMLtoMarkdown('div', html), convertHTMLtoMarkdown('img', html), or any tag name other than the exact lowercase string 'a'. Also triggered by passing an uppercase 'A' (the check is tag === 'a' with no toLowerCase normalization) or by feeding a DOM element's tagName that has not been normalized to lowercase 'a'.
Common situations: A developer extends the rendering pipeline and assumes this helper handles arbitrary tags (it does not). Passing element.tagName directly from the DOM (often uppercase). Refactoring that renames or duplicates the call site with a different tag. Copy-pasting the function expecting generic HTML-to-MD behavior.
Related errors
AI-assisted analysis of adam-p/markdown-here@e00d005299 (2026-08-13).
Data as JSON: /api/errors/57adaf88f4f1b9a9.
Report an issue: GitHub.