@astrojs/markdown-remark 0.7.0-next.1 → 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.
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +29 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -3
- package/dist/load-plugins.d.ts +0 -0
- package/dist/rehype-collect-headers.d.ts +0 -0
- package/dist/rehype-escape.d.ts +0 -0
- package/dist/rehype-expressions.d.ts +0 -0
- package/dist/rehype-islands.d.ts +0 -0
- package/dist/rehype-islands.js +4 -1
- package/dist/rehype-jsx.d.ts +0 -0
- package/dist/remark-expressions.d.ts +0 -0
- package/dist/remark-jsx.d.ts +0 -0
- package/dist/remark-prism.d.ts +0 -0
- package/dist/remark-prism.js +1 -1
- package/dist/remark-scoped-styles.d.ts +0 -0
- package/dist/remark-shiki.d.ts +0 -0
- package/dist/remark-slug.d.ts +0 -0
- package/dist/remark-unwrap.d.ts +0 -0
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.ts +22 -11
- package/src/rehype-islands.ts +10 -2
- package/src/remark-prism.ts +4 -2
- package/src/remark-shiki.ts +16 -4
- package/src/remark-unwrap.ts +8 -2
- package/src/types.ts +1 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
[33m@astrojs/markdown-remark:build: [0mcache hit, replaying output [2m5817ab166c77bc86[0m
|
|
2
|
+
[33m@astrojs/markdown-remark:build: [0m
|
|
3
|
+
[33m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@0.8.1 build /Users/fks/Code/astro/packages/markdown/remark
|
|
4
|
+
[33m@astrojs/markdown-remark:build: [0m> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
|
|
5
|
+
[33m@astrojs/markdown-remark:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`e425f896`](https://github.com/withastro/astro/commit/e425f896b668d98033ad3b998b50c1f28bc7f6ee) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Update config options to resepect [RFC0019](https://github.com/withastro/rfcs/blob/main/proposals/0019-config-finalization.md)
|
|
14
|
+
|
|
15
|
+
## 0.7.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#2824](https://github.com/withastro/astro/pull/2824) [`0a3d3e51`](https://github.com/withastro/astro/commit/0a3d3e51a66af80fa949ba0f5e2104439d2be634) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Change shiki to our default markdown syntax highlighter. This includes updates to all relevant starter projects that used Prism-specific styles.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#2870](https://github.com/withastro/astro/pull/2870) [`d763ec18`](https://github.com/withastro/astro/commit/d763ec183ea391ad79ca16bf2b2e76848fc1180c) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Fix a shiki performance issue affecting large sites
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`2db97f10`](https://github.com/withastro/astro/commit/2db97f10dc50f9498413181b78c477fe8833895b)]:
|
|
26
|
+
- @astrojs/prism@0.4.1
|
|
27
|
+
|
|
3
28
|
## 0.7.0-next.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -174,10 +199,10 @@
|
|
|
174
199
|
|
|
175
200
|
```js
|
|
176
201
|
export default {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
202
|
+
markdownOptions: {
|
|
203
|
+
remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]],
|
|
204
|
+
rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
|
|
205
|
+
},
|
|
181
206
|
};
|
|
182
207
|
```
|
|
183
208
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AstroMarkdownOptions, MarkdownRenderingOptions } from './types';
|
|
2
|
-
export { AstroMarkdownOptions, MarkdownRenderingOptions };
|
|
1
|
+
import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types';
|
|
2
|
+
export { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin };
|
|
3
3
|
/** Internal utility for rendering a full markdown file and extracting Frontmatter data */
|
|
4
4
|
export declare function renderMarkdownWithFrontmatter(contents: string, opts?: MarkdownRenderingOptions | null): Promise<{
|
|
5
5
|
frontmatter: {
|
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
|
|
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([
|
|
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
|
|
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);
|
package/dist/load-plugins.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/rehype-escape.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/rehype-islands.d.ts
CHANGED
|
File without changes
|
package/dist/rehype-islands.js
CHANGED
|
@@ -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), {
|
|
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/dist/rehype-jsx.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/remark-jsx.d.ts
CHANGED
|
File without changes
|
package/dist/remark-prism.d.ts
CHANGED
|
File without changes
|
package/dist/remark-prism.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
import Prism from "prismjs";
|
|
3
|
-
import { addAstro } from "@astrojs/prism";
|
|
3
|
+
import { addAstro } from "@astrojs/prism/internal";
|
|
4
4
|
import loadLanguages from "prismjs/components/index.js";
|
|
5
5
|
const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
|
|
6
6
|
const languageMap = /* @__PURE__ */ new Map([["ts", "typescript"]]);
|
|
File without changes
|
package/dist/remark-shiki.d.ts
CHANGED
|
File without changes
|
package/dist/remark-slug.d.ts
CHANGED
|
File without changes
|
package/dist/remark-unwrap.d.ts
CHANGED
|
File without changes
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as unified from 'unified';
|
|
2
2
|
import type { ShikiConfig } from './remark-shiki';
|
|
3
|
+
export { ShikiConfig };
|
|
3
4
|
export declare type Plugin = string | [string, any] | unified.Plugin | [unified.Plugin, any];
|
|
4
5
|
export interface AstroMarkdownOptions {
|
|
5
6
|
mode?: 'md' | 'mdx';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
".": "./dist/index.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@astrojs/prism": "^0.4.1
|
|
19
|
+
"@astrojs/prism": "^0.4.1",
|
|
20
20
|
"assert": "^2.0.0",
|
|
21
21
|
"github-slugger": "^1.4.0",
|
|
22
22
|
"gray-matter": "^4.0.3",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AstroMarkdownOptions, MarkdownRenderingOptions } from './types';
|
|
1
|
+
import type { AstroMarkdownOptions, MarkdownRenderingOptions, ShikiConfig, Plugin } from './types';
|
|
2
2
|
|
|
3
3
|
import createCollectHeaders from './rehype-collect-headers.js';
|
|
4
4
|
import scopedStyles from './remark-scoped-styles.js';
|
|
@@ -20,10 +20,13 @@ import rehypeStringify from 'rehype-stringify';
|
|
|
20
20
|
import rehypeRaw from 'rehype-raw';
|
|
21
21
|
import matter from 'gray-matter';
|
|
22
22
|
|
|
23
|
-
export { AstroMarkdownOptions, MarkdownRenderingOptions };
|
|
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(
|
|
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([
|
|
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(
|
|
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
|
|
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);
|
package/src/rehype-islands.ts
CHANGED
|
@@ -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 (
|
|
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, {
|
|
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,
|
package/src/remark-prism.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
2
|
import Prism from 'prismjs';
|
|
3
|
-
import { addAstro } from '@astrojs/prism';
|
|
3
|
+
import { addAstro } from '@astrojs/prism/internal';
|
|
4
4
|
import loadLanguages from 'prismjs/components/index.js';
|
|
5
5
|
const noVisit = new Set(['root', 'html', 'text']);
|
|
6
6
|
|
|
@@ -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(
|
|
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);
|
package/src/remark-shiki.ts
CHANGED
|
@@ -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 (
|
|
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
|
// <span class="line"
|
|
64
67
|
|
|
65
68
|
// Replace "shiki" class naming with "astro" and add "is:raw".
|
|
66
|
-
html = html.replace(
|
|
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(
|
|
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(
|
|
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
|
package/src/remark-unwrap.ts
CHANGED
|
@@ -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 (
|
|
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
|
|
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
|
}
|