summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2022-04-02 14:15:41 -0600
committerGravatar GitHub <noreply@github.com> 2022-04-02 14:15:41 -0600
commit1335797903a57716e9a02b0ffd8ca636b3883c62 (patch)
treed8835124fec7ab80bfbf25c6d9c5a57039a1c56d /packages/markdown/remark/src
parentd63213f1198293e72bb9d9734bf4ec8309c515d4 (diff)
downloadastro-1335797903a57716e9a02b0ffd8ca636b3883c62.tar.gz
astro-1335797903a57716e9a02b0ffd8ca636b3883c62.tar.zst
astro-1335797903a57716e9a02b0ffd8ca636b3883c62.zip
update prettier width (#2968)
Diffstat (limited to 'packages/markdown/remark/src')
-rw-r--r--packages/markdown/remark/src/index.ts20
-rw-r--r--packages/markdown/remark/src/rehype-islands.ts12
-rw-r--r--packages/markdown/remark/src/remark-prism.ts4
-rw-r--r--packages/markdown/remark/src/remark-shiki.ts20
-rw-r--r--packages/markdown/remark/src/remark-unwrap.ts10
5 files changed, 54 insertions, 12 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index 0fb398bc7..c15cf502d 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -23,7 +23,10 @@ import matter from 'gray-matter';
export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
/** Internal utility for rendering a full markdown file and extracting Frontmatter data */
-export async function renderMarkdownWithFrontmatter(contents: string, opts?: MarkdownRenderingOptions | null) {
+export async function renderMarkdownWithFrontmatter(
+ contents: string,
+ opts?: MarkdownRenderingOptions | null
+) {
const { data: frontmatter, content } = matter(contents);
const value = await renderMarkdown(content, opts);
return { ...value, frontmatter };
@@ -73,7 +76,15 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
parser.use([remarkPrism(scopedClassName)]);
}
- parser.use([[markdownToHtml as any, { allowDangerousHtml: true, passThrough: ['raw', 'mdxTextExpression', 'mdxJsxTextElement', 'mdxJsxFlowElement'] }]]);
+ parser.use([
+ [
+ markdownToHtml as any,
+ {
+ allowDangerousHtml: true,
+ passThrough: ['raw', 'mdxTextExpression', 'mdxJsxTextElement', 'mdxJsxFlowElement'],
+ },
+ ],
+ ]);
loadedRehypePlugins.forEach(([plugin, opts]) => {
parser.use([[plugin, opts]]);
@@ -88,7 +99,10 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
let result: string;
try {
- const vfile = await parser.use([rehypeCollectHeaders]).use(rehypeStringify, { allowDangerousHtml: true }).process(content);
+ const vfile = await parser
+ .use([rehypeCollectHeaders])
+ .use(rehypeStringify, { allowDangerousHtml: true })
+ .process(content);
result = vfile.toString();
} catch (err) {
console.error(err);
diff --git a/packages/markdown/remark/src/rehype-islands.ts b/packages/markdown/remark/src/rehype-islands.ts
index 868f9096e..bbd584792 100644
--- a/packages/markdown/remark/src/rehype-islands.ts
+++ b/packages/markdown/remark/src/rehype-islands.ts
@@ -2,7 +2,11 @@ import { SKIP, visit as _visit } from 'unist-util-visit';
// This is a workaround.
// It fixes a compatibility issue between different, incompatible ASTs given by plugins to Unist
-const visit = _visit as (node: any, type: string, callback?: (node: any, index: number, parent: any) => any) => any;
+const visit = _visit as (
+ node: any,
+ type: string,
+ callback?: (node: any, index: number, parent: any) => any
+) => any;
// This fixes some confusing bugs coming from somewhere inside of our Markdown pipeline.
// `unist`/`remark`/`rehype` (not sure) often generate malformed HTML inside of <astro-root>
@@ -18,7 +22,11 @@ export default function rehypeIslands(): any {
// Sometimes comments can be trapped as text, which causes them to be escaped
// This casts them back to real HTML comments
if (parent && child.value.indexOf('<!--') > -1 && index != null) {
- parent.children.splice(index, 1, { ...child, type: 'comment', value: child.value.replace('<!--', '').replace('-->', '').trim() });
+ parent.children.splice(index, 1, {
+ ...child,
+ type: 'comment',
+ value: child.value.replace('<!--', '').replace('-->', '').trim(),
+ });
return [SKIP, index];
}
// For some reason `rehype` likes to inject extra linebreaks,
diff --git a/packages/markdown/remark/src/remark-prism.ts b/packages/markdown/remark/src/remark-prism.ts
index 6d3e4e664..544de1540 100644
--- a/packages/markdown/remark/src/remark-prism.ts
+++ b/packages/markdown/remark/src/remark-prism.ts
@@ -56,7 +56,9 @@ function transformer(className: MaybeString) {
if (className) {
classes.push(className);
}
- node.value = `<pre class="${classes.join(' ')}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
+ node.value = `<pre class="${classes.join(
+ ' '
+ )}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
return node;
};
return visit(tree, 'code', visitor);
diff --git a/packages/markdown/remark/src/remark-shiki.ts b/packages/markdown/remark/src/remark-shiki.ts
index f34fa26ef..314a0e38e 100644
--- a/packages/markdown/remark/src/remark-shiki.ts
+++ b/packages/markdown/remark/src/remark-shiki.ts
@@ -37,7 +37,10 @@ export interface ShikiConfig {
*/
const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
-const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig, scopedClassName?: string | null) => {
+const remarkShiki = async (
+ { langs = [], theme = 'github-dark', wrap = false }: ShikiConfig,
+ scopedClassName?: string | null
+) => {
const cacheID: string = typeof theme === 'string' ? theme : theme.name;
let highlighterAsync = highlighterCacheAsync.get(cacheID);
if (!highlighterAsync) {
@@ -63,15 +66,24 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
// &lt;span class=&quot;line&quot;
// Replace "shiki" class naming with "astro" and add "is:raw".
- html = html.replace('<pre class="shiki"', `<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`);
+ html = html.replace(
+ '<pre class="shiki"',
+ `<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`
+ );
// Replace "shiki" css variable naming with "astro".
- html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
+ html = html.replace(
+ /style="(background-)?color: var\(--shiki-/g,
+ 'style="$1color: var(--astro-code-'
+ );
// Handle code wrapping
// if wrap=null, do nothing.
if (wrap === false) {
html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
} else if (wrap === true) {
- html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"');
+ html = html.replace(
+ /style="(.*?)"/,
+ 'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
+ );
}
// Apply scopedClassName to all nested lines
diff --git a/packages/markdown/remark/src/remark-unwrap.ts b/packages/markdown/remark/src/remark-unwrap.ts
index 6da2a496a..3ce7a72c0 100644
--- a/packages/markdown/remark/src/remark-unwrap.ts
+++ b/packages/markdown/remark/src/remark-unwrap.ts
@@ -2,7 +2,11 @@ import { visit as _visit, SKIP } from 'unist-util-visit';
// This is a workaround.
// It fixes a compatibility issue between different, incompatible ASTs given by plugins to Unist
-const visit = _visit as (node: any, type: string, callback?: (node: any, index: number, parent: any) => any) => any;
+const visit = _visit as (
+ node: any,
+ type: string,
+ callback?: (node: any, index: number, parent: any) => any
+) => any;
// Remove the wrapping paragraph for <astro-root> islands
export default function remarkUnwrap() {
@@ -33,6 +37,8 @@ export default function remarkUnwrap() {
};
function containsAstroRootNode(node: any) {
- return node.children.map((child: any) => astroRootNodes.has(child)).reduce((all: boolean, v: boolean) => (all ? all : v), false);
+ return node.children
+ .map((child: any) => astroRootNodes.has(child))
+ .reduce((all: boolean, v: boolean) => (all ? all : v), false);
}
}