Skip to content

Instantly share code, notes, and snippets.

@sscotth
Created March 21, 2019 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sscotth/b79f32fa56eef4ff33434c2fe4b15625 to your computer and use it in GitHub Desktop.
Save sscotth/b79f32fa56eef4ff33434c2fe4b15625 to your computer and use it in GitHub Desktop.
mdx Elements
const assert = require('assert')
const mdx = require('@mdx-js/mdx')
const text = 'foo'
const expected = el =>
`\n\nconst layoutProps = {\n \n};\nexport default class MDXContent extends React.Component {\n constructor(props) {\n super(props)\n this.layout = null\n }\n render() {\n const { components, ...props } = this.props\n\n return <MDXTag\n name="wrapper"\n \n components={components}><${el}>${text}</${el}>\n </MDXTag>\n }\n}\nMDXContent.isMDXComponent = true`
const elements = [
// Unknown HTML Elements
'foo',
'bar',
'baz',
// Known HTML Elements
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element
// Main root
'html',
// Document metadata
'base',
'head',
'link',
'meta',
'style',
'title',
// Sectioning root
'body',
// Content sectioning
'address',
'article',
'aside',
'footer',
'header',
// 'h1', // FAIL
// 'h2', // FAIL
// 'h3', // FAIL
// 'h4', // FAIL
// 'h5', // FAIL
// 'h6', // FAIL
'hgroup',
'main',
'nav',
'section',
// Text content
'blockquote',
'dd',
'dir',
'div',
'dl',
'dt',
'figcaption',
'figure',
'hr',
'li',
'main',
'ol',
// 'p', // FAIL
'pre',
'ul',
// Inline text semantics
// 'a', // FAIL
'abbr',
// 'b', // FAIL
'bdi',
'bdo',
'br',
'cite',
'code',
'data',
'dfn',
'em',
// 'i', FAIL
'kbd',
'mark',
// 'q', FAIL
'rb',
'rp',
'rt',
'rtc',
'ruby',
// 's', FAIL
'samp',
'small',
'span',
'strong',
'sub',
'sup',
'time',
'tt',
// 'u', FAIL
'var',
'wbr',
// Image and multimedia
'area',
'audio',
'img',
'map',
'track',
'video',
// Embedded content
'applet',
'embed',
'iframe',
'noembed',
'object',
'param',
'picture',
'source',
// Scripting
'canvas',
'noscript',
'script',
// Demarcating edits
'del',
'ins',
// Table content
'caption',
'col',
'colgroup',
'table',
'tbody',
'td',
'tfoot',
'th',
'thead',
'tr',
// Forms
'button',
'datalist',
'fieldset',
'form',
'input',
'label',
'legend',
'meter',
'optgroup',
'option',
'output',
'progress',
'select',
'textarea',
// Interactive elements
'details',
'dialog',
'menu',
'menuitem',
'summary',
// Web Components
'content',
'element',
'shadow',
'slot',
'template',
// Obsolete and deprecated elements
'acronym',
'applet',
'basefont',
'bgsound',
'big',
'blink',
'center',
'command',
'content',
'dir',
'element',
'font',
'frame',
'frameset',
'image',
'isindex',
'keygen',
'listing',
'marquee',
'menuitem',
'multicol',
'nextid',
'nobr',
'noembed',
'noframes',
'plaintext',
'shadow',
'spacer',
'strike',
'tt',
'xmp',
]
elements.forEach(el =>
mdx(`<${el}>${text}</${el}>`).then(code =>
assert.strictEqual(code, expected(el)),
),
)
const knownFailures = [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'p',
'a',
'b',
'i',
'q',
's',
'u',
]
knownFailureExpectation = el =>
`\n\nconst layoutProps = {\n \n};\nexport default class MDXContent extends React.Component {\n constructor(props) {\n super(props)\n this.layout = null\n }\n render() {\n const { components, ...props } = this.props\n\n return <MDXTag\n name="wrapper"\n \n components={components}><MDXTag name="p" components={components}><${el}>{\`${text}\`}</${el}></MDXTag>\n </MDXTag>\n }\n}\nMDXContent.isMDXComponent = true`
knownFailures.forEach(el =>
mdx(`<${el}>${text}</${el}>`).then(code =>
assert.strictEqual(code, knownFailureExpectation(el)),
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment