[ci] format

This commit is contained in:
natemoo-re 2022-06-03 13:39:43 +00:00 committed by github-actions[bot]
parent 6c955ca643
commit ae14595407
2 changed files with 26 additions and 18 deletions

View file

@ -17,15 +17,11 @@ export default function remarkMdxish(this: any, options = {}) {
} }
function makeFromMarkdownLessStrict(extensions: fromMarkdown.Extension[]) { function makeFromMarkdownLessStrict(extensions: fromMarkdown.Extension[]) {
extensions.forEach(extension => { extensions.forEach((extension) => {
// Fix exit handlers that are too strict // Fix exit handlers that are too strict
['mdxJsxFlowTag', 'mdxJsxTextTag'].forEach(exitHandler => { ['mdxJsxFlowTag', 'mdxJsxTextTag'].forEach((exitHandler) => {
if (!extension.exit || !extension.exit[exitHandler]) if (!extension.exit || !extension.exit[exitHandler]) return;
return; extension.exit[exitHandler] = chainHandlers(fixSelfClosing, extension.exit[exitHandler]);
extension.exit[exitHandler] = chainHandlers(
fixSelfClosing,
extension.exit[exitHandler]
);
}); });
}); });
@ -33,18 +29,28 @@ function makeFromMarkdownLessStrict(extensions: fromMarkdown.Extension[]) {
} }
const selfClosingTags = new Set([ const selfClosingTags = new Set([
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'area',
'track', 'wbr' 'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'source',
'track',
'wbr',
]); ]);
function fixSelfClosing(this: fromMarkdown.CompileContext) { function fixSelfClosing(this: fromMarkdown.CompileContext) {
const tag = this.getData('mdxJsxTag') as Tag; const tag = this.getData('mdxJsxTag') as Tag;
if (tag.name && selfClosingTags.has(tag.name)) if (tag.name && selfClosingTags.has(tag.name)) tag.selfClosing = true;
tag.selfClosing = true;
} }
function chainHandlers(...handlers: fromMarkdown.Handle[]) { function chainHandlers(...handlers: fromMarkdown.Handle[]) {
return function handlerChain (this: fromMarkdown.CompileContext, token: fromMarkdown.Token) { return function handlerChain(this: fromMarkdown.CompileContext, token: fromMarkdown.Token) {
handlers.forEach(handler => handler.call(this, token)); handlers.forEach((handler) => handler.call(this, token));
}; };
} }

View file

@ -8,9 +8,11 @@ describe('strictness', () => {
{} {}
); );
chai.expect(code).to.equal( chai
`<p>Use self-closing void elements<br />like word<wbr />break and images: ` + .expect(code)
`<img src="hi.jpg" /></p>` .to.equal(
); `<p>Use self-closing void elements<br />like word<wbr />break and images: ` +
`<img src="hi.jpg" /></p>`
);
}); });
}); });