@primate/markdown 0.1.1 → 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 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.1.1",
4
- "description": "Primate Markdown module",
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
- "marked": "^7.0.4",
20
- "runtime-compat": "^0.25.7"
18
+ "@primate/frontend": "^0.16.0"
21
19
  },
22
20
  "peerDependencies": {
23
- "primate": "0.22"
21
+ "marked": "13",
22
+ "primate": "^0.32.0"
24
23
  },
25
24
  "type": "module",
26
- "exports": "./src/exports.js"
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,3 @@
1
+ import serve from "@primate/frontend/core/serve";
2
+
3
+ export default serve();
@@ -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
+ });
@@ -0,0 +1,8 @@
1
+ import default_extension from "#extension";
2
+ import pkgname from "#pkgname";
3
+ import serve from "#serve";
4
+
5
+ export default ({ extension = default_extension } = {}) => ({
6
+ name: pkgname,
7
+ serve: serve(extension),
8
+ });
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # Markdown
2
-
3
- This handler serves Markdown components with the `md` file extension.
4
-
5
- ## [Documentation](https://primatejs.com/modules/markdown)
package/src/compile.js DELETED
@@ -1,39 +0,0 @@
1
- import {marked} from "marked";
2
-
3
- const identity_heading = (text, level) => `<h${level}>${text}</h${level}>`;
4
-
5
- export default async ({
6
- app,
7
- directory,
8
- options,
9
- }) => {
10
- const {location} = app.config;
11
- const monkeyed_heading = options?.renderer?.heading ?? identity_heading;
12
- const source = app.runpath(directory);
13
- const target = app.runpath(location.server, directory);
14
- await target.file.create();
15
-
16
- return async (filename, input) => {
17
- const toc = [];
18
- const renderer = {
19
- ...options?.renderer ?? {},
20
- heading(text, level) {
21
- const name = text.toLowerCase().replaceAll(/[?{}%]/gu, "");
22
- toc.push({level, text, name});
23
- return monkeyed_heading(text, level);
24
- },
25
- };
26
- marked.use({
27
- ...options,
28
- renderer,
29
- });
30
-
31
- const content = marked.parse(input);
32
- const html = target.join(`${filename}.html`.replace(source, ""));
33
- await html.directory.file.create();
34
- await html.file.write(content);
35
-
36
- const json = target.join(`${filename}.json`.replace(source, ""));
37
- await json.file.write(JSON.stringify(toc));
38
- };
39
- };
package/src/errors.js DELETED
@@ -1,6 +0,0 @@
1
- import {Path} from "runtime-compat/fs";
2
- import {Logger} from "primate";
3
-
4
- const json = await new Path(import.meta.url).up(1).join("errors.json").json();
5
-
6
- export default Logger.err(json.errors, json.module);
package/src/errors.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "module": "primate/solid",
3
- "errors": {
4
- "MissingComponent": {
5
- "message": "missing component {0}",
6
- "fix": "create {1} or remove route function",
7
- "level": "Error"
8
- }
9
- }
10
- }
package/src/exports.js DELETED
@@ -1,3 +0,0 @@
1
- export {default} from "./module.js";
2
-
3
- export {default as compile} from "./compile.js";
package/src/module.js DELETED
@@ -1,67 +0,0 @@
1
- import {Response, Status, MediaType} from "runtime-compat/http";
2
- import precompile from "./compile.js";
3
-
4
- const respond = (handler, directory) => (...[name, ...rest]) => async app => {
5
- const base = app.runpath(app.config.location.server, directory);
6
- const content = await base.join(`${name}.html`).text();
7
- const toc = await base.join(`${name}.json`).json();
8
-
9
- return handler({
10
- content,
11
- toc,
12
- }, ...rest);
13
- };
14
-
15
- const as_html = app => async ({content}, _, {status = Status.OK} = {}) =>
16
- new Response(await app.render({body: content}), {
17
- status,
18
- headers: {...await app.headers(), "Content-Type": MediaType.TEXT_HTML},
19
- });
20
-
21
- export default ({
22
- directory,
23
- extension = "md",
24
- options,
25
- handler,
26
- } = {}) => {
27
- const env = {};
28
- const re = new RegExp(`^.*.(?:${extension})$`, "u");
29
- let compile;
30
-
31
- return {
32
- name: "primate:markdown",
33
- async init(app, next) {
34
- env.directory = directory ?? app.config.location.components;
35
-
36
- return next(app);
37
- },
38
- register(app, next) {
39
- app.register(extension, respond(handler ?? as_html(app), env.directory));
40
- return next(app);
41
- },
42
- async compile(app, next) {
43
- const {location} = app.config;
44
- const source = app.runpath(env.directory);
45
- // copy ${env.directory} to build/${env.directory}
46
- await app.stage(app.root.join(env.directory), env.directory, re);
47
-
48
- const components = await source.collect(re);
49
- const target = app.runpath(location.server, env.directory);
50
- await target.file.create();
51
-
52
- compile = await precompile({
53
- app,
54
- directory: env.directory,
55
- options,
56
- });
57
-
58
- await Promise.all(components.map(async component =>
59
- compile(component.path, await component.file.read())));
60
-
61
- return next(app);
62
- },
63
- async handle(request, next) {
64
- return next({...request, markdown: {compile}});
65
- },
66
- };
67
- };