@primate/markdown 0.2.0 → 0.4.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/LICENSE +19 -0
- package/package.json +26 -8
- package/src/private/build/index.js +18 -0
- package/src/private/build/server.js +10 -0
- package/src/private/extension.js +1 -0
- package/src/private/name.js +1 -0
- package/src/private/pkgname.js +1 -0
- package/src/private/serve/index.js +3 -0
- package/src/public/default.js +10 -0
- package/src/public/runtime.js +8 -0
- package/README.md +0 -5
- package/src/compile.js +0 -24
- package/src/errors.js +0 -6
- package/src/errors.json +0 -10
- package/src/exports.js +0 -3
- package/src/module.js +0 -65
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) Terrablue <terrablue@proton.me> and contributors.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/markdown",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Primate Markdown
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Primate Markdown frontend",
|
|
5
5
|
"homepage": "https://primatejs.com/modules/markdown",
|
|
6
6
|
"bugs": "https://github.com/primatejs/primate/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
9
|
"src/**/*.js",
|
|
10
|
-
"src/errors.json",
|
|
11
10
|
"!src/**/*.spec.js"
|
|
12
11
|
],
|
|
13
12
|
"repository": {
|
|
@@ -16,12 +15,31 @@
|
|
|
16
15
|
"directory": "packages/markdown"
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
|
-
"
|
|
20
|
-
"runtime-compat": "^0.25.8"
|
|
18
|
+
"@primate/frontend": "^0.16.0"
|
|
21
19
|
},
|
|
22
20
|
"peerDependencies": {
|
|
23
|
-
"
|
|
21
|
+
"marked": "13",
|
|
22
|
+
"primate": "^0.32.0"
|
|
24
23
|
},
|
|
25
24
|
"type": "module",
|
|
26
|
-
"
|
|
27
|
-
|
|
25
|
+
"imports": {
|
|
26
|
+
"#*": {
|
|
27
|
+
"@primate/lt": "./src/private/*.js",
|
|
28
|
+
"default": "./src/private/*.js"
|
|
29
|
+
},
|
|
30
|
+
"#build": {
|
|
31
|
+
"@primate/lt": "./src/private/build/index.js",
|
|
32
|
+
"default": "./src/private/build/index.js"
|
|
33
|
+
},
|
|
34
|
+
"#serve": {
|
|
35
|
+
"@primate/lt": "./src/private/serve/index.js",
|
|
36
|
+
"default": "./src/private/serve/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"runtime": "./src/public/runtime.js",
|
|
42
|
+
"default": "./src/public/default.js"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import name from "#name";
|
|
2
|
+
import compile from "@primate/frontend/core/compile";
|
|
3
|
+
import server from "./server.js";
|
|
4
|
+
|
|
5
|
+
export default (extension, options) => async (app, next) => {
|
|
6
|
+
app.register(extension, {
|
|
7
|
+
...await compile({
|
|
8
|
+
app,
|
|
9
|
+
extension,
|
|
10
|
+
name,
|
|
11
|
+
compile: { server: server(options) },
|
|
12
|
+
}),
|
|
13
|
+
// no support for hydration
|
|
14
|
+
client: _ => _,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return next(app);
|
|
18
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { marked } from "marked";
|
|
2
|
+
|
|
3
|
+
const compile = text => `export default () => ${JSON.stringify(text)};`;
|
|
4
|
+
|
|
5
|
+
export default options => async (text) => {
|
|
6
|
+
const renderer = { ...options?.renderer ?? {} };
|
|
7
|
+
marked.use({ ...options, renderer });
|
|
8
|
+
|
|
9
|
+
return compile(await marked.parse(text));
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default ".md";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default "markdown";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default "@primate/markdown";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import build from "#build";
|
|
2
|
+
import default_extension from "#extension";
|
|
3
|
+
import pkgname from "#pkgname";
|
|
4
|
+
import serve from "#serve";
|
|
5
|
+
|
|
6
|
+
export default ({ extension = default_extension } = {}) => ({
|
|
7
|
+
name: pkgname,
|
|
8
|
+
build: build(extension),
|
|
9
|
+
serve: serve(extension),
|
|
10
|
+
});
|
package/README.md
DELETED
package/src/compile.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {marked} from "marked";
|
|
2
|
-
|
|
3
|
-
const identity_heading = (text, level) => `<h${level}>${text}</h${level}>`;
|
|
4
|
-
const heading = options => options?.renderer?.heading ?? identity_heading;
|
|
5
|
-
|
|
6
|
-
export default (input, options) => {
|
|
7
|
-
const toc = [];
|
|
8
|
-
const renderer = {
|
|
9
|
-
...options?.renderer ?? {},
|
|
10
|
-
heading(text, level) {
|
|
11
|
-
toc.push({text, level,
|
|
12
|
-
name: text.toLowerCase()
|
|
13
|
-
.replaceAll(/[?{}%]/gu, "")
|
|
14
|
-
.replace(/[^\w]+/gu, "-"),
|
|
15
|
-
});
|
|
16
|
-
return heading(options)(text, level);
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
marked.use({...options, renderer});
|
|
20
|
-
|
|
21
|
-
const content = marked.parse(input);
|
|
22
|
-
|
|
23
|
-
return {content, toc};
|
|
24
|
-
};
|
package/src/errors.js
DELETED
package/src/errors.json
DELETED
package/src/exports.js
DELETED
package/src/module.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {Response, Status, MediaType} from "runtime-compat/http";
|
|
2
|
-
import {stringify} from "runtime-compat/object";
|
|
3
|
-
import compile from "./compile.js";
|
|
4
|
-
|
|
5
|
-
const respond = (handler, directory) => (...[name, ...rest]) =>
|
|
6
|
-
async (app, ...noapp) => {
|
|
7
|
-
const base = app.runpath(app.config.location.server, directory);
|
|
8
|
-
const content = await base.join(`${name}.html`).text();
|
|
9
|
-
const toc = await base.join(`${name}.json`).json();
|
|
10
|
-
|
|
11
|
-
return handler({content, toc}, ...rest)(app, ...noapp);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const as_html = ({content}, _, {status = Status.OK, page} = {}) => async app =>
|
|
15
|
-
new Response(await app.render({body: content, page}), {
|
|
16
|
-
status,
|
|
17
|
-
headers: {...await app.headers(), "Content-Type": MediaType.TEXT_HTML},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export default ({
|
|
21
|
-
directory,
|
|
22
|
-
extension = "md",
|
|
23
|
-
options,
|
|
24
|
-
handler,
|
|
25
|
-
} = {}) => {
|
|
26
|
-
const env = {};
|
|
27
|
-
const re = new RegExp(`^.*.(?:${extension})$`, "u");
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
name: "primate:markdown",
|
|
31
|
-
async init(app, next) {
|
|
32
|
-
env.directory = directory ?? app.config.location.components;
|
|
33
|
-
|
|
34
|
-
return next(app);
|
|
35
|
-
},
|
|
36
|
-
register(app, next) {
|
|
37
|
-
app.register(extension, respond(handler ?? as_html, env.directory));
|
|
38
|
-
return next(app);
|
|
39
|
-
},
|
|
40
|
-
async compile(app, next) {
|
|
41
|
-
const {location} = app.config;
|
|
42
|
-
const source = app.runpath(env.directory);
|
|
43
|
-
// copy ${env.directory} to build/${env.directory}
|
|
44
|
-
await app.stage(app.root.join(env.directory), env.directory, re);
|
|
45
|
-
|
|
46
|
-
const components = await source.collect(re);
|
|
47
|
-
const target = app.runpath(location.server, env.directory);
|
|
48
|
-
await target.file.create();
|
|
49
|
-
|
|
50
|
-
await Promise.all(components.map(async component => {
|
|
51
|
-
const filename = component.path;
|
|
52
|
-
const {content, toc} = compile(await component.text(), options);
|
|
53
|
-
|
|
54
|
-
const html = target.join(`${filename}.html`.replace(source, ""));
|
|
55
|
-
await html.directory.file.create();
|
|
56
|
-
await html.file.write(content);
|
|
57
|
-
|
|
58
|
-
const json = target.join(`${filename}.json`.replace(source, ""));
|
|
59
|
-
await json.file.write(stringify(toc));
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
return next(app);
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
};
|