@astrojs/markdown-remark 0.8.0 → 0.8.3
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 -5
- package/CHANGELOG.md +6 -0
- package/dist/index.js +11 -3
- package/dist/rehype-islands.js +4 -1
- package/package.json +10 -10
- package/src/index.ts +20 -9
- package/src/rehype-islands.ts +10 -2
- package/src/remark-prism.ts +3 -1
- package/src/remark-shiki.ts +16 -4
- package/src/remark-unwrap.ts +8 -2
- package/LICENSE +0 -34
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
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,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
|
|
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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./dist/index.js"
|
|
17
17
|
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"prepublish": "pnpm build",
|
|
20
|
+
"build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
|
|
21
|
+
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
22
|
+
"postbuild": "astro-scripts copy \"src/**/*.js\"",
|
|
23
|
+
"dev": "astro-scripts dev \"src/**/*.ts\""
|
|
24
|
+
},
|
|
18
25
|
"dependencies": {
|
|
19
26
|
"@astrojs/prism": "^0.4.1",
|
|
20
27
|
"assert": "^2.0.0",
|
|
@@ -41,13 +48,6 @@
|
|
|
41
48
|
"devDependencies": {
|
|
42
49
|
"@types/github-slugger": "^1.3.0",
|
|
43
50
|
"@types/prismjs": "^1.26.0",
|
|
44
|
-
"astro-scripts": "
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"prepublish": "pnpm build",
|
|
48
|
-
"build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
|
|
49
|
-
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
50
|
-
"postbuild": "astro-scripts copy \"src/**/*.js\"",
|
|
51
|
-
"dev": "astro-scripts dev \"src/**/*.ts\""
|
|
51
|
+
"astro-scripts": "workspace:*"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
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(
|
|
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
|
@@ -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
|
}
|
package/LICENSE
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Fred K. Schott
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"""
|
|
25
|
-
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
|
26
|
-
|
|
27
|
-
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
28
|
-
|
|
29
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
30
|
-
|
|
31
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
32
|
-
|
|
33
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
34
|
-
"""
|