@astrojs/markdown-remark 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- @astrojs/markdown-remark:build: cache hit, replaying output 6e22a141f5baff6f
2
- @astrojs/markdown-remark:build: 
3
- @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.8.0 build /Users/fks/Code/astro/packages/markdown/remark
4
- @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
- @astrojs/markdown-remark:build: 
1
+ @astrojs/markdown-remark:build: cache hit, replaying output 5817ab166c77bc86
2
+ @astrojs/markdown-remark:build: 
3
+ @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.8.1 build /Users/fks/Code/astro/packages/markdown/remark
4
+ @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
+ @astrojs/markdown-remark:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2971](https://github.com/withastro/astro/pull/2971) [`ad3c3916`](https://github.com/withastro/astro/commit/ad3c391696c5b9cc350a22831717682e73e25776) Thanks [@JuanM04](https://github.com/JuanM04)! - Escape expressions when mode == 'md'
8
+
3
9
  ## 0.8.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.js CHANGED
@@ -52,7 +52,7 @@ async function renderMarkdown(content, opts) {
52
52
  const isMDX = mode === "mdx";
53
53
  const { headers, rehypeCollectHeaders } = createCollectHeaders();
54
54
  await Promise.all([loadRemarkExpressions(), loadRemarkJsx()]);
55
- let parser = unified().use(markdown).use(isMDX ? [remarkJsx] : []).use(isMDX ? [remarkExpressions] : []).use([remarkUnwrap]);
55
+ let parser = unified().use(markdown).use(isMDX ? [remarkJsx, remarkExpressions] : []).use([remarkUnwrap]);
56
56
  if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
57
57
  remarkPlugins = [...DEFAULT_REMARK_PLUGINS];
58
58
  rehypePlugins = [...DEFAULT_REHYPE_PLUGINS];
@@ -70,11 +70,19 @@ async function renderMarkdown(content, opts) {
70
70
  } else if (syntaxHighlight === "prism") {
71
71
  parser.use([remarkPrism(scopedClassName)]);
72
72
  }
73
- parser.use([[markdownToHtml, { allowDangerousHtml: true, passThrough: ["raw", "mdxTextExpression", "mdxJsxTextElement", "mdxJsxFlowElement"] }]]);
73
+ parser.use([
74
+ [
75
+ markdownToHtml,
76
+ {
77
+ allowDangerousHtml: true,
78
+ passThrough: ["raw", "mdxTextExpression", "mdxJsxTextElement", "mdxJsxFlowElement"]
79
+ }
80
+ ]
81
+ ]);
74
82
  loadedRehypePlugins.forEach(([plugin, opts2]) => {
75
83
  parser.use([[plugin, opts2]]);
76
84
  });
77
- parser.use(isMDX ? [rehypeJsx] : []).use(isMDX ? [rehypeExpressions] : []).use(isMDX ? [] : [rehypeRaw]).use(isMDX ? [rehypeEscape] : []).use(rehypeIslands);
85
+ parser.use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw]).use(rehypeEscape).use(rehypeIslands);
78
86
  let result;
79
87
  try {
80
88
  const vfile = await parser.use([rehypeCollectHeaders]).use(rehypeStringify, { allowDangerousHtml: true }).process(content);
@@ -26,7 +26,10 @@ function rehypeIslands() {
26
26
  visit(el, "text", (child, index, parent) => {
27
27
  if (child.type === "text") {
28
28
  if (parent && child.value.indexOf("<!--") > -1 && index != null) {
29
- parent.children.splice(index, 1, __spreadProps(__spreadValues({}, child), { type: "comment", value: child.value.replace("<!--", "").replace("-->", "").trim() }));
29
+ parent.children.splice(index, 1, __spreadProps(__spreadValues({}, child), {
30
+ type: "comment",
31
+ value: child.value.replace("<!--", "").replace("-->", "").trim()
32
+ }));
30
33
  return [SKIP, index];
31
34
  }
32
35
  child.value = child.value.replace(/\n+/g, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -23,7 +23,10 @@ import matter from 'gray-matter';
23
23
  export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
24
24
 
25
25
  /** Internal utility for rendering a full markdown file and extracting Frontmatter data */
26
- export async function renderMarkdownWithFrontmatter(contents: string, opts?: MarkdownRenderingOptions | null) {
26
+ export async function renderMarkdownWithFrontmatter(
27
+ contents: string,
28
+ opts?: MarkdownRenderingOptions | null
29
+ ) {
27
30
  const { data: frontmatter, content } = matter(contents);
28
31
  const value = await renderMarkdown(content, opts);
29
32
  return { ...value, frontmatter };
@@ -47,8 +50,7 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
47
50
 
48
51
  let parser = unified()
49
52
  .use(markdown)
50
- .use(isMDX ? [remarkJsx] : [])
51
- .use(isMDX ? [remarkExpressions] : [])
53
+ .use(isMDX ? [remarkJsx, remarkExpressions] : [])
52
54
  .use([remarkUnwrap]);
53
55
 
54
56
  if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
@@ -73,22 +75,31 @@ export async function renderMarkdown(content: string, opts?: MarkdownRenderingOp
73
75
  parser.use([remarkPrism(scopedClassName)]);
74
76
  }
75
77
 
76
- parser.use([[markdownToHtml as any, { allowDangerousHtml: true, passThrough: ['raw', 'mdxTextExpression', 'mdxJsxTextElement', 'mdxJsxFlowElement'] }]]);
78
+ parser.use([
79
+ [
80
+ markdownToHtml as any,
81
+ {
82
+ allowDangerousHtml: true,
83
+ passThrough: ['raw', 'mdxTextExpression', 'mdxJsxTextElement', 'mdxJsxFlowElement'],
84
+ },
85
+ ],
86
+ ]);
77
87
 
78
88
  loadedRehypePlugins.forEach(([plugin, opts]) => {
79
89
  parser.use([[plugin, opts]]);
80
90
  });
81
91
 
82
92
  parser
83
- .use(isMDX ? [rehypeJsx] : [])
84
- .use(isMDX ? [rehypeExpressions] : [])
85
- .use(isMDX ? [] : [rehypeRaw])
86
- .use(isMDX ? [rehypeEscape] : [])
93
+ .use(isMDX ? [rehypeJsx, rehypeExpressions] : [rehypeRaw])
94
+ .use(rehypeEscape)
87
95
  .use(rehypeIslands);
88
96
 
89
97
  let result: string;
90
98
  try {
91
- const vfile = await parser.use([rehypeCollectHeaders]).use(rehypeStringify, { allowDangerousHtml: true }).process(content);
99
+ const vfile = await parser
100
+ .use([rehypeCollectHeaders])
101
+ .use(rehypeStringify, { allowDangerousHtml: true })
102
+ .process(content);
92
103
  result = vfile.toString();
93
104
  } catch (err) {
94
105
  console.error(err);
@@ -2,7 +2,11 @@ import { SKIP, visit as _visit } from 'unist-util-visit';
2
2
 
3
3
  // This is a workaround.
4
4
  // It fixes a compatibility issue between different, incompatible ASTs given by plugins to Unist
5
- const visit = _visit as (node: any, type: string, callback?: (node: any, index: number, parent: any) => any) => any;
5
+ const visit = _visit as (
6
+ node: any,
7
+ type: string,
8
+ callback?: (node: any, index: number, parent: any) => any
9
+ ) => any;
6
10
 
7
11
  // This fixes some confusing bugs coming from somewhere inside of our Markdown pipeline.
8
12
  // `unist`/`remark`/`rehype` (not sure) often generate malformed HTML inside of <astro-root>
@@ -18,7 +22,11 @@ export default function rehypeIslands(): any {
18
22
  // Sometimes comments can be trapped as text, which causes them to be escaped
19
23
  // This casts them back to real HTML comments
20
24
  if (parent && child.value.indexOf('<!--') > -1 && index != null) {
21
- parent.children.splice(index, 1, { ...child, type: 'comment', value: child.value.replace('<!--', '').replace('-->', '').trim() });
25
+ parent.children.splice(index, 1, {
26
+ ...child,
27
+ type: 'comment',
28
+ value: child.value.replace('<!--', '').replace('-->', '').trim(),
29
+ });
22
30
  return [SKIP, index];
23
31
  }
24
32
  // For some reason `rehype` likes to inject extra linebreaks,
@@ -56,7 +56,9 @@ function transformer(className: MaybeString) {
56
56
  if (className) {
57
57
  classes.push(className);
58
58
  }
59
- node.value = `<pre class="${classes.join(' ')}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
59
+ node.value = `<pre class="${classes.join(
60
+ ' '
61
+ )}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
60
62
  return node;
61
63
  };
62
64
  return visit(tree, 'code', visitor);
@@ -37,7 +37,10 @@ export interface ShikiConfig {
37
37
  */
38
38
  const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();
39
39
 
40
- const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig, scopedClassName?: string | null) => {
40
+ const remarkShiki = async (
41
+ { langs = [], theme = 'github-dark', wrap = false }: ShikiConfig,
42
+ scopedClassName?: string | null
43
+ ) => {
41
44
  const cacheID: string = typeof theme === 'string' ? theme : theme.name;
42
45
  let highlighterAsync = highlighterCacheAsync.get(cacheID);
43
46
  if (!highlighterAsync) {
@@ -63,15 +66,24 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
63
66
  // &lt;span class=&quot;line&quot;
64
67
 
65
68
  // Replace "shiki" class naming with "astro" and add "is:raw".
66
- html = html.replace('<pre class="shiki"', `<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`);
69
+ html = html.replace(
70
+ '<pre class="shiki"',
71
+ `<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`
72
+ );
67
73
  // Replace "shiki" css variable naming with "astro".
68
- html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
74
+ html = html.replace(
75
+ /style="(background-)?color: var\(--shiki-/g,
76
+ 'style="$1color: var(--astro-code-'
77
+ );
69
78
  // Handle code wrapping
70
79
  // if wrap=null, do nothing.
71
80
  if (wrap === false) {
72
81
  html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
73
82
  } else if (wrap === true) {
74
- html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"');
83
+ html = html.replace(
84
+ /style="(.*?)"/,
85
+ 'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
86
+ );
75
87
  }
76
88
 
77
89
  // Apply scopedClassName to all nested lines
@@ -2,7 +2,11 @@ import { visit as _visit, SKIP } from 'unist-util-visit';
2
2
 
3
3
  // This is a workaround.
4
4
  // It fixes a compatibility issue between different, incompatible ASTs given by plugins to Unist
5
- const visit = _visit as (node: any, type: string, callback?: (node: any, index: number, parent: any) => any) => any;
5
+ const visit = _visit as (
6
+ node: any,
7
+ type: string,
8
+ callback?: (node: any, index: number, parent: any) => any
9
+ ) => any;
6
10
 
7
11
  // Remove the wrapping paragraph for <astro-root> islands
8
12
  export default function remarkUnwrap() {
@@ -33,6 +37,8 @@ export default function remarkUnwrap() {
33
37
  };
34
38
 
35
39
  function containsAstroRootNode(node: any) {
36
- return node.children.map((child: any) => astroRootNodes.has(child)).reduce((all: boolean, v: boolean) => (all ? all : v), false);
40
+ return node.children
41
+ .map((child: any) => astroRootNodes.has(child))
42
+ .reduce((all: boolean, v: boolean) => (all ? all : v), false);
37
43
  }
38
44
  }