{"record":{"id":"57adaf88f4f1b9a9","repo":"adam-p/markdown-here","slug":"converthtmltomarkdown-tag-is-not-a-supported-ta","errorCode":null,"errorMessage":"convertHTMLtoMarkdown: <tag> is not a supported tag","messagePattern":"convertHTMLtoMarkdown: <tag> is not a supported tag","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/common/mdh-html-to-text.js","lineNumber":357,"sourceCode":"    groups to create the desired MD link.\n    */\n    html = html.replace(\n      /((?:\\]\\([^\\)]*)|(?:\\[[^\\]]*)|(?:\\[.*\\]:.*))?<a\\s[^>]*href=\"([^\"]*)\"[^>]*>(.*?)<\\/a>/ig,\n      function($0, $1, $2, $3) {\n        return $1 ? $0 : '['+$3+']('+$2+')';\n      });\n\n    for (var i = 0; i < htmlToRestore.length; i++) {\n      html = html.replace(htmlToRestore[i][0], function() {\n          // 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\n          // Because we don't control the content of that argument, we either\n          // need to escape dollar signs in it, or use the function version.\n          return htmlToRestore[i][1];\n        });\n    }\n  }\n  else {\n    throw new Error('convertHTMLtoMarkdown: ' + tag + ' is not a supported tag');\n  }\n\n  return html;\n}\n\n\nexports.MdhHtmlToText = MdhHtmlToText;\n\nexports._testExports = {\n  convertHTMLtoMarkdown: convertHTMLtoMarkdown\n};\n\nvar EXPORTED_SYMBOLS = ['MdhHtmlToText'];\n\nif (typeof module !== 'undefined') {\n  module.exports = exports;\n} else {\n  this.MdhHtmlToText = exports;","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/adam-p/markdown-here/blob/e00d005299922198aef968e0cd42b275525c20a6/src/common/mdh-html-to-text.js#L339-L375","documentation":"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).","triggerScenarios":"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'.","commonSituations":"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.","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."],"exampleFix":"// before\nconvertHTMLtoMarkdown(node.tagName, node.outerHTML); // throws for 'DIV','IMG', etc.\n\n// after\nif (node.tagName.toLowerCase() === 'a') {\n  convertHTMLtoMarkdown('a', node.outerHTML);\n} else {\n  // route non-anchor HTML through marked.js instead\n}","handlingStrategy":"validation","validationCode":"// Only 'a' is supported — check before calling.\nfunction tryConvert(tag, html) {\n  const normalized = String(tag).toLowerCase();\n  if (normalized !== 'a') {\n    // not supported by this helper; use marked.js for other tags\n    return html;\n  }\n  return convertHTMLtoMarkdown('a', html);\n}","typeGuard":"// Runtime guard matching the function's true capability.\nfunction isSupportedConversionTag(tag) {\n  return typeof tag === 'string' && tag.toLowerCase() === 'a';\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["markdown","html","validation","markdown-here","api-contract"],"backgroundTag":null,"analyzedSha":"e00d005299922198aef968e0cd42b275525c20a6","analyzedAt":"2026-08-13T00:39:36.904Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}