UNPKG

micro-mdx-parser

Version:

A tiny parser to convert markdown or html into JSON

229 lines (223 loc) 3.31 kB
/* Tags which contain arbitrary non-parsed content For example: <script> JavaScript should not be parsed */ const childlessTags = ['style', 'script', 'template'] /* Tags which auto-close because they cannot be nested For example: <p>Outer<p>Inner is <p>Outer</p><p>Inner</p> */ const closingTags = [ 'html', 'head', 'body', 'p', 'dt', 'dd', 'li', 'option', 'thead', 'th', 'tbody', 'tr', 'td', 'tfoot', 'colgroup' ] /* Closing tags which have ancestor tags which may exist within them which prevent the closing tag from auto-closing. For example: in <li><ul><li></ul></li>, the top-level <li> should not auto-close. */ const closingTagAncestorBreakers = { li: ['ul', 'ol', 'menu'], dt: ['dl'], dd: ['dl'], tbody: ['table'], thead: ['table'], tfoot: ['table'], tr: ['table'], td: ['table'] } /* Tags which do not need the closing tag For example: <img> does not need </img> */ const voidTags = [ '!doctype', 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr' ] // https://github.com/sindresorhus/html-tags/blob/main/html-tags.json const htmlTags = [ "a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "link", "main", "map", "mark", "math", "menu", "menuitem", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "slot", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "var", "video", "wbr" ] // via https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements // const inlineTags= [ // 'a', // 'abbr', // 'acronym', // 'b', // 'bdi', // 'bdo', // 'big', // 'br', // 'button', // 'canvas', // 'cite', // 'code', // 'data', // 'datalist', // 'del', // 'dfn', // 'em', // 'embed', // 'i', // 'iframe', // 'img', // 'input', // 'ins', // 'kbd', // 'label', // 'map', // 'mark', // 'meter', // 'noscript', // 'object', // 'output', // 'picture', // 'progress', // 'q', // 'ruby', // 's', // 'samp', // 'script', // 'select', // 'slot', // 'small', // 'span', // 'strong', // 'sub', // 'sup', // 'svg', // 'template', // 'textarea', // 'time', // 'u', // 'tt', // 'var', // 'wbr', // ] module.exports = { childlessTags, closingTags, closingTagAncestorBreakers, voidTags, htmlTags, // inlineTags, }