@weborigami/origami 0.2.9 → 0.2.11
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"main": "./main.js",
|
|
14
14
|
"types": "./index.ts",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@types/node": "22.13.
|
|
16
|
+
"@types/node": "22.13.13",
|
|
17
17
|
"typescript": "5.8.2"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@weborigami/async-tree": "0.2.
|
|
21
|
-
"@weborigami/language": "0.2.
|
|
22
|
-
"@weborigami/types": "0.2.
|
|
20
|
+
"@weborigami/async-tree": "0.2.11",
|
|
21
|
+
"@weborigami/language": "0.2.11",
|
|
22
|
+
"@weborigami/types": "0.2.11",
|
|
23
23
|
"exif-parser": "0.1.12",
|
|
24
24
|
"graphviz-wasm": "3.0.2",
|
|
25
25
|
"highlight.js": "11.11.1",
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extension,
|
|
3
|
-
ObjectTree,
|
|
4
|
-
symbols,
|
|
5
|
-
trailingSlash,
|
|
6
|
-
} from "@weborigami/async-tree";
|
|
1
|
+
import { extension, trailingSlash } from "@weborigami/async-tree";
|
|
7
2
|
import { compile } from "@weborigami/language";
|
|
8
|
-
import { parseYaml } from "../common/serialize.js";
|
|
9
3
|
import { toString } from "../common/utilities.js";
|
|
10
4
|
import { processUnpackedContent } from "../internal.js";
|
|
11
5
|
import getParent from "./getParent.js";
|
|
12
|
-
import parseFrontMatter from "./parseFrontMatter.js";
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* An Origami template document: a plain text file that contains Origami
|
|
@@ -23,7 +16,7 @@ export default {
|
|
|
23
16
|
const parent = getParent(packed, options);
|
|
24
17
|
|
|
25
18
|
// Unpack as a text document
|
|
26
|
-
const
|
|
19
|
+
const text = toString(packed);
|
|
27
20
|
|
|
28
21
|
// See if we can construct a URL to use in error messages
|
|
29
22
|
const key = options.key;
|
|
@@ -36,79 +29,16 @@ export default {
|
|
|
36
29
|
url = new URL(key, parentHref);
|
|
37
30
|
}
|
|
38
31
|
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
let frontData = null;
|
|
42
|
-
let frontSource = null;
|
|
43
|
-
let offset = 0;
|
|
44
|
-
let extendedParent = parent;
|
|
45
|
-
const parsed = parseFrontMatter(unpacked);
|
|
46
|
-
if (!parsed) {
|
|
47
|
-
text = unpacked;
|
|
48
|
-
} else {
|
|
49
|
-
const { body, frontText, isOrigami } = parsed;
|
|
50
|
-
if (isOrigami) {
|
|
51
|
-
// Origami front matter
|
|
52
|
-
frontSource = { name: key, text: frontText, url };
|
|
53
|
-
} else {
|
|
54
|
-
// YAML front matter
|
|
55
|
-
frontData = parseYaml(frontText);
|
|
56
|
-
if (typeof frontData !== "object") {
|
|
57
|
-
throw new TypeError(`YAML or JSON front matter must be an object`);
|
|
58
|
-
}
|
|
59
|
-
extendedParent = new ObjectTree(frontData);
|
|
60
|
-
extendedParent.parent = parent;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Determine how many lines the source code is offset by (if any) to
|
|
64
|
-
// account for front matter, plus 2 lines for `---` separators
|
|
65
|
-
offset = (frontText.match(/\r?\n/g) ?? []).length + 2;
|
|
66
|
-
|
|
67
|
-
text = body;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Construct an object to represent the source code
|
|
71
|
-
const bodySource = {
|
|
32
|
+
// Compile the text as an Origami template document
|
|
33
|
+
const source = {
|
|
72
34
|
name: key,
|
|
73
|
-
offset,
|
|
74
35
|
text,
|
|
75
36
|
url,
|
|
76
37
|
};
|
|
38
|
+
const defineFn = compile.templateDocument(source);
|
|
77
39
|
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
const defineTemplateFn = compile.templateDocument(bodySource, {
|
|
81
|
-
scopeCaching,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Determine the result of the template
|
|
85
|
-
let result;
|
|
86
|
-
if (frontSource) {
|
|
87
|
-
// Result is the evaluated front source
|
|
88
|
-
const frontFn = compile.expression(frontSource, {
|
|
89
|
-
macros: {
|
|
90
|
-
"@template": defineTemplateFn.code,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
result = await frontFn.call(parent);
|
|
94
|
-
} else {
|
|
95
|
-
const templateFn = await defineTemplateFn.call(extendedParent);
|
|
96
|
-
if (frontData) {
|
|
97
|
-
// Result is a function that adds the front data to the template result
|
|
98
|
-
result = async (input) => {
|
|
99
|
-
const text = await templateFn.call(extendedParent, input);
|
|
100
|
-
const object = {
|
|
101
|
-
...frontData,
|
|
102
|
-
"@text": text,
|
|
103
|
-
};
|
|
104
|
-
object[symbols.parent] = extendedParent;
|
|
105
|
-
return object;
|
|
106
|
-
};
|
|
107
|
-
} else {
|
|
108
|
-
// Result is a function that calls the body template
|
|
109
|
-
result = templateFn;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
40
|
+
// Invoke the definition to get back the template function
|
|
41
|
+
const result = await defineFn.call(parent);
|
|
112
42
|
|
|
113
43
|
const resultExtension = key ? extension.extname(key) : null;
|
|
114
44
|
if (resultExtension && Object.isExtensible(result)) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isOrigamiFrontMatter } from "@weborigami/language";
|
|
2
|
+
|
|
1
3
|
export default function parseFrontMatter(text) {
|
|
2
4
|
const regex =
|
|
3
5
|
/^(---\r?\n(?<frontText>[\s\S]*?\r?\n?)---\r?\n)(?<body>[\s\S]*$)/;
|
|
@@ -5,17 +7,10 @@ export default function parseFrontMatter(text) {
|
|
|
5
7
|
if (!match?.groups) {
|
|
6
8
|
return null;
|
|
7
9
|
}
|
|
8
|
-
const isOrigami =
|
|
10
|
+
const isOrigami = isOrigamiFrontMatter(match.groups.frontText);
|
|
9
11
|
return {
|
|
10
12
|
body: match.groups.body,
|
|
11
13
|
frontText: match.groups.frontText,
|
|
12
14
|
isOrigami,
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
function detectOrigami(text) {
|
|
17
|
-
// Find first character that's not whitespace, alphanumeric, or underscore
|
|
18
|
-
const first = text.match(/[^A-Za-z0-9_ \t\n\r]/)?.[0];
|
|
19
|
-
const origamiMarkers = ["(", ".", "/", "{"];
|
|
20
|
-
return origamiMarkers.includes(first);
|
|
21
|
-
}
|
package/src/text/inline.js
CHANGED
|
@@ -43,14 +43,18 @@ export default async function inline(input) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// @ts-ignore
|
|
46
|
-
|
|
46
|
+
let result = await oridocumentHandler.unpack(input, {
|
|
47
47
|
parent: extendedParent,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (result instanceof Function) {
|
|
51
|
+
const text = await result();
|
|
52
|
+
if (inputIsDocument) {
|
|
53
|
+
return documentObject(text, input);
|
|
54
|
+
} else {
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
52
58
|
|
|
53
|
-
return
|
|
54
|
-
? documentObject(templateResult, inputData)
|
|
55
|
-
: templateResult;
|
|
59
|
+
return result;
|
|
56
60
|
}
|
package/src/text/mdHtml.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extension, isUnpackable } from "@weborigami/async-tree";
|
|
2
2
|
import highlight from "highlight.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Marked } from "marked";
|
|
4
4
|
import { gfmHeadingId as markedGfmHeadingId } from "marked-gfm-heading-id";
|
|
5
5
|
import { markedHighlight } from "marked-highlight";
|
|
6
6
|
import { markedSmartypants } from "marked-smartypants";
|
|
@@ -10,6 +10,8 @@ import origamiHighlightDefinition from "./origamiHighlightDefinition.js";
|
|
|
10
10
|
|
|
11
11
|
highlight.registerLanguage("ori", origamiHighlightDefinition);
|
|
12
12
|
|
|
13
|
+
// Create our own marked instance so we don't interfere with the global one
|
|
14
|
+
const marked = new Marked();
|
|
13
15
|
marked.use(
|
|
14
16
|
// @ts-ignore
|
|
15
17
|
markedGfmHeadingId(),
|
|
@@ -24,8 +26,6 @@ marked.use(
|
|
|
24
26
|
markedSmartypants(),
|
|
25
27
|
{
|
|
26
28
|
gfm: true, // Use GitHub-flavored markdown.
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
mangle: false,
|
|
29
29
|
}
|
|
30
30
|
);
|
|
31
31
|
|
|
@@ -52,7 +52,7 @@ export default async function mdHtml(input) {
|
|
|
52
52
|
if (markdown === null) {
|
|
53
53
|
throw new Error("mdHtml: The provided input couldn't be treated as text.");
|
|
54
54
|
}
|
|
55
|
-
const html = marked(markdown);
|
|
55
|
+
const html = marked.parse(markdown);
|
|
56
56
|
return inputIsDocument ? documentObject(html, input) : html;
|
|
57
57
|
}
|
|
58
58
|
|