[ci] format

This commit is contained in:
tony-sull 2022-07-22 22:47:21 +00:00 committed by fredkbot
parent 00fab4ce13
commit 41f4a8f9cb
7 changed files with 33 additions and 31 deletions

View file

@ -703,7 +703,7 @@ export interface AstroUserConfig {
* @see https://docs.astro.build/en/guides/integrations-guide/mdx/ * @see https://docs.astro.build/en/guides/integrations-guide/mdx/
* Default: false * Default: false
*/ */
astroFlavoredMarkdown?: boolean; astroFlavoredMarkdown?: boolean;
}; };
} }

View file

@ -52,7 +52,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
vite: {}, vite: {},
legacy: { legacy: {
astroFlavoredMarkdown: false, astroFlavoredMarkdown: false,
} },
}; };
async function resolvePostcssConfig(inlineOptions: any, root: URL): Promise<PostCSSConfigResult> { async function resolvePostcssConfig(inlineOptions: any, root: URL): Promise<PostCSSConfigResult> {
@ -214,7 +214,10 @@ export const AstroConfigSchema = z.object({
.default(ASTRO_CONFIG_DEFAULTS.vite), .default(ASTRO_CONFIG_DEFAULTS.vite),
legacy: z legacy: z
.object({ .object({
astroFlavoredMarkdown: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.legacy.astroFlavoredMarkdown), astroFlavoredMarkdown: z
.boolean()
.optional()
.default(ASTRO_CONFIG_DEFAULTS.legacy.astroFlavoredMarkdown),
}) })
.optional() .optional()
.default({}), .default({}),

View file

@ -175,7 +175,7 @@ export async function render(
logging, logging,
markdown: { markdown: {
...astroConfig.markdown, ...astroConfig.markdown,
isAstroFlavoredMd: astroConfig.legacy.astroFlavoredMarkdown isAstroFlavoredMd: astroConfig.legacy.astroFlavoredMarkdown,
}, },
mod, mod,
mode, mode,

View file

@ -59,7 +59,7 @@ export async function renderJSX(result: SSRResult, vnode: any): Promise<any> {
if (vnode.type) { if (vnode.type) {
if (typeof vnode.type === 'function' && (vnode.type as any)['astro:renderer']) { if (typeof vnode.type === 'function' && (vnode.type as any)['astro:renderer']) {
skipAstroJSXCheck.add(vnode.type) skipAstroJSXCheck.add(vnode.type);
} }
if (typeof vnode.type === 'function' && vnode.props['server:root']) { if (typeof vnode.type === 'function' && vnode.props['server:root']) {
const output = await vnode.type(vnode.props ?? {}); const output = await vnode.type(vnode.props ?? {});
@ -91,7 +91,7 @@ export async function renderJSX(result: SSRResult, vnode: any): Promise<any> {
} }
if (!isVNode(child)) { if (!isVNode(child)) {
_slots.default.push(child); _slots.default.push(child);
return return;
} }
if ('slot' in child.props) { if ('slot' in child.props) {
_slots[child.props.slot] = [...(_slots[child.props.slot] ?? []), child]; _slots[child.props.slot] = [...(_slots[child.props.slot] ?? []), child];
@ -110,10 +110,12 @@ export async function renderJSX(result: SSRResult, vnode: any): Promise<any> {
const slotPromises = []; const slotPromises = [];
const slots: Record<string, any> = {}; const slots: Record<string, any> = {};
for (const [key, value] of Object.entries(_slots)) { for (const [key, value] of Object.entries(_slots)) {
slotPromises.push(renderJSX(result, value).then(output => { slotPromises.push(
if (output.toString().trim().length === 0) return; renderJSX(result, value).then((output) => {
slots[key] = () => output; if (output.toString().trim().length === 0) return;
})) slots[key] = () => output;
})
);
} }
await Promise.all(slotPromises); await Promise.all(slotPromises);

View file

@ -29,7 +29,7 @@ export const DEFAULT_REHYPE_PLUGINS = [];
/** Shared utility for rendering markdown */ /** Shared utility for rendering markdown */
export async function renderMarkdown( export async function renderMarkdown(
content: string, content: string,
opts: MarkdownRenderingOptions, opts: MarkdownRenderingOptions
): Promise<MarkdownRenderingResult> { ): Promise<MarkdownRenderingResult> {
let { let {
fileURL, fileURL,

View file

@ -5,26 +5,26 @@ describe('autolinking', () => {
describe('plain md', () => { describe('plain md', () => {
it('autolinks URLs starting with a protocol in plain text', async () => { it('autolinks URLs starting with a protocol in plain text', async () => {
const { code } = await renderMarkdown(`See https://example.com for more.`, {}); const { code } = await renderMarkdown(`See https://example.com for more.`, {});
chai chai
.expect(code.replace(/\n/g, '')) .expect(code.replace(/\n/g, ''))
.to.equal(`<p>See <a href="https://example.com">https://example.com</a> for more.</p>`); .to.equal(`<p>See <a href="https://example.com">https://example.com</a> for more.</p>`);
}); });
it('autolinks URLs starting with "www." in plain text', async () => { it('autolinks URLs starting with "www." in plain text', async () => {
const { code } = await renderMarkdown(`See www.example.com for more.`, {}); const { code } = await renderMarkdown(`See www.example.com for more.`, {});
chai chai
.expect(code.trim()) .expect(code.trim())
.to.equal(`<p>See <a href="http://www.example.com">www.example.com</a> for more.</p>`); .to.equal(`<p>See <a href="http://www.example.com">www.example.com</a> for more.</p>`);
}); });
it('does not autolink URLs in code blocks', async () => { it('does not autolink URLs in code blocks', async () => {
const { code } = await renderMarkdown( const { code } = await renderMarkdown(
'See `https://example.com` or `www.example.com` for more.', 'See `https://example.com` or `www.example.com` for more.',
{} {}
); );
chai chai
.expect(code.trim()) .expect(code.trim())
.to.equal( .to.equal(
@ -35,14 +35,14 @@ describe('autolinking', () => {
}); });
describe('astro-flavored md', () => { describe('astro-flavored md', () => {
const renderAstroMd = text => renderMarkdown(text, { isAstroFlavoredMd: true }); const renderAstroMd = (text) => renderMarkdown(text, { isAstroFlavoredMd: true });
it('does not autolink URLs in code blocks', async () => { it('does not autolink URLs in code blocks', async () => {
const { code } = await renderAstroMd( const { code } = await renderAstroMd(
'See `https://example.com` or `www.example.com` for more.', 'See `https://example.com` or `www.example.com` for more.',
{} {}
); );
chai chai
.expect(code.trim()) .expect(code.trim())
.to.equal( .to.equal(
@ -50,24 +50,24 @@ describe('autolinking', () => {
`<code is:raw>www.example.com</code> for more.</p>` `<code is:raw>www.example.com</code> for more.</p>`
); );
}); });
it('does not autolink URLs in fenced code blocks', async () => { it('does not autolink URLs in fenced code blocks', async () => {
const { code } = await renderAstroMd( const { code } = await renderAstroMd(
'Example:\n```\nGo to https://example.com or www.example.com now.\n```' 'Example:\n```\nGo to https://example.com or www.example.com now.\n```'
); );
chai chai
.expect(code) .expect(code)
.to.contain(`<pre is:raw`) .to.contain(`<pre is:raw`)
.to.contain(`Go to https://example.com or www.example.com now.`); .to.contain(`Go to https://example.com or www.example.com now.`);
}); });
it('does not autolink URLs starting with a protocol when nested inside links', async () => { it('does not autolink URLs starting with a protocol when nested inside links', async () => {
const { code } = await renderAstroMd( const { code } = await renderAstroMd(
`See [http://example.com](http://example.com) or ` + `See [http://example.com](http://example.com) or ` +
`<a test href="https://example.com">https://example.com</a>` `<a test href="https://example.com">https://example.com</a>`
); );
chai chai
.expect(code.replace(/\n/g, '')) .expect(code.replace(/\n/g, ''))
.to.equal( .to.equal(
@ -75,13 +75,13 @@ describe('autolinking', () => {
`<a test href="https://example.com">https://example.com</a></p>` `<a test href="https://example.com">https://example.com</a></p>`
); );
}); });
it('does not autolink URLs starting with "www." when nested inside links', async () => { it('does not autolink URLs starting with "www." when nested inside links', async () => {
const { code } = await renderAstroMd( const { code } = await renderAstroMd(
`See [www.example.com](https://www.example.com) or ` + `See [www.example.com](https://www.example.com) or ` +
`<a test href="https://www.example.com">www.example.com</a>` `<a test href="https://www.example.com">www.example.com</a>`
); );
chai chai
.expect(code.replace(/\n/g, '')) .expect(code.replace(/\n/g, ''))
.to.equal( .to.equal(
@ -89,13 +89,13 @@ describe('autolinking', () => {
`<a test href="https://www.example.com">www.example.com</a></p>` `<a test href="https://www.example.com">www.example.com</a></p>`
); );
}); });
it('does not autolink URLs when nested several layers deep inside links', async () => { it('does not autolink URLs when nested several layers deep inside links', async () => {
const { code } = await renderAstroMd( const { code } = await renderAstroMd(
`<a href="https://www.example.com">**Visit _our www.example.com or ` + `<a href="https://www.example.com">**Visit _our www.example.com or ` +
`http://localhost pages_ for more!**</a>` `http://localhost pages_ for more!**</a>`
); );
chai chai
.expect(code.replace(/\n/g, '')) .expect(code.replace(/\n/g, ''))
.to.equal( .to.equal(
@ -104,5 +104,5 @@ describe('autolinking', () => {
`</strong></a>` `</strong></a>`
); );
}); });
}) });
}); });

View file

@ -67,10 +67,7 @@ describe('strictness in Astro-flavored markdown', () => {
}); });
it('should allow attribute names starting with "@" after attribute names', async () => { it('should allow attribute names starting with "@" after attribute names', async () => {
const { code } = await renderAstroMd( const { code } = await renderAstroMd(`<button disabled @click="handleClick">Test</button>`, {});
`<button disabled @click="handleClick">Test</button>`,
{}
);
chai.expect(code.trim()).to.equal(`<button disabled @click="handleClick">Test</button>`); chai.expect(code.trim()).to.equal(`<button disabled @click="handleClick">Test</button>`);
}); });