@astrojs/markdown-remark 0.14.0 → 0.14.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 +2 -2
- package/CHANGELOG.md +10 -0
- package/dist/index.js +7 -6
- package/dist/rehype-escape.js +2 -2
- package/dist/remark-initialize-astro-data.d.ts +2 -0
- package/dist/remark-initialize-astro-data.js +10 -0
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/index.ts +7 -5
- package/src/rehype-escape.ts +3 -2
- package/src/remark-escape.ts +1 -1
- package/src/remark-initialize-astro-data.ts +9 -0
- package/src/types.ts +2 -0
- package/test/entities.test.js +15 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
[35m@astrojs/markdown-remark:build: [0mcache hit, replaying output [
|
|
1
|
+
[35m@astrojs/markdown-remark:build: [0mcache hit, replaying output [2mf2df71f430c1c421[0m
|
|
2
2
|
[35m@astrojs/markdown-remark:build: [0m
|
|
3
|
-
[35m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@0.14.
|
|
3
|
+
[35m@astrojs/markdown-remark:build: [0m> @astrojs/markdown-remark@0.14.1 build /home/runner/work/astro/astro/packages/markdown/remark
|
|
4
4
|
[35m@astrojs/markdown-remark:build: [0m> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
|
|
5
5
|
[35m@astrojs/markdown-remark:build: [0m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @astrojs/markdown-remark
|
|
2
2
|
|
|
3
|
+
## 0.14.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4176](https://github.com/withastro/astro/pull/4176) [`2675b8633`](https://github.com/withastro/astro/commit/2675b8633c5d5c45b237ec87940d5eaf1bfb1b4b) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Support frontmatter injection for MD and MDX using remark and rehype plugins
|
|
8
|
+
|
|
9
|
+
* [#4137](https://github.com/withastro/astro/pull/4137) [`471c6f784`](https://github.com/withastro/astro/commit/471c6f784e21399676c8b2002665ffdf83a1c59e) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Speed up internal markdown builds with new vite-plugin markdown
|
|
10
|
+
|
|
11
|
+
- [#4169](https://github.com/withastro/astro/pull/4169) [`16034f0dd`](https://github.com/withastro/astro/commit/16034f0dd5b3683e9e022dbd413e85bd18d2b031) Thanks [@hippotastic](https://github.com/hippotastic)! - Fix double-escaping of non-highlighted code blocks in Astro-flavored markdown
|
|
12
|
+
|
|
3
13
|
## 0.14.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import rehypeExpressions from "./rehype-expressions.js";
|
|
|
5
5
|
import rehypeIslands from "./rehype-islands.js";
|
|
6
6
|
import rehypeJsx from "./rehype-jsx.js";
|
|
7
7
|
import remarkEscape from "./remark-escape.js";
|
|
8
|
+
import { remarkInitializeAstroData } from "./remark-initialize-astro-data.js";
|
|
8
9
|
import remarkMarkAndUnravel from "./remark-mark-and-unravel.js";
|
|
9
10
|
import remarkMdxish from "./remark-mdxish.js";
|
|
10
11
|
import remarkPrism from "./remark-prism.js";
|
|
@@ -33,7 +34,7 @@ async function renderMarkdown(content, opts) {
|
|
|
33
34
|
const input = new VFile({ value: content, path: fileURL });
|
|
34
35
|
const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
|
|
35
36
|
const { headings, rehypeCollectHeadings } = createCollectHeadings();
|
|
36
|
-
let parser = unified().use(markdown).use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
|
|
37
|
+
let parser = unified().use(markdown).use(remarkInitializeAstroData).use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
|
|
37
38
|
if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
|
|
38
39
|
remarkPlugins = [...DEFAULT_REMARK_PLUGINS];
|
|
39
40
|
rehypePlugins = [...DEFAULT_REHYPE_PLUGINS];
|
|
@@ -72,18 +73,18 @@ async function renderMarkdown(content, opts) {
|
|
|
72
73
|
parser.use(
|
|
73
74
|
isAstroFlavoredMd ? [rehypeJsx, rehypeExpressions, rehypeEscape, rehypeIslands, rehypeCollectHeadings] : [rehypeCollectHeadings, rehypeRaw]
|
|
74
75
|
).use(rehypeStringify, { allowDangerousHtml: true });
|
|
75
|
-
let
|
|
76
|
+
let vfile;
|
|
76
77
|
try {
|
|
77
|
-
|
|
78
|
-
result = vfile.toString();
|
|
78
|
+
vfile = await parser.process(input);
|
|
79
79
|
} catch (err) {
|
|
80
80
|
err = prefixError(err, `Failed to parse Markdown file "${input.path}"`);
|
|
81
81
|
console.error(err);
|
|
82
82
|
throw err;
|
|
83
83
|
}
|
|
84
84
|
return {
|
|
85
|
-
metadata: { headings, source: content, html:
|
|
86
|
-
code:
|
|
85
|
+
metadata: { headings, source: content, html: String(vfile.value) },
|
|
86
|
+
code: String(vfile.value),
|
|
87
|
+
vfile
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
90
|
function prefixError(err, prefix) {
|
package/dist/rehype-escape.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { visit } from "unist-util-visit";
|
|
1
|
+
import { SKIP, visit } from "unist-util-visit";
|
|
2
2
|
function escapeEntities(value) {
|
|
3
3
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
4
4
|
}
|
|
@@ -10,8 +10,8 @@ function rehypeEscape() {
|
|
|
10
10
|
visit(el, "raw", (raw) => {
|
|
11
11
|
raw.value = escapeEntities(raw.value);
|
|
12
12
|
});
|
|
13
|
+
return SKIP;
|
|
13
14
|
}
|
|
14
|
-
return el;
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type * as hast from 'hast';
|
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
3
|
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
|
4
4
|
import type * as unified from 'unified';
|
|
5
|
+
import type { VFile } from 'vfile';
|
|
5
6
|
export type { Node } from 'unist';
|
|
6
7
|
export declare type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, mdast.Root>;
|
|
7
8
|
export declare type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
|
|
@@ -41,5 +42,6 @@ export interface MarkdownMetadata {
|
|
|
41
42
|
}
|
|
42
43
|
export interface MarkdownRenderingResult {
|
|
43
44
|
metadata: MarkdownMetadata;
|
|
45
|
+
vfile: VFile;
|
|
44
46
|
code: string;
|
|
45
47
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import rehypeExpressions from './rehype-expressions.js';
|
|
|
7
7
|
import rehypeIslands from './rehype-islands.js';
|
|
8
8
|
import rehypeJsx from './rehype-jsx.js';
|
|
9
9
|
import remarkEscape from './remark-escape.js';
|
|
10
|
+
import { remarkInitializeAstroData } from './remark-initialize-astro-data.js';
|
|
10
11
|
import remarkMarkAndUnravel from './remark-mark-and-unravel.js';
|
|
11
12
|
import remarkMdxish from './remark-mdxish.js';
|
|
12
13
|
import remarkPrism from './remark-prism.js';
|
|
@@ -45,6 +46,7 @@ export async function renderMarkdown(
|
|
|
45
46
|
|
|
46
47
|
let parser = unified()
|
|
47
48
|
.use(markdown)
|
|
49
|
+
.use(remarkInitializeAstroData)
|
|
48
50
|
.use(isAstroFlavoredMd ? [remarkMdxish, remarkMarkAndUnravel, remarkUnwrap, remarkEscape] : []);
|
|
49
51
|
|
|
50
52
|
if (remarkPlugins.length === 0 && rehypePlugins.length === 0) {
|
|
@@ -99,10 +101,9 @@ export async function renderMarkdown(
|
|
|
99
101
|
)
|
|
100
102
|
.use(rehypeStringify, { allowDangerousHtml: true });
|
|
101
103
|
|
|
102
|
-
let
|
|
104
|
+
let vfile: VFile;
|
|
103
105
|
try {
|
|
104
|
-
|
|
105
|
-
result = vfile.toString();
|
|
106
|
+
vfile = await parser.process(input);
|
|
106
107
|
} catch (err) {
|
|
107
108
|
// Ensure that the error message contains the input filename
|
|
108
109
|
// to make it easier for the user to fix the issue
|
|
@@ -113,8 +114,9 @@ export async function renderMarkdown(
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
return {
|
|
116
|
-
metadata: { headings, source: content, html:
|
|
117
|
-
code:
|
|
117
|
+
metadata: { headings, source: content, html: String(vfile.value) },
|
|
118
|
+
code: String(vfile.value),
|
|
119
|
+
vfile,
|
|
118
120
|
};
|
|
119
121
|
}
|
|
120
122
|
|
package/src/rehype-escape.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { visit } from 'unist-util-visit';
|
|
1
|
+
import { SKIP, visit } from 'unist-util-visit';
|
|
2
2
|
|
|
3
3
|
export function escapeEntities(value: string): string {
|
|
4
4
|
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
@@ -14,8 +14,9 @@ export default function rehypeEscape(): any {
|
|
|
14
14
|
visit(el, 'raw', (raw) => {
|
|
15
15
|
raw.value = escapeEntities(raw.value);
|
|
16
16
|
});
|
|
17
|
+
// Do not visit children to prevent double escaping
|
|
18
|
+
return SKIP;
|
|
17
19
|
}
|
|
18
|
-
return el;
|
|
19
20
|
});
|
|
20
21
|
};
|
|
21
22
|
}
|
package/src/remark-escape.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Literal } from 'unist';
|
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
|
|
4
4
|
// In code blocks, this removes the JS comment wrapper added to
|
|
5
|
-
// HTML comments by vite-plugin-markdown.
|
|
5
|
+
// HTML comments by vite-plugin-markdown-legacy.
|
|
6
6
|
export default function remarkEscape() {
|
|
7
7
|
return (tree: any) => {
|
|
8
8
|
visit(tree, 'code', removeCommentWrapper);
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type * as hast from 'hast';
|
|
|
2
2
|
import type * as mdast from 'mdast';
|
|
3
3
|
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
|
4
4
|
import type * as unified from 'unified';
|
|
5
|
+
import type { VFile } from 'vfile';
|
|
5
6
|
|
|
6
7
|
export type { Node } from 'unist';
|
|
7
8
|
|
|
@@ -58,5 +59,6 @@ export interface MarkdownMetadata {
|
|
|
58
59
|
|
|
59
60
|
export interface MarkdownRenderingResult {
|
|
60
61
|
metadata: MarkdownMetadata;
|
|
62
|
+
vfile: VFile;
|
|
61
63
|
code: string;
|
|
62
64
|
}
|
package/test/entities.test.js
CHANGED
|
@@ -2,11 +2,22 @@ import { renderMarkdown } from '../dist/index.js';
|
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
|
|
4
4
|
describe('entities', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
it('should not unescape entities in regular Markdown', async () => {
|
|
6
|
+
const { code } = await renderMarkdown(`<i>This should NOT be italic</i>`, {
|
|
7
|
+
isAstroFlavoredMd: false,
|
|
8
|
+
});
|
|
9
9
|
|
|
10
10
|
expect(code).to.equal(`<p><i>This should NOT be italic</i></p>`);
|
|
11
11
|
});
|
|
12
|
+
|
|
13
|
+
it('should not escape entities in code blocks twice in Astro-flavored markdown', async () => {
|
|
14
|
+
const { code } = await renderMarkdown(`\`\`\`astro\n<h1>{x && x.name || ''}!</h1>\n\`\`\``, {
|
|
15
|
+
isAstroFlavoredMd: true,
|
|
16
|
+
syntaxHighlight: false,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(code).to.equal(
|
|
20
|
+
`<pre is:raw><code class="language-astro"><h1>{x && x.name || ''}!</h1>\n</code></pre>`
|
|
21
|
+
);
|
|
22
|
+
});
|
|
12
23
|
});
|