@astrojs/markdown-remark 0.9.2 → 0.9.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/CHANGELOG.md +8 -0
- package/astrojs-markdown-remark-0.9.3.tgz +0 -0
- package/dist/index.d.ts +3 -10
- package/dist/index.js +1 -1
- package/dist/rehype-collect-headers.d.ts +3 -3
- package/dist/rehype-collect-headers.js +6 -5
- package/dist/rehype-islands.js +1 -1
- package/dist/remark-unwrap.js +2 -2
- package/dist/types.d.ts +14 -0
- package/package.json +2 -3
- package/src/index.ts +6 -4
- package/src/rehype-collect-headers.ts +12 -9
- package/src/rehype-islands.ts +3 -3
- package/src/remark-unwrap.ts +3 -3
- package/src/types.ts +17 -0
- package/astrojs-markdown-remark-0.9.2.tgz +0 -0
- package/dist/remark-slug.d.ts +0 -10
- package/dist/remark-slug.js +0 -23
- package/src/remark-slug.ts +0 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @astrojs/markdown-remark
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3234](https://github.com/withastro/astro/pull/3234) [`de123b28`](https://github.com/withastro/astro/commit/de123b28b3ff398b800cb598f20326ca85a0fb60) Thanks [@JuanM04](https://github.com/JuanM04)! - Removed `rehype-slug` in favor of our own implementation. The behavior of the slugging should remain the same
|
|
8
|
+
|
|
9
|
+
* [#3234](https://github.com/withastro/astro/pull/3234) [`de123b28`](https://github.com/withastro/astro/commit/de123b28b3ff398b800cb598f20326ca85a0fb60) Thanks [@JuanM04](https://github.com/JuanM04)! - Moved some type from `astro` to `@astrojs/markdown-remark`
|
|
10
|
+
|
|
3
11
|
## 0.9.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type { MarkdownRenderingOptions } from './types';
|
|
1
|
+
import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export declare const DEFAULT_REMARK_PLUGINS: string[];
|
|
4
|
-
export declare const DEFAULT_REHYPE_PLUGINS:
|
|
4
|
+
export declare const DEFAULT_REHYPE_PLUGINS: never[];
|
|
5
5
|
/** Shared utility for rendering markdown */
|
|
6
|
-
export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<
|
|
7
|
-
metadata: {
|
|
8
|
-
headers: any[];
|
|
9
|
-
source: string;
|
|
10
|
-
html: string;
|
|
11
|
-
};
|
|
12
|
-
code: string;
|
|
13
|
-
}>;
|
|
6
|
+
export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<MarkdownRenderingResult>;
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import rehypeStringify from "rehype-stringify";
|
|
|
17
17
|
import rehypeRaw from "rehype-raw";
|
|
18
18
|
export * from "./types.js";
|
|
19
19
|
const DEFAULT_REMARK_PLUGINS = ["remark-gfm", "remark-smartypants"];
|
|
20
|
-
const DEFAULT_REHYPE_PLUGINS = [
|
|
20
|
+
const DEFAULT_REHYPE_PLUGINS = [];
|
|
21
21
|
async function renderMarkdown(content, opts) {
|
|
22
22
|
var _a;
|
|
23
23
|
let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { MarkdownHeader, RehypePlugin } from './types.js';
|
|
2
2
|
export default function createCollectHeaders(): {
|
|
3
|
-
headers:
|
|
4
|
-
rehypeCollectHeaders: () =>
|
|
3
|
+
headers: MarkdownHeader[];
|
|
4
|
+
rehypeCollectHeaders: () => ReturnType<RehypePlugin>;
|
|
5
5
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
|
-
import
|
|
2
|
+
import Slugger from "github-slugger";
|
|
3
3
|
function createCollectHeaders() {
|
|
4
4
|
const headers = [];
|
|
5
|
+
const slugger = new Slugger();
|
|
5
6
|
function rehypeCollectHeaders() {
|
|
6
7
|
return function(tree) {
|
|
7
8
|
visit(tree, (node) => {
|
|
8
|
-
var _a;
|
|
9
9
|
if (node.type !== "element")
|
|
10
10
|
return;
|
|
11
11
|
const { tagName } = node;
|
|
@@ -19,10 +19,11 @@ function createCollectHeaders() {
|
|
|
19
19
|
visit(node, "text", (child) => {
|
|
20
20
|
text += child.value;
|
|
21
21
|
});
|
|
22
|
-
let slug = ((_a = node == null ? void 0 : node.properties) == null ? void 0 : _a.id) || slugger.slug(text);
|
|
23
22
|
node.properties = node.properties || {};
|
|
24
|
-
node.properties.id
|
|
25
|
-
|
|
23
|
+
if (typeof node.properties.id !== "string") {
|
|
24
|
+
node.properties.id = slugger.slug(text);
|
|
25
|
+
}
|
|
26
|
+
headers.push({ depth, slug: node.properties.id, text });
|
|
26
27
|
});
|
|
27
28
|
};
|
|
28
29
|
}
|
package/dist/rehype-islands.js
CHANGED
|
@@ -22,7 +22,7 @@ const visit = _visit;
|
|
|
22
22
|
function rehypeIslands() {
|
|
23
23
|
return function(node) {
|
|
24
24
|
return visit(node, "element", (el) => {
|
|
25
|
-
if (el.tagName == "astro-
|
|
25
|
+
if (el.tagName == "astro-island") {
|
|
26
26
|
visit(el, "text", (child, index, parent) => {
|
|
27
27
|
if (child.type === "text") {
|
|
28
28
|
if (parent && child.value.indexOf("<!--") > -1 && index != null) {
|
package/dist/remark-unwrap.js
CHANGED
|
@@ -7,10 +7,10 @@ function remarkUnwrap() {
|
|
|
7
7
|
insideAstroRoot = false;
|
|
8
8
|
astroRootNodes.clear();
|
|
9
9
|
visit(tree, "html", (node) => {
|
|
10
|
-
if (node.value.indexOf("<astro-
|
|
10
|
+
if (node.value.indexOf("<astro-island") > -1 && !insideAstroRoot) {
|
|
11
11
|
insideAstroRoot = true;
|
|
12
12
|
}
|
|
13
|
-
if (node.value.indexOf("</astro-
|
|
13
|
+
if (node.value.indexOf("</astro-island") > -1 && insideAstroRoot) {
|
|
14
14
|
insideAstroRoot = false;
|
|
15
15
|
}
|
|
16
16
|
astroRootNodes.add(node);
|
package/dist/types.d.ts
CHANGED
|
@@ -26,3 +26,17 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
|
|
26
26
|
scopedClassName: string | null;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
+
export interface MarkdownHeader {
|
|
30
|
+
depth: number;
|
|
31
|
+
slug: string;
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
export interface MarkdownMetadata {
|
|
35
|
+
headers: MarkdownHeader[];
|
|
36
|
+
source: string;
|
|
37
|
+
html: string;
|
|
38
|
+
}
|
|
39
|
+
export interface MarkdownRenderingResult {
|
|
40
|
+
metadata: MarkdownMetadata;
|
|
41
|
+
code: string;
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,9 +30,8 @@
|
|
|
30
30
|
"mdast-util-mdx-jsx": "^1.2.0",
|
|
31
31
|
"mdast-util-to-string": "^3.1.0",
|
|
32
32
|
"micromark-extension-mdx-jsx": "^1.0.3",
|
|
33
|
-
"prismjs": "^1.
|
|
33
|
+
"prismjs": "^1.28.0",
|
|
34
34
|
"rehype-raw": "^6.1.1",
|
|
35
|
-
"rehype-slug": "^5.0.1",
|
|
36
35
|
"rehype-stringify": "^9.0.3",
|
|
37
36
|
"remark-gfm": "^3.0.1",
|
|
38
37
|
"remark-parse": "^10.0.1",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MarkdownRenderingOptions } from './types';
|
|
1
|
+
import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
|
|
2
2
|
|
|
3
3
|
import createCollectHeaders from './rehype-collect-headers.js';
|
|
4
4
|
import scopedStyles from './remark-scoped-styles.js';
|
|
@@ -22,11 +22,13 @@ import rehypeRaw from 'rehype-raw';
|
|
|
22
22
|
export * from './types.js';
|
|
23
23
|
|
|
24
24
|
export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
|
|
25
|
-
|
|
26
|
-
export const DEFAULT_REHYPE_PLUGINS = ['rehype-slug'];
|
|
25
|
+
export const DEFAULT_REHYPE_PLUGINS = [];
|
|
27
26
|
|
|
28
27
|
/** Shared utility for rendering markdown */
|
|
29
|
-
export async function renderMarkdown(
|
|
28
|
+
export async function renderMarkdown(
|
|
29
|
+
content: string,
|
|
30
|
+
opts: MarkdownRenderingOptions
|
|
31
|
+
): Promise<MarkdownRenderingResult> {
|
|
30
32
|
let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts;
|
|
31
33
|
const scopedClassName = opts.$?.scopedClassName;
|
|
32
34
|
const isMDX = mode === 'mdx';
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
-
import
|
|
2
|
+
import Slugger from 'github-slugger';
|
|
3
|
+
|
|
4
|
+
import type { MarkdownHeader, RehypePlugin } from './types.js';
|
|
3
5
|
|
|
4
|
-
/** */
|
|
5
6
|
export default function createCollectHeaders() {
|
|
6
|
-
const headers:
|
|
7
|
+
const headers: MarkdownHeader[] = [];
|
|
8
|
+
const slugger = new Slugger();
|
|
7
9
|
|
|
8
|
-
function rehypeCollectHeaders() {
|
|
9
|
-
return function (tree
|
|
10
|
+
function rehypeCollectHeaders(): ReturnType<RehypePlugin> {
|
|
11
|
+
return function (tree) {
|
|
10
12
|
visit(tree, (node) => {
|
|
11
13
|
if (node.type !== 'element') return;
|
|
12
14
|
const { tagName } = node;
|
|
@@ -21,11 +23,12 @@ export default function createCollectHeaders() {
|
|
|
21
23
|
text += child.value;
|
|
22
24
|
});
|
|
23
25
|
|
|
24
|
-
let slug = node?.properties?.id || slugger.slug(text);
|
|
25
|
-
|
|
26
26
|
node.properties = node.properties || {};
|
|
27
|
-
node.properties.id
|
|
28
|
-
|
|
27
|
+
if (typeof node.properties.id !== 'string') {
|
|
28
|
+
node.properties.id = slugger.slug(text);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
headers.push({ depth, slug: node.properties.id, text });
|
|
29
32
|
});
|
|
30
33
|
};
|
|
31
34
|
}
|
package/src/rehype-islands.ts
CHANGED
|
@@ -9,14 +9,14 @@ const visit = _visit as (
|
|
|
9
9
|
) => any;
|
|
10
10
|
|
|
11
11
|
// This fixes some confusing bugs coming from somewhere inside of our Markdown pipeline.
|
|
12
|
-
// `unist`/`remark`/`rehype` (not sure) often generate malformed HTML inside of <astro-
|
|
12
|
+
// `unist`/`remark`/`rehype` (not sure) often generate malformed HTML inside of <astro-island>
|
|
13
13
|
// For hydration to work properly, frameworks need the DOM to be the exact same on server/client.
|
|
14
14
|
// This reverts some "helpful corrections" that are applied to our perfectly valid HTML!
|
|
15
15
|
export default function rehypeIslands(): any {
|
|
16
16
|
return function (node: any): any {
|
|
17
17
|
return visit(node, 'element', (el) => {
|
|
18
|
-
// Bugs only happen inside of <astro-
|
|
19
|
-
if (el.tagName == 'astro-
|
|
18
|
+
// Bugs only happen inside of <astro-island> islands
|
|
19
|
+
if (el.tagName == 'astro-island') {
|
|
20
20
|
visit(el, 'text', (child, index, parent) => {
|
|
21
21
|
if (child.type === 'text') {
|
|
22
22
|
// Sometimes comments can be trapped as text, which causes them to be escaped
|
package/src/remark-unwrap.ts
CHANGED
|
@@ -8,7 +8,7 @@ const visit = _visit as (
|
|
|
8
8
|
callback?: (node: any, index: number, parent: any) => any
|
|
9
9
|
) => any;
|
|
10
10
|
|
|
11
|
-
// Remove the wrapping paragraph for <astro-
|
|
11
|
+
// Remove the wrapping paragraph for <astro-island> islands
|
|
12
12
|
export default function remarkUnwrap() {
|
|
13
13
|
const astroRootNodes = new Set();
|
|
14
14
|
let insideAstroRoot = false;
|
|
@@ -19,10 +19,10 @@ export default function remarkUnwrap() {
|
|
|
19
19
|
astroRootNodes.clear();
|
|
20
20
|
|
|
21
21
|
visit(tree, 'html', (node) => {
|
|
22
|
-
if (node.value.indexOf('<astro-
|
|
22
|
+
if (node.value.indexOf('<astro-island') > -1 && !insideAstroRoot) {
|
|
23
23
|
insideAstroRoot = true;
|
|
24
24
|
}
|
|
25
|
-
if (node.value.indexOf('</astro-
|
|
25
|
+
if (node.value.indexOf('</astro-island') > -1 && insideAstroRoot) {
|
|
26
26
|
insideAstroRoot = false;
|
|
27
27
|
}
|
|
28
28
|
astroRootNodes.add(node);
|
package/src/types.ts
CHANGED
|
@@ -40,3 +40,20 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
|
|
40
40
|
scopedClassName: string | null;
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
export interface MarkdownHeader {
|
|
45
|
+
depth: number;
|
|
46
|
+
slug: string;
|
|
47
|
+
text: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface MarkdownMetadata {
|
|
51
|
+
headers: MarkdownHeader[];
|
|
52
|
+
source: string;
|
|
53
|
+
html: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface MarkdownRenderingResult {
|
|
57
|
+
metadata: MarkdownMetadata;
|
|
58
|
+
code: string;
|
|
59
|
+
}
|
|
Binary file
|
package/dist/remark-slug.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('mdast').Root} Root
|
|
3
|
-
* @typedef {import('hast').Properties} Properties
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Plugin to add anchors headings using GitHub’s algorithm.
|
|
7
|
-
*
|
|
8
|
-
* @type {import('unified').Plugin<void[], Root>}
|
|
9
|
-
*/
|
|
10
|
-
export default function remarkSlug(): (tree: any) => void;
|
package/dist/remark-slug.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { toString } from "mdast-util-to-string";
|
|
2
|
-
import { visit } from "unist-util-visit";
|
|
3
|
-
import BananaSlug from "github-slugger";
|
|
4
|
-
const slugs = new BananaSlug();
|
|
5
|
-
function remarkSlug() {
|
|
6
|
-
return (tree) => {
|
|
7
|
-
slugs.reset();
|
|
8
|
-
visit(tree, (node) => {
|
|
9
|
-
console.log(node);
|
|
10
|
-
});
|
|
11
|
-
visit(tree, "heading", (node) => {
|
|
12
|
-
const data = node.data || (node.data = {});
|
|
13
|
-
const props = data.hProperties || (data.hProperties = {});
|
|
14
|
-
let id = props.id;
|
|
15
|
-
id = id ? slugs.slug(String(id), true) : slugs.slug(toString(node));
|
|
16
|
-
data.id = id;
|
|
17
|
-
props.id = id;
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
remarkSlug as default
|
|
23
|
-
};
|
package/src/remark-slug.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import('mdast').Root} Root
|
|
3
|
-
* @typedef {import('hast').Properties} Properties
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { toString } from 'mdast-util-to-string';
|
|
7
|
-
import { visit } from 'unist-util-visit';
|
|
8
|
-
import BananaSlug from 'github-slugger';
|
|
9
|
-
|
|
10
|
-
const slugs = new BananaSlug();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Plugin to add anchors headings using GitHub’s algorithm.
|
|
14
|
-
*
|
|
15
|
-
* @type {import('unified').Plugin<void[], Root>}
|
|
16
|
-
*/
|
|
17
|
-
export default function remarkSlug() {
|
|
18
|
-
return (tree: any) => {
|
|
19
|
-
slugs.reset();
|
|
20
|
-
visit(tree, (node) => {
|
|
21
|
-
console.log(node);
|
|
22
|
-
});
|
|
23
|
-
visit(tree, 'heading', (node) => {
|
|
24
|
-
const data = node.data || (node.data = {});
|
|
25
|
-
const props = /** @type {Properties} */ data.hProperties || (data.hProperties = {});
|
|
26
|
-
let id = props.id;
|
|
27
|
-
id = id ? slugs.slug(String(id), true) : slugs.slug(toString(node));
|
|
28
|
-
data.id = id;
|
|
29
|
-
props.id = id;
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
}
|