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

View file

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