@primate/markdown 0.8.0 → 0.10.0
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/lib/private/default.d.ts +10 -0
- package/lib/private/{Default.js → default.js} +33 -22
- package/lib/private/init.d.ts +16 -0
- package/lib/private/init.js +18 -0
- package/lib/private/runtime.d.ts +10 -0
- package/lib/private/runtime.js +4 -0
- package/lib/public/default.d.ts +2 -3
- package/lib/public/default.js +1 -2
- package/lib/public/runtime.d.ts +2 -3
- package/lib/public/runtime.js +1 -2
- package/package.json +13 -11
- package/lib/private/Default.d.ts +0 -11
- package/lib/private/Runtime.d.ts +0 -41
- package/lib/private/Runtime.js +0 -37
- package/lib/public/Component.d.ts +0 -2
- package/lib/public/Component.js +0 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: (input?: import("@rcompat/type").Unpack<({
|
|
2
|
+
extensions?: string[] | undefined;
|
|
3
|
+
spa?: boolean | undefined;
|
|
4
|
+
ssr?: boolean | undefined;
|
|
5
|
+
} & {
|
|
6
|
+
marked?: import("marked").MarkedExtension<string, string> | undefined;
|
|
7
|
+
pretransform?: ((text: string) => import("@rcompat/type").MaybePromise<string>) | undefined;
|
|
8
|
+
}) | undefined>) => import("@primate/core/frontend").Module;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=default.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import init from "#init";
|
|
2
|
+
import frontend from "@primate/core/frontend";
|
|
2
3
|
import fs from "@rcompat/fs";
|
|
3
4
|
import string from "@rcompat/string";
|
|
4
5
|
import { marked } from "marked";
|
|
@@ -11,7 +12,7 @@ function slugify(text) {
|
|
|
11
12
|
function frontmatter(src) {
|
|
12
13
|
const input = src.replace(/^\uFEFF/, "");
|
|
13
14
|
const match = input.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
14
|
-
if (
|
|
15
|
+
if (match === null)
|
|
15
16
|
return {
|
|
16
17
|
body: input,
|
|
17
18
|
meta: null,
|
|
@@ -54,12 +55,28 @@ function frontmatter(src) {
|
|
|
54
55
|
return { body, meta };
|
|
55
56
|
}
|
|
56
57
|
;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
58
|
+
function toc(body) {
|
|
59
|
+
return marked
|
|
60
|
+
.lexer(body)
|
|
61
|
+
.filter(token => token.type === "heading")
|
|
62
|
+
.map(token => {
|
|
63
|
+
const heading = token;
|
|
64
|
+
return {
|
|
65
|
+
depth: heading.depth,
|
|
66
|
+
slug: slugify(heading.text),
|
|
67
|
+
text: heading.text,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export default frontend({
|
|
72
|
+
...init,
|
|
73
|
+
schema: init.schema,
|
|
74
|
+
onBuild(app, options) {
|
|
75
|
+
const pretransform = options.pretransform ?? ((m) => m);
|
|
76
|
+
if (options.marked !== undefined) {
|
|
77
|
+
const renderer = { ...options.marked.renderer ?? {} };
|
|
78
|
+
marked.use({ ...options.marked, renderer });
|
|
79
|
+
}
|
|
63
80
|
app.plugin("server", {
|
|
64
81
|
name: "markdown",
|
|
65
82
|
setup(build) {
|
|
@@ -70,21 +87,13 @@ export default class Default extends Runtime {
|
|
|
70
87
|
build.onLoad({ filter: /.*/, namespace: "markdown" }, async (args) => {
|
|
71
88
|
const text = await fs.text(args.path);
|
|
72
89
|
const { body, meta } = frontmatter(await pretransform(text));
|
|
73
|
-
const tokens = marked.lexer(body);
|
|
74
|
-
const toc = tokens
|
|
75
|
-
.filter(token => token.type === "heading")
|
|
76
|
-
.map(token => ({
|
|
77
|
-
depth: token.depth,
|
|
78
|
-
slug: slugify(token.text),
|
|
79
|
-
text: token.text,
|
|
80
|
-
}));
|
|
81
90
|
return {
|
|
82
91
|
contents: string.dedent `
|
|
83
92
|
export default {
|
|
84
93
|
md: ${JSON.stringify(body)},
|
|
85
94
|
html: ${JSON.stringify(await marked.parse(body))},
|
|
86
|
-
toc: JSON.parse(${JSON.stringify(JSON.stringify(toc))}),
|
|
87
|
-
meta: ${meta ? JSON.stringify(meta) : "null"},
|
|
95
|
+
toc: JSON.parse(${JSON.stringify(JSON.stringify(toc(body)))}),
|
|
96
|
+
meta: ${meta !== null ? JSON.stringify(meta) : "null"},
|
|
88
97
|
};
|
|
89
98
|
`,
|
|
90
99
|
loader: "js",
|
|
@@ -93,7 +102,9 @@ export default class Default extends Runtime {
|
|
|
93
102
|
});
|
|
94
103
|
},
|
|
95
104
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
105
|
+
},
|
|
106
|
+
compile: {
|
|
107
|
+
server: async (_, file) => `export { default } from "markdown:${file.path}";`,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Init } from "@primate/core/frontend";
|
|
2
|
+
import type { MaybePromise } from "@rcompat/type";
|
|
3
|
+
import type { MarkedExtension } from "marked";
|
|
4
|
+
type Pretransform = (text: string) => MaybePromise<string>;
|
|
5
|
+
declare const schema: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
|
|
6
|
+
readonly marked: import("pema").OptionalType<import("pema").PureType<MarkedExtension<string, string>, "PureType">>;
|
|
7
|
+
readonly pretransform: import("pema").OptionalType<import("pema").PureType<Pretransform, "PureType">>;
|
|
8
|
+
}>, {
|
|
9
|
+
marked: MarkedExtension<string, string> | undefined;
|
|
10
|
+
pretransform: Pretransform | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
declare const init: Init<{
|
|
13
|
+
html: string;
|
|
14
|
+
}, typeof schema>;
|
|
15
|
+
export default init;
|
|
16
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import p from "pema";
|
|
2
|
+
const schema = p({
|
|
3
|
+
marked: p.pure().optional(),
|
|
4
|
+
pretransform: p.pure().optional(),
|
|
5
|
+
});
|
|
6
|
+
function render(component) {
|
|
7
|
+
return { body: component.html };
|
|
8
|
+
}
|
|
9
|
+
const init = {
|
|
10
|
+
name: "markdown",
|
|
11
|
+
extensions: [".md"],
|
|
12
|
+
layouts: false,
|
|
13
|
+
client: false,
|
|
14
|
+
render,
|
|
15
|
+
schema,
|
|
16
|
+
};
|
|
17
|
+
export default init;
|
|
18
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: (input?: import("@rcompat/type").Unpack<({
|
|
2
|
+
extensions?: string[] | undefined;
|
|
3
|
+
spa?: boolean | undefined;
|
|
4
|
+
ssr?: boolean | undefined;
|
|
5
|
+
} & {
|
|
6
|
+
marked?: import("marked").MarkedExtension<string, string> | undefined;
|
|
7
|
+
pretransform?: ((text: string) => import("@rcompat/type").MaybePromise<string>) | undefined;
|
|
8
|
+
}) | undefined>) => import("@primate/core/frontend").Module;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=runtime.d.ts.map
|
package/lib/public/default.d.ts
CHANGED
package/lib/public/default.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Markdown for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/frontend/markdown",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -17,21 +17,22 @@
|
|
|
17
17
|
"!/**/*.spec.*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@rcompat/assert": "^0.
|
|
21
|
-
"@rcompat/string": "^0.
|
|
22
|
-
"marked": "^17.0.
|
|
23
|
-
"
|
|
24
|
-
"
|
|
20
|
+
"@rcompat/assert": "^0.8.1",
|
|
21
|
+
"@rcompat/string": "^0.16.1",
|
|
22
|
+
"marked": "^17.0.5",
|
|
23
|
+
"pema": "^0.6.0",
|
|
24
|
+
"@primate/core": "^0.6.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@rcompat/type": "^0.
|
|
27
|
+
"@rcompat/type": "^0.11.1",
|
|
28
|
+
"@primate/test": "^0.0.0"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"primate": "^0.
|
|
31
|
+
"primate": "^0.37.0"
|
|
31
32
|
},
|
|
32
33
|
"imports": {
|
|
33
34
|
"#*": {
|
|
34
|
-
"
|
|
35
|
+
"@primate/source": "./src/private/*.ts",
|
|
35
36
|
"default": "./lib/private/*.js"
|
|
36
37
|
}
|
|
37
38
|
},
|
|
@@ -42,13 +43,14 @@
|
|
|
42
43
|
"default": "./lib/public/default.js"
|
|
43
44
|
},
|
|
44
45
|
"./*": {
|
|
45
|
-
"
|
|
46
|
+
"@primate/source": "./src/public/*.ts",
|
|
46
47
|
"default": "./lib/public/*.js"
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "npm run clean && tsc",
|
|
51
52
|
"clean": "rm -rf ./lib",
|
|
52
|
-
"lint": "eslint ."
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"test": "npm run build && npx proby"
|
|
53
55
|
}
|
|
54
56
|
}
|
package/lib/private/Default.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Runtime from "#Runtime";
|
|
2
|
-
import type BuildApp from "@primate/core/BuildApp";
|
|
3
|
-
import type NextBuild from "@primate/core/NextBuild";
|
|
4
|
-
import type { FileRef } from "@rcompat/fs";
|
|
5
|
-
export default class Default extends Runtime {
|
|
6
|
-
compile: {
|
|
7
|
-
server: (_: string, file: FileRef) => Promise<string>;
|
|
8
|
-
};
|
|
9
|
-
build(app: BuildApp, next: NextBuild): Promise<BuildApp>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=Default.d.ts.map
|
package/lib/private/Runtime.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type Component from "#Component";
|
|
2
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
3
|
-
import type { MaybePromise } from "@rcompat/type";
|
|
4
|
-
import type { MarkedExtension } from "marked";
|
|
5
|
-
declare function render(component: Component): {
|
|
6
|
-
body: string;
|
|
7
|
-
};
|
|
8
|
-
type Pretransform = (text: string) => MaybePromise<string>;
|
|
9
|
-
export default class Runtime extends FrontendModule<Component> {
|
|
10
|
-
#private;
|
|
11
|
-
name: string;
|
|
12
|
-
defaultExtensions: string[];
|
|
13
|
-
layouts: boolean;
|
|
14
|
-
client: boolean;
|
|
15
|
-
render: typeof render;
|
|
16
|
-
static schema: import("pema").ObjectType<{
|
|
17
|
-
fileExtensions: import("pema").OptionalType<import("pema").ArrayType<import("pema").StringType>>;
|
|
18
|
-
marked: import("pema").OptionalType<import("pema").PureType<MarkedExtension<string, string>, "PureType">>;
|
|
19
|
-
pretransform: import("pema").OptionalType<import("pema").PureType<Pretransform, "PureType">>;
|
|
20
|
-
spa: import("pema").DefaultType<import("pema").BooleanType, true>;
|
|
21
|
-
ssr: import("pema").DefaultType<import("pema").BooleanType, true>;
|
|
22
|
-
}>;
|
|
23
|
-
static options: {
|
|
24
|
-
fileExtensions: string[] | undefined;
|
|
25
|
-
marked: MarkedExtension<string, string> | undefined;
|
|
26
|
-
pretransform: Pretransform | undefined;
|
|
27
|
-
spa: boolean;
|
|
28
|
-
ssr: boolean;
|
|
29
|
-
};
|
|
30
|
-
static input: {
|
|
31
|
-
fileExtensions?: string[] | undefined;
|
|
32
|
-
marked?: MarkedExtension<string, string> | undefined;
|
|
33
|
-
pretransform?: Pretransform | undefined;
|
|
34
|
-
spa?: boolean | undefined;
|
|
35
|
-
ssr?: boolean | undefined;
|
|
36
|
-
} | undefined;
|
|
37
|
-
constructor(config?: typeof Runtime.input);
|
|
38
|
-
get pretransform(): Pretransform;
|
|
39
|
-
}
|
|
40
|
-
export {};
|
|
41
|
-
//# sourceMappingURL=Runtime.d.ts.map
|
package/lib/private/Runtime.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import FrontendModule from "@primate/core/frontend/Module";
|
|
2
|
-
import assert from "@rcompat/assert";
|
|
3
|
-
import { marked } from "marked";
|
|
4
|
-
import p from "pema";
|
|
5
|
-
function render(component) {
|
|
6
|
-
return { body: component.html };
|
|
7
|
-
}
|
|
8
|
-
export default class Runtime extends FrontendModule {
|
|
9
|
-
name = "markdown";
|
|
10
|
-
defaultExtensions = [".md"];
|
|
11
|
-
layouts = false;
|
|
12
|
-
client = false;
|
|
13
|
-
render = render;
|
|
14
|
-
#pretransform;
|
|
15
|
-
static schema = p({
|
|
16
|
-
fileExtensions: p.array(p.string).optional(),
|
|
17
|
-
marked: p.pure().optional(),
|
|
18
|
-
pretransform: p.pure().optional(),
|
|
19
|
-
spa: p.boolean.default(true),
|
|
20
|
-
ssr: p.boolean.default(true),
|
|
21
|
-
});
|
|
22
|
-
static options = Runtime.schema.infer;
|
|
23
|
-
static input = Runtime.schema.input;
|
|
24
|
-
constructor(config = {}) {
|
|
25
|
-
const { marked: marked_options, pretransform, ...super_config } = config;
|
|
26
|
-
super(super_config);
|
|
27
|
-
assert.maybe.dict(marked_options);
|
|
28
|
-
assert.maybe.function(pretransform);
|
|
29
|
-
this.#pretransform = (pretransform ?? ((m) => m));
|
|
30
|
-
const renderer = { ...marked_options?.renderer ?? {} };
|
|
31
|
-
marked.use({ ...marked_options, renderer });
|
|
32
|
-
}
|
|
33
|
-
get pretransform() {
|
|
34
|
-
return this.#pretransform;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=Runtime.js.map
|
package/lib/public/Component.js
DELETED