@longform/longform 0.0.1
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 +21 -0
- package/README.md +52 -0
- package/dist/longform.d.ts +67 -0
- package/dist/longform.js +398 -0
- package/dist/longform.js.gz +0 -0
- package/dist/longform.js.map +7 -0
- package/dist/longform.min.js +5 -0
- package/dist/longform.min.js.gz +0 -0
- package/dist/longform.min.js.map +7 -0
- package/lib/longform.test.ts +287 -0
- package/lib/longform.ts +583 -0
- package/lib/types.ts +70 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Matthew Quinn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Longform
|
|
2
|
+
|
|
3
|
+
<b class=keyword>Longform</b> is an easy to read markup and templating
|
|
4
|
+
language that outputs to <b class=keyword>HTML</b> and <b class=keyword>XML</b>.
|
|
5
|
+
A longform document can be parsed to a complete document in the output format
|
|
6
|
+
or as fragments to be used by a application as a source of markup when generating a
|
|
7
|
+
document, or when manipulating DOM in a browser environment.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
This repo contains the Longform language specification and a light weight Longform
|
|
11
|
+
parser implemented for server rendering of HTML or XML documents and client side
|
|
12
|
+
templating if required. Both the Longform language and parser are a work in progress.
|
|
13
|
+
You can view more on what language features are currently supported in the Github
|
|
14
|
+
milestones.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Read more about the Longform language in the <a href="https://occultist-dev.github.io/longform">Longform Markup Language document</a>.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
npm install @longform/longform
|
|
24
|
+
deno install jsr:@longform/longform
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
const markup = `
|
|
31
|
+
@doctype:: html
|
|
32
|
+
html::
|
|
33
|
+
head::
|
|
34
|
+
title:: Example Longform
|
|
35
|
+
body::
|
|
36
|
+
h1:: Example Longform
|
|
37
|
+
|
|
38
|
+
#fragment1
|
|
39
|
+
div::
|
|
40
|
+
p::
|
|
41
|
+
This is a Longform fragment referencable by it's identifier.
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const fragments = longform(markup);
|
|
45
|
+
|
|
46
|
+
// outputs the root fragment as HTML
|
|
47
|
+
console.log(fragments.root);
|
|
48
|
+
|
|
49
|
+
// outputs fragment1 as HTML
|
|
50
|
+
console.log(fragments.fragment1.output);
|
|
51
|
+
```
|
|
52
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
declare module "types" {
|
|
2
|
+
export type WorkingElement = {
|
|
3
|
+
indent: number;
|
|
4
|
+
key?: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
tag?: string;
|
|
7
|
+
class?: string;
|
|
8
|
+
attrs: Record<string, string | null>;
|
|
9
|
+
text?: string;
|
|
10
|
+
html: string;
|
|
11
|
+
};
|
|
12
|
+
export type ChunkType = 'parsed' | 'ref' | 'scope';
|
|
13
|
+
export type WorkingChunk = {
|
|
14
|
+
type: ChunkType;
|
|
15
|
+
html: string;
|
|
16
|
+
els: WorkingElement[];
|
|
17
|
+
};
|
|
18
|
+
export type WorkingFragmentType = 'root' | 'embed' | 'bare' | 'range' | 'text' | 'template';
|
|
19
|
+
export type FragmentType = 'embed' | 'bare' | 'range' | 'text';
|
|
20
|
+
export type FragmentRef = {
|
|
21
|
+
id: string;
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
};
|
|
25
|
+
export type WorkingFragment = {
|
|
26
|
+
id?: string;
|
|
27
|
+
template: boolean;
|
|
28
|
+
type: WorkingFragmentType;
|
|
29
|
+
html: string;
|
|
30
|
+
refs: FragmentRef[];
|
|
31
|
+
chunks: WorkingChunk[];
|
|
32
|
+
els: WorkingElement[];
|
|
33
|
+
};
|
|
34
|
+
export type Fragment = {
|
|
35
|
+
id: string;
|
|
36
|
+
selector: string;
|
|
37
|
+
type: FragmentType;
|
|
38
|
+
html: string;
|
|
39
|
+
};
|
|
40
|
+
export type ParsedResult = {
|
|
41
|
+
root: string | null;
|
|
42
|
+
selector: string | null;
|
|
43
|
+
fragments: Record<string, Fragment>;
|
|
44
|
+
templates: Record<string, string>;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
declare module "longform" {
|
|
48
|
+
import type { FragmentType, ParsedResult, Fragment } from "types";
|
|
49
|
+
export type { FragmentType, Fragment, ParsedResult };
|
|
50
|
+
/**
|
|
51
|
+
* Parses a longform document into a object containing the root and fragments
|
|
52
|
+
* in the output format.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} doc - The longform document to parse.
|
|
55
|
+
* @returns {ParsedResult}
|
|
56
|
+
*/
|
|
57
|
+
export function longform(doc: string, debug?: (...d: unknown[]) => void): ParsedResult;
|
|
58
|
+
/**
|
|
59
|
+
* Processes a client side Longform template to HTML fragment string.
|
|
60
|
+
*
|
|
61
|
+
* @param fragment - The fragment identifier.
|
|
62
|
+
* @param args - A record of template arguments.
|
|
63
|
+
* @param getFragment - A function which returns an already processed fragment's HTML string.
|
|
64
|
+
* @returns The processed template.
|
|
65
|
+
*/
|
|
66
|
+
export function processTemplate(template: string, args: Record<string, string | number>, getFragment: (fragment: string) => string | undefined): string | undefined;
|
|
67
|
+
}
|
package/dist/longform.js
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
const sniffTestRe = /^(?:(?:(--).*)|(?: *(@|#).*)|(?: *[\w\-]+(?::[\w\-]+)?(?:[#.[][^\n]+)?(::).*)|(?: +([\["]).*)|(\ \ .*))$/gmi, element1 = /((?:\ \ )+)? ?([\w\-]+(?::[\w\-]+)?)([#\.\[][^\n]*)?::(?: ({{?|[^\n]+))?/gmi, directive1 = /((?:\ \ )+)? ?@([\w][\w\-]+)(?::: ?([^\n]+)?)?/gmi, attribute1 = /((?:\ \ )+)\[(\w[\w-]*(?::\w[\w-]*)?)(?:=([^\n]+))?\]/, preformattedClose = /[ \t]*}}?[ \t]*/, id1 = /((?:\ \ )+)?#(#)?([\w\-]+)(?: ([\["]))?/gmi, idnt1 = /^(\ \ )+/, text1 = /^((?:\ \ )+)([^ \n][^\n]*)$/i, paramsRe = /(?:(#|\.)([^#.\[\n]+)|(?:\[(\w[\w\-]*(?::\w[\w\-]*)?)(?:=([^\n\]]+))?\]))/g, refRe = /#\[([\w\-]+)\]/g, escapeRe = /([&<>"'#\[\]{}])/g, templateLinesRe = /^(\ \ )?([^\n]*)$/gmi, voids = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wrb"]);
|
|
2
|
+
let m1, m2, m3;
|
|
3
|
+
const entities = {
|
|
4
|
+
"&": "&",
|
|
5
|
+
"<": "<",
|
|
6
|
+
">": ">",
|
|
7
|
+
'"': """,
|
|
8
|
+
"'": "'"
|
|
9
|
+
// '#': '#',
|
|
10
|
+
// '[': '&lbrak;',
|
|
11
|
+
// ']': '&rbrak;',
|
|
12
|
+
// '{': '}',
|
|
13
|
+
// '}': '{',
|
|
14
|
+
};
|
|
15
|
+
function escape(value) {
|
|
16
|
+
return value.replace(escapeRe, (match) => {
|
|
17
|
+
var _a;
|
|
18
|
+
return (_a = entities[match]) != null ? _a : match;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function makeElement(indent = 0) {
|
|
22
|
+
return {
|
|
23
|
+
indent,
|
|
24
|
+
html: "",
|
|
25
|
+
attrs: {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function makeChunk(type = "parsed") {
|
|
29
|
+
return {
|
|
30
|
+
type,
|
|
31
|
+
html: "",
|
|
32
|
+
els: []
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function makeFragment(type = "bare") {
|
|
36
|
+
return {
|
|
37
|
+
type,
|
|
38
|
+
html: "",
|
|
39
|
+
template: false,
|
|
40
|
+
els: [],
|
|
41
|
+
chunks: [],
|
|
42
|
+
refs: []
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function longform(doc, debug = () => {
|
|
46
|
+
}) {
|
|
47
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
48
|
+
let skipping = false, textIndent = null, verbatimSerialize = true, verbatimIndent = null, verbatimFirst = false, element = makeElement(), chunk = makeChunk(), fragment = makeFragment(), root = null;
|
|
49
|
+
const claimed = /* @__PURE__ */ new Set(), parsed = /* @__PURE__ */ new Map(), output = /* @__PURE__ */ Object.create(null);
|
|
50
|
+
output.fragments = /* @__PURE__ */ Object.create(null);
|
|
51
|
+
output.templates = /* @__PURE__ */ Object.create(null);
|
|
52
|
+
function applyIndent(targetIndent) {
|
|
53
|
+
if (element.tag != null) {
|
|
54
|
+
const root2 = fragment.type === "range" ? targetIndent < 2 : fragment.html === "";
|
|
55
|
+
fragment.html += `<${element.tag}`;
|
|
56
|
+
if (root2) {
|
|
57
|
+
if (fragment.type === "root") {
|
|
58
|
+
fragment.html += ` data-lf-root`;
|
|
59
|
+
} else if (fragment.type === "bare" || fragment.type === "range") {
|
|
60
|
+
fragment.html += ` data-lf="${fragment.id}"`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (element.id != null) {
|
|
64
|
+
fragment.html += ' id="' + element.id + '"';
|
|
65
|
+
}
|
|
66
|
+
if (element.class != null) {
|
|
67
|
+
fragment.html += ' class="' + element.class + '"';
|
|
68
|
+
}
|
|
69
|
+
for (const attr of Object.entries(element.attrs)) {
|
|
70
|
+
if (attr[1] == null) {
|
|
71
|
+
fragment.html += " " + attr[0];
|
|
72
|
+
} else {
|
|
73
|
+
fragment.html += ` ${attr[0]}="${attr[1]}"`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
fragment.html += ">";
|
|
77
|
+
if (!voids.has(element.tag) && element.text != null) {
|
|
78
|
+
fragment.html += element.text;
|
|
79
|
+
}
|
|
80
|
+
if (!voids.has(element.tag)) {
|
|
81
|
+
fragment.els.push(element);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (targetIndent <= element.indent) {
|
|
85
|
+
element = makeElement(targetIndent);
|
|
86
|
+
while (fragment.els.length !== 0 && (targetIndent == null || fragment.els[fragment.els.length - 1].indent !== targetIndent - 1)) {
|
|
87
|
+
const element2 = fragment.els.pop();
|
|
88
|
+
fragment.html += `</${element2 == null ? void 0 : element2.tag}>`;
|
|
89
|
+
}
|
|
90
|
+
if (targetIndent === 0) {
|
|
91
|
+
debug(0, "<", fragment.type, fragment.id);
|
|
92
|
+
if (fragment.template) {
|
|
93
|
+
output.templates[fragment.id] = fragment.html;
|
|
94
|
+
} else if (fragment.type === "root") {
|
|
95
|
+
root = fragment;
|
|
96
|
+
} else {
|
|
97
|
+
parsed.set(fragment.id, fragment);
|
|
98
|
+
}
|
|
99
|
+
fragment = makeFragment();
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
element = makeElement(targetIndent);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
while (m1 = sniffTestRe.exec(doc)) {
|
|
106
|
+
if (m1[1] === "--") {
|
|
107
|
+
continue;
|
|
108
|
+
} else if (fragment.template) {
|
|
109
|
+
fragment.html += m1[0];
|
|
110
|
+
}
|
|
111
|
+
if (verbatimIndent != null) {
|
|
112
|
+
idnt1.lastIndex = 0;
|
|
113
|
+
m2 = idnt1.exec(m1[0]);
|
|
114
|
+
const indent = m2 == null ? null : m2[0].length / 2;
|
|
115
|
+
if (m2 == null || indent <= verbatimIndent) {
|
|
116
|
+
fragment.html += "\n";
|
|
117
|
+
debug(indent, "}", m2 == null ? void 0 : m2[0]);
|
|
118
|
+
applyIndent(indent);
|
|
119
|
+
verbatimIndent = null;
|
|
120
|
+
verbatimFirst = false;
|
|
121
|
+
textIndent = indent;
|
|
122
|
+
if (preformattedClose.test(m1[0])) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
const line = m1[0].replace(" ".repeat(verbatimIndent + 1), "");
|
|
127
|
+
debug(indent, "{", line);
|
|
128
|
+
if (element.tag != null) {
|
|
129
|
+
applyIndent(indent);
|
|
130
|
+
}
|
|
131
|
+
if (verbatimFirst) {
|
|
132
|
+
verbatimFirst = false;
|
|
133
|
+
} else {
|
|
134
|
+
fragment.html += "\n";
|
|
135
|
+
}
|
|
136
|
+
if (verbatimSerialize) {
|
|
137
|
+
fragment.html += escape(line);
|
|
138
|
+
} else {
|
|
139
|
+
fragment.html += line;
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (m1[0].trim() === "") {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
switch ((_b = (_a = m1[2]) != null ? _a : m1[3]) != null ? _b : m1[4]) {
|
|
148
|
+
// deno-lint-ignore no-fallthrough
|
|
149
|
+
case "#": {
|
|
150
|
+
id1.lastIndex = 0;
|
|
151
|
+
m2 = id1.exec(m1[0]);
|
|
152
|
+
if (m2 != null) {
|
|
153
|
+
const indent = ((_d = (_c = m2[1]) == null ? void 0 : _c.length) != null ? _d : 0) / 2;
|
|
154
|
+
if (element.tag != null || textIndent != null) {
|
|
155
|
+
applyIndent(indent);
|
|
156
|
+
textIndent = null;
|
|
157
|
+
}
|
|
158
|
+
debug(indent, "id", m2[2], m2[3], m2[4]);
|
|
159
|
+
fragment.id = m2[3];
|
|
160
|
+
if (indent === 0) {
|
|
161
|
+
if (m2[4] == "[") {
|
|
162
|
+
fragment.type = "range";
|
|
163
|
+
} else if (m2[4] === '"') {
|
|
164
|
+
fragment.type = "text";
|
|
165
|
+
} else if (m2[2] != null) {
|
|
166
|
+
fragment.type = "bare";
|
|
167
|
+
} else {
|
|
168
|
+
fragment.type = "embed";
|
|
169
|
+
element.id = fragment.id;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
case "@":
|
|
176
|
+
case "[":
|
|
177
|
+
// deno-lint-ignore no-fallthrough
|
|
178
|
+
case "::": {
|
|
179
|
+
element1.lastIndex = 0;
|
|
180
|
+
m2 = ((_e = m1[2]) != null ? _e : m1[4] != null) ? null : element1.exec(m1[0]);
|
|
181
|
+
if (m2 != null) {
|
|
182
|
+
const indent = ((_g = (_f = m2[1]) == null ? void 0 : _f.length) != null ? _g : 0) / 2, tg = m2[2], ar = m2[3], pr = m2[4] === "{" || m2[4] === "{{";
|
|
183
|
+
const tx = pr ? null : m2[4];
|
|
184
|
+
debug(indent, "e", tg, pr, tx);
|
|
185
|
+
if (element.tag != null || element.indent > indent) {
|
|
186
|
+
applyIndent(indent);
|
|
187
|
+
}
|
|
188
|
+
element.indent = indent;
|
|
189
|
+
element.tag = tg;
|
|
190
|
+
textIndent = null;
|
|
191
|
+
if (indent === 0 && fragment.id == null) {
|
|
192
|
+
if (root != null) {
|
|
193
|
+
skipping = true;
|
|
194
|
+
} else {
|
|
195
|
+
fragment.type = "root";
|
|
196
|
+
root = fragment;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (ar != null) {
|
|
200
|
+
debug(indent, "a", ar);
|
|
201
|
+
while (m2 = paramsRe.exec(ar)) {
|
|
202
|
+
if (m2[1] === "#") {
|
|
203
|
+
element.id = m2[2];
|
|
204
|
+
} else if (m2[1] === ".") {
|
|
205
|
+
if (element.class == null) {
|
|
206
|
+
element.class = m2[2];
|
|
207
|
+
} else {
|
|
208
|
+
element.class += " " + m2[2];
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
if (m2[3] === "id") {
|
|
212
|
+
if (element.id == null) {
|
|
213
|
+
element.id = m2[4];
|
|
214
|
+
}
|
|
215
|
+
} else if (m2[3] === "class") {
|
|
216
|
+
if (element.class == null) {
|
|
217
|
+
element.class = m2[4];
|
|
218
|
+
} else {
|
|
219
|
+
element.class += " " + m2[4];
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
element.attrs[m2[3]] = m2[4];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!pr && tx != null) {
|
|
228
|
+
element.text = tx;
|
|
229
|
+
} else if (pr) {
|
|
230
|
+
verbatimFirst = true;
|
|
231
|
+
verbatimIndent = indent;
|
|
232
|
+
verbatimSerialize = m2[4] === "{";
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
attribute1.lastIndex = 0;
|
|
237
|
+
m2 = m1[2] != null ? null : attribute1.exec(m1[0]);
|
|
238
|
+
if (m2 != null && element.tag != null) {
|
|
239
|
+
debug("a", m2[2], m2[3]);
|
|
240
|
+
if (m2[2] === "id") {
|
|
241
|
+
if (element.id == null) {
|
|
242
|
+
element.id = m2[3].trim();
|
|
243
|
+
}
|
|
244
|
+
} else if (m2[2] === "class") {
|
|
245
|
+
if (element.class != null) {
|
|
246
|
+
element.class += " " + m2[3].trim();
|
|
247
|
+
} else {
|
|
248
|
+
element.class = m2[3].trim();
|
|
249
|
+
}
|
|
250
|
+
} else if (element.attrs[m2[2]] != null) {
|
|
251
|
+
element.attrs[m2[2]] += m2[3];
|
|
252
|
+
} else {
|
|
253
|
+
element.attrs[m2[2]] = m2[3];
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
directive1.lastIndex = 0;
|
|
258
|
+
m2 = m1[3] != null ? null : directive1.exec(m1[0]);
|
|
259
|
+
if (m2 != null) {
|
|
260
|
+
const indent = ((_i = (_h = m2[1]) == null ? void 0 : _h.length) != null ? _i : 0) / 2;
|
|
261
|
+
if (element.tag != null || textIndent != null) {
|
|
262
|
+
applyIndent(indent);
|
|
263
|
+
}
|
|
264
|
+
debug(indent, "d", m2[2], m2[3]);
|
|
265
|
+
switch (m2[2]) {
|
|
266
|
+
case "doctype": {
|
|
267
|
+
fragment.html += `<!doctype ${(_j = m2[3]) != null ? _j : "html"}>`;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case "xml": {
|
|
271
|
+
fragment.html += `<?xml ${(_k = m2[3]) != null ? _k : 'version="1.0" encoding="UTF-8"'}?>`;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case "template": {
|
|
275
|
+
let indented = false;
|
|
276
|
+
fragment.template = indent === 0;
|
|
277
|
+
templateLinesRe.lastIndex = sniffTestRe.lastIndex;
|
|
278
|
+
while (m2 = templateLinesRe.exec(doc)) {
|
|
279
|
+
if (m2[1] == null && !indented) {
|
|
280
|
+
id1.lastIndex = 0;
|
|
281
|
+
m3 = id1.exec(m2[0]);
|
|
282
|
+
fragment.id = m3[3];
|
|
283
|
+
fragment.html += m2[0];
|
|
284
|
+
} else if (m2[1] == null && indented) {
|
|
285
|
+
sniffTestRe.lastIndex = templateLinesRe.lastIndex - 1;
|
|
286
|
+
applyIndent(0);
|
|
287
|
+
break;
|
|
288
|
+
} else {
|
|
289
|
+
fragment.html += "\n" + m2[0];
|
|
290
|
+
}
|
|
291
|
+
indented = true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
default: {
|
|
299
|
+
m2 = text1.exec(m1[0]);
|
|
300
|
+
if (m2 == null) {
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
const indent = m2[1].length / 2;
|
|
304
|
+
const tx = m2[2].trim();
|
|
305
|
+
debug(indent, "t", m2[2]);
|
|
306
|
+
if (element.tag != null) {
|
|
307
|
+
applyIndent(indent);
|
|
308
|
+
fragment.html += tx;
|
|
309
|
+
} else if (fragment.type === "text" && fragment.html === "") {
|
|
310
|
+
fragment.html += tx;
|
|
311
|
+
} else {
|
|
312
|
+
fragment.html += " " + tx;
|
|
313
|
+
}
|
|
314
|
+
textIndent = indent;
|
|
315
|
+
while (m2 = refRe.exec(tx)) {
|
|
316
|
+
const start = fragment.html.length + m2.index - tx.length;
|
|
317
|
+
fragment.refs.push({
|
|
318
|
+
id: m2[1],
|
|
319
|
+
start,
|
|
320
|
+
end: start + m2[0].length
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
applyIndent(0);
|
|
328
|
+
const arr = Array.from(parsed.values());
|
|
329
|
+
function flatten(fragment2) {
|
|
330
|
+
for (let j = fragment2.refs.length - 1; j >= 0; j--) {
|
|
331
|
+
const ref = fragment2.refs[j];
|
|
332
|
+
if (claimed.has(ref.id) || !parsed.has(ref.id)) {
|
|
333
|
+
fragment2.html = fragment2.html.slice(0, ref.start) + fragment2.html.slice(ref.end);
|
|
334
|
+
} else {
|
|
335
|
+
const child = flatten(parsed.get(ref.id));
|
|
336
|
+
fragment2.html = fragment2.html.slice(0, ref.start) + child.html + fragment2.html.slice(ref.end);
|
|
337
|
+
if (child.type === "embed") {
|
|
338
|
+
claimed.add(child.id);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
fragment2.refs = [];
|
|
343
|
+
return fragment2;
|
|
344
|
+
}
|
|
345
|
+
for (let i = 0; i < parsed.size + 1; i++) {
|
|
346
|
+
let fragment2;
|
|
347
|
+
if (i === 0 && root == null) {
|
|
348
|
+
continue;
|
|
349
|
+
} else if (i === 0) {
|
|
350
|
+
fragment2 = root;
|
|
351
|
+
} else {
|
|
352
|
+
fragment2 = arr[i - 1];
|
|
353
|
+
}
|
|
354
|
+
if (fragment2.refs.length === 0) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
flatten(fragment2);
|
|
358
|
+
}
|
|
359
|
+
if ((root == null ? void 0 : root.html) != null) {
|
|
360
|
+
output.root = root.html;
|
|
361
|
+
output.selector = `[data-lf-root]`;
|
|
362
|
+
}
|
|
363
|
+
for (let i = 0; i < arr.length; i++) {
|
|
364
|
+
let selector;
|
|
365
|
+
const fragment2 = arr[i];
|
|
366
|
+
if (fragment2 == null || claimed.has(fragment2.id)) {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (fragment2.type === "embed") {
|
|
370
|
+
selector = `[id=${fragment2.id}]`;
|
|
371
|
+
} else if (fragment2.type === "bare") {
|
|
372
|
+
selector = `[data-lf=${fragment2.id}]`;
|
|
373
|
+
} else if (fragment2.type === "range") {
|
|
374
|
+
selector = `[data-lf=${fragment2.id}]`;
|
|
375
|
+
}
|
|
376
|
+
output.fragments[fragment2.id] = {
|
|
377
|
+
id: fragment2.id,
|
|
378
|
+
selector,
|
|
379
|
+
type: fragment2.type,
|
|
380
|
+
html: fragment2.html
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return output;
|
|
384
|
+
}
|
|
385
|
+
const templateRe = /(?:#{([\w][\w\-_]*)})|(?:#\[([\w][\w\-_]+)\])/g;
|
|
386
|
+
export function processTemplate(template, args, getFragment) {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
const lf = template.replace(templateRe, (_match, param, ref) => {
|
|
389
|
+
if (ref != null) {
|
|
390
|
+
const fragment = getFragment(ref);
|
|
391
|
+
if (fragment == null) return "";
|
|
392
|
+
return fragment;
|
|
393
|
+
}
|
|
394
|
+
return args[param] != null ? escape(args[param].toString()) : "";
|
|
395
|
+
});
|
|
396
|
+
return (_b = (_a = Object.values(longform(lf).fragments)[0]) == null ? void 0 : _a.html) != null ? _b : null;
|
|
397
|
+
}
|
|
398
|
+
//# sourceMappingURL=longform.js.map
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/longform.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ChunkType, FragmentType, ParsedResult, WorkingChunk, WorkingElement, WorkingFragment, Fragment } from \"./types.ts\";\n\nexport type {\n FragmentType,\n Fragment,\n ParsedResult\n};\n\nconst sniffTestRe = /^(?:(?:(--).*)|(?: *(@|#).*)|(?: *[\\w\\-]+(?::[\\w\\-]+)?(?:[#.[][^\\n]+)?(::).*)|(?: +([\\[\"]).*)|(\\ \\ .*))$/gmi\n , element1 = /((?:\\ \\ )+)? ?([\\w\\-]+(?::[\\w\\-]+)?)([#\\.\\[][^\\n]*)?::(?: ({{?|[^\\n]+))?/gmi\n , directive1 = /((?:\\ \\ )+)? ?@([\\w][\\w\\-]+)(?::: ?([^\\n]+)?)?/gmi\n , attribute1 = /((?:\\ \\ )+)\\[(\\w[\\w-]*(?::\\w[\\w-]*)?)(?:=([^\\n]+))?\\]/\n , preformattedClose = /[ \\t]*}}?[ \\t]*/\n , id1 = /((?:\\ \\ )+)?#(#)?([\\w\\-]+)(?: ([\\[\"]))?/gmi\n , idnt1 = /^(\\ \\ )+/\n , text1 = /^((?:\\ \\ )+)([^ \\n][^\\n]*)$/i\n , paramsRe = /(?:(#|\\.)([^#.\\[\\n]+)|(?:\\[(\\w[\\w\\-]*(?::\\w[\\w\\-]*)?)(?:=([^\\n\\]]+))?\\]))/g\n , refRe = /#\\[([\\w\\-]+)\\]/g\n , escapeRe = /([&<>\"'#\\[\\]{}])/g\n , templateLinesRe = /^(\\ \\ )?([^\\n]*)$/gmi\n , voids = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wrb']);\n\nlet m1: RegExpExecArray | null\n , m2: RegExpExecArray | null\n , m3: RegExpExecArray | null;\n\nconst entities = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n// '#': '#',\n// '[': '&lbrak;',\n// ']': '&rbrak;',\n// '{': '}',\n// '}': '{',\n};\n\nfunction escape(value: string): string {\n return value.replace(escapeRe, (match) => {\n return entities[match] ?? match;\n });\n}\n\nfunction makeElement(indent: number = 0): WorkingElement {\n return {\n indent,\n html: '',\n attrs: {},\n };\n}\n\nfunction makeChunk(type: ChunkType = 'parsed'): WorkingChunk {\n return {\n type,\n html: '',\n els: [],\n };\n}\n\nfunction makeFragment(type: FragmentType = 'bare'): WorkingFragment {\n return {\n type,\n html: '',\n template: false,\n els: [],\n chunks: [],\n refs: [],\n };\n}\n\n/**\n * Parses a longform document into a object containing the root and fragments\n * in the output format.\n *\n * @param {string} doc - The longform document to parse.\n * @returns {ParsedResult}\n */\nexport function longform(doc: string, debug: (...d: unknown[]) => void = () => {}): ParsedResult {\n let skipping: boolean = false\n , textIndent: number | null = null\n , verbatimSerialize: boolean = true\n , verbatimIndent: number | null = null\n , verbatimFirst: boolean = false\n , element: WorkingElement = makeElement()\n , chunk: WorkingChunk | null = makeChunk()\n , fragment: WorkingFragment = makeFragment()\n // the root fragment\n , root: WorkingFragment | null = null\n // ids of claimed fragments\n const claimed: Set<string> = new Set()\n // parsed fragments\n , parsed: Map<string, WorkingFragment> = new Map()\n , output: ParsedResult = Object.create(null);\n\n output.fragments = Object.create(null);\n output.templates = Object.create(null);\n \n \n /**\n * Closes any current in progress element definition\n * and creates a new working element.\n */\n function applyIndent(targetIndent: number) {\n if (element.tag != null) {\n const root = fragment.type === 'range'\n ? targetIndent < 2\n : fragment.html === ''\n ;\n\n fragment.html += `<${element.tag}`\n\n if (root) {\n if (fragment.type === 'root') {\n fragment.html += ` data-lf-root`;\n } else if (fragment.type === 'bare' || fragment.type === 'range') {\n fragment.html += ` data-lf=\"${fragment.id}\"`;\n }\n }\n\n if (element.id != null) {\n fragment.html += ' id=\"' + element.id + '\"';\n }\n\n if (element.class != null) {\n fragment.html += ' class=\"' + element.class + '\"';\n }\n\n for (const attr of Object.entries(element.attrs)) {\n if (attr[1] == null) {\n fragment.html += ' ' + attr[0]\n } else {\n fragment.html += ` ${attr[0]}=\"${attr[1]}\"`;\n }\n }\n\n fragment.html += '>';\n\n if (!voids.has(element.tag as string) && element.text != null) {\n fragment.html += element.text;\n }\n\n if (\n !voids.has(element.tag as string)\n ) {\n fragment.els.push(element);\n }\n }\n\n if (targetIndent <= element.indent) {\n element = makeElement(targetIndent);\n\n while (\n fragment.els.length !== 0 && (\n targetIndent == null ||\n fragment.els[fragment.els.length - 1].indent !== targetIndent - 1\n )\n ) {\n const element = fragment.els.pop();\n\n fragment.html += `</${element?.tag}>`;\n }\n\n if (targetIndent === 0) {\n debug(0, '<', fragment.type, fragment.id);\n if (fragment.template) {\n output.templates[fragment.id] = fragment.html;\n } else if (fragment.type === 'root') {\n root = fragment;\n } else {\n parsed.set(fragment.id, fragment);\n }\n\n fragment = makeFragment();\n }\n } else {\n element = makeElement(targetIndent)\n }\n }\n\n while ((m1 = sniffTestRe.exec(doc))) {\n if (m1[1] === '--') {\n continue;\n } else if (fragment.template) {\n fragment.html += m1[0];\n }\n\n // If this is a script tag or preformatted block\n // we want to retain the intended formatting less\n // the indent. Preformatting can apply to any element\n // by ending the declaration with `:: {`.\n if (verbatimIndent != null) {\n // inside a script or preformatted block\n idnt1.lastIndex = 0;\n m2 = idnt1.exec(m1[0]);\n const indent = m2 == null\n ? null\n : m2[0].length / 2;\n\n if (m2 == null || indent as number <= verbatimIndent) {\n fragment.html += '\\n';\n debug(indent, '}', m2?.[0]);\n\n applyIndent(indent);\n verbatimIndent = null;\n verbatimFirst = false;\n textIndent = indent;\n\n if (preformattedClose.test(m1[0])) {\n continue;\n }\n } else {\n const line = m1[0].replace(' '.repeat(verbatimIndent + 1), '');\n debug(indent, '{', line);\n\n if (element.tag != null) {\n applyIndent(indent as number);\n }\n\n if (verbatimFirst) {\n verbatimFirst = false;\n } else {\n fragment.html += '\\n';\n }\n \n if (verbatimSerialize) {\n fragment.html += escape(line);\n } else {\n fragment.html += line;\n }\n\n continue;\n }\n }\n\n if (m1[0].trim() === '') {\n continue;\n }\n\n switch (m1[2] ?? m1[3] ?? m1[4]) {\n // deno-lint-ignore no-fallthrough\n case '#': {\n id1.lastIndex = 0;\n m2 = id1.exec(m1[0]);\n\n if (m2 != null) {\n const indent = (m2[1]?.length ?? 0) / 2;\n\n if (element.tag != null || textIndent != null) {\n applyIndent(indent);\n textIndent = null;\n }\n\n debug(indent, 'id', m2[2], m2[3], m2[4]);\n\n fragment.id = m2[3];\n\n if (indent === 0) {\n if (m2[4] == '[') {\n fragment.type = 'range';\n } else if (m2[4] === '\"') {\n fragment.type = 'text';\n } else if (m2[2] != null) {\n fragment.type = 'bare';\n } else {\n fragment.type = 'embed';\n element.id = fragment.id;\n }\n }\n\n break;\n }\n }\n case '@':\n case '[':\n // deno-lint-ignore no-fallthrough\n case '::': {\n element1.lastIndex = 0;\n // fall through if m1[3] is a # or @\n m2 = m1[2] ?? m1[4] != null\n ? null\n : element1.exec(m1[0]);\n\n // if null then invalid element selector\n // allow the default text case to handle\n if (m2 != null) {\n const indent = (m2[1]?.length ?? 0) / 2\n , tg = m2[2]\n , ar = m2[3]\n , pr = m2[4] === '{' || m2[4] === '{{'\n const tx = pr ? null : m2[4]\n\n debug(indent, 'e', tg, pr, tx);\n\n if (\n element.tag != null ||\n element.indent > indent\n ) {\n applyIndent(indent);\n }\n\n element.indent = indent;\n element.tag = tg;\n\n textIndent = null;\n \n if (indent === 0 && fragment.id == null) {\n if (root != null) {\n skipping = true;\n } else {\n fragment.type = 'root';\n root = fragment;\n }\n }\n \n if (ar != null) {\n debug(indent, 'a', ar);\n while ((m2 = paramsRe.exec(ar))) {\n if (m2[1] === '#') {\n element.id = m2[2];\n } else if (m2[1] === '.') {\n if (element.class == null) {\n element.class = m2[2];\n } else {\n element.class += ' ' + m2[2];\n }\n } else {\n if (m2[3] === 'id') {\n if (element.id == null) {\n element.id = m2[4];\n }\n } else if (m2[3] === 'class') {\n if (element.class == null) {\n element.class = m2[4]\n } else {\n element.class += ' ' + m2[4]\n }\n } else {\n element.attrs[m2[3]] = m2[4];\n }\n }\n }\n }\n\n if (!pr && tx != null) {\n element.text = tx;\n } else if (pr) {\n verbatimFirst = true;\n verbatimIndent = indent;\n verbatimSerialize = m2[4] === '{';\n }\n\n break;\n }\n\n attribute1.lastIndex = 0;\n m2 = m1[2] != null\n ? null\n : attribute1.exec(m1[0]);\n\n if (m2 != null && element.tag != null) {\n debug('a', m2[2], m2[3]);\n\n if (m2[2] === 'id') {\n if (element.id == null) {\n element.id = m2[3].trim();\n }\n } else if (m2[2] === 'class') {\n if (element.class != null) {\n element.class += ' ' + m2[3].trim();\n } else {\n element.class = m2[3].trim();\n }\n } else if (element.attrs[m2[2]] != null) {\n element.attrs[m2[2]] += m2[3];\n } else {\n element.attrs[m2[2]] = m2[3];\n }\n\n break;\n }\n\n directive1.lastIndex = 0;\n m2 = m1[3] != null\n ? null \n : directive1.exec(m1[0]);\n\n if (m2 != null) {\n const indent = (m2[1]?.length ?? 0) / 2;\n\n if (element.tag != null || textIndent != null) {\n applyIndent(indent);\n }\n\n debug(indent, 'd', m2[2], m2[3]);\n\n switch (m2[2]) {\n case 'doctype': {\n fragment.html += `<!doctype ${m2[3] ?? 'html'}>`;\n break;\n }\n case 'xml': {\n fragment.html += `<?xml ${m2[3] ?? 'version=\"1.0\" encoding=\"UTF-8\"'}?>`;\n break;\n }\n case 'template': {\n let indented = false;\n fragment.template = indent === 0;\n\n templateLinesRe.lastIndex = sniffTestRe.lastIndex;\n while ((m2 = templateLinesRe.exec(doc))) {\n if (m2[1] == null && !indented) {\n id1.lastIndex = 0;\n m3 = id1.exec(m2[0]);\n\n fragment.id = m3[3];\n fragment.html += m2[0];\n } else if (m2[1] == null && indented) {\n sniffTestRe.lastIndex = templateLinesRe.lastIndex - 1;\n applyIndent(0)\n break;\n } else {\n fragment.html += '\\n' + m2[0];\n }\n indented = true;\n }\n }\n }\n\n break;\n }\n\n }\n default: {\n m2 = text1.exec(m1[0]) as RegExpExecArray;\n\n if (m2 == null) {\n break;\n }\n const indent = m2[1].length / 2;\n const tx = m2[2].trim();\n\n debug(indent, 't', m2[2]);\n\n if (element.tag != null) {\n applyIndent(indent);\n\n fragment.html += tx;\n } else if (fragment.type === 'text' && fragment.html === '') {\n fragment.html += tx;\n } else {\n fragment.html += ' ' + tx;\n }\n\n textIndent = indent;\n\n while ((m2 = refRe.exec(tx))) {\n const start = fragment.html.length + m2.index - tx.length;\n\n fragment.refs.push({\n id: m2[1],\n start,\n end: start + m2[0].length,\n });\n }\n\n break;\n }\n }\n }\n\n applyIndent(0);\n\n const arr = Array.from(parsed.values());\n\n function flatten(fragment: WorkingFragment): WorkingFragment {\n // work backwards so we don't change the html string length\n // for the later replacements\n for (let j = fragment.refs.length - 1; j >= 0; j--) {\n const ref = fragment.refs[j];\n\n if (claimed.has(ref.id) || !parsed.has(ref.id)) {\n fragment.html = fragment.html.slice(0, ref.start)\n + fragment.html.slice(ref.end)\n } else {\n const child = flatten(parsed.get(ref.id));\n\n fragment.html = fragment.html.slice(0, ref.start)\n + child.html\n + fragment.html.slice(ref.end);\n\n if (child.type === 'embed') {\n claimed.add(child.id)\n }\n }\n }\n\n fragment.refs = [];\n\n return fragment;\n }\n\n for (let i = 0; i < parsed.size + 1; i++) {\n let fragment: WorkingFragment;\n \n if (i === 0 && root == null) {\n continue;\n } else if (i === 0) {\n fragment = root;\n } else {\n fragment = arr[i - 1];\n }\n\n if (fragment.refs.length === 0) {\n continue;\n }\n\n flatten(fragment)\n }\n\n if (root?.html != null) {\n output.root = root.html;\n output.selector = `[data-lf-root]`;\n }\n\n for (let i = 0; i < arr.length; i++) {\n let selector: string;\n const fragment = arr[i];\n\n if (fragment == null || claimed.has(fragment.id)) {\n continue;\n }\n\n if (fragment.type === 'embed') {\n selector = `[id=${fragment.id}]`;\n } else if (fragment.type === 'bare') {\n selector = `[data-lf=${fragment.id}]`;\n } else if (fragment.type === 'range') {\n selector = `[data-lf=${fragment.id}]`;\n }\n\n output.fragments[fragment.id] = {\n id: fragment.id,\n selector,\n type: fragment.type as 'embed' | 'bare' | 'range',\n html: fragment.html,\n };\n }\n\n return output;\n}\n\n\nconst templateRe = /(?:#{([\\w][\\w\\-_]*)})|(?:#\\[([\\w][\\w\\-_]+)\\])/g;\n\n/**\n * Processes a client side Longform template to HTML fragment string.\n *\n * @param fragment - The fragment identifier.\n * @param args - A record of template arguments.\n * @param getFragment - A function which returns an already processed fragment's HTML string.\n * @returns The processed template.\n */\nexport function processTemplate(\n template: string,\n args: Record<string, string | number>,\n getFragment: (fragment: string) => string | undefined,\n): string | undefined {\n const lf = template.replace(templateRe, (_match, param, ref) => {\n if (ref != null) {\n const fragment = getFragment(ref);\n\n if (fragment == null) return '';\n\n return fragment;\n }\n \n return args[param] != null ? escape(args[param].toString()) : '';\n });\n\n return Object.values(longform(lf).fragments)[0]?.html ?? null;\n}\n"],
|
|
5
|
+
"mappings": "AAQA,MAAM,cAAc,gHAChB,WAAW,+EACX,aAAa,qDACb,aAAa,yDACb,o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D;",
|
|
6
|
+
"names": ["root", "element", "fragment"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const W=/^(?:(?:(--).*)|(?: *(@|#).*)|(?: *[\w\-]+(?::[\w\-]+)?(?:[#.[][^\n]+)?(::).*)|(?: +([\["]).*)|(\ \ .*))$/gmi,q=/((?:\ \ )+)? ?([\w\-]+(?::[\w\-]+)?)([#\.\[][^\n]*)?::(?: ({{?|[^\n]+))?/gmi,L=/((?:\ \ )+)? ?@([\w][\w\-]+)(?::: ?([^\n]+)?)?/gmi,U=/((?:\ \ )+)\[(\w[\w-]*(?::\w[\w-]*)?)(?:=([^\n]+))?\]/,K=/[ \t]*}}?[ \t]*/,y=/((?:\ \ )+)?#(#)?([\w\-]+)(?: ([\["]))?/gmi,B=/^(\ \ )+/,N=/^((?:\ \ )+)([^ \n][^\n]*)$/i,Q=/(?:(#|\.)([^#.\[\n]+)|(?:\[(\w[\w\-]*(?::\w[\w\-]*)?)(?:=([^\n\]]+))?\]))/g,V=/#\[([\w\-]+)\]/g,X=/([&<>"'#\[\]{}])/g,$=/^(\ \ )?([^\n]*)$/gmi,D=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wrb"]);let r,e,G;const Y={"&":"&","<":"<",">":">",'"':""","'":"'"};function H(u){return u.replace(X,a=>{var g;return(g=Y[a])!=null?g:a})}function E(u=0){return{indent:u,html:"",attrs:{}}}function Z(u="parsed"){return{type:u,html:"",els:[]}}function J(u="bare"){return{type:u,html:"",template:!1,els:[],chunks:[],refs:[]}}export function longform(u,a=()=>{}){var T,C,I,j,A,O,S,P,_,z,M;let g=!1,f=null,p=!0,c=null,x=!1,n=E(),b=Z(),l=J(),m=null;const w=new Set,k=new Map,h=Object.create(null);h.fragments=Object.create(null),h.templates=Object.create(null);function o(t){if(n.tag!=null){const i=l.type==="range"?t<2:l.html==="";l.html+=`<${n.tag}`,i&&(l.type==="root"?l.html+=" data-lf-root":(l.type==="bare"||l.type==="range")&&(l.html+=` data-lf="${l.id}"`)),n.id!=null&&(l.html+=' id="'+n.id+'"'),n.class!=null&&(l.html+=' class="'+n.class+'"');for(const s of Object.entries(n.attrs))s[1]==null?l.html+=" "+s[0]:l.html+=` ${s[0]}="${s[1]}"`;l.html+=">",!D.has(n.tag)&&n.text!=null&&(l.html+=n.text),D.has(n.tag)||l.els.push(n)}if(t<=n.indent){for(n=E(t);l.els.length!==0&&(t==null||l.els[l.els.length-1].indent!==t-1);){const i=l.els.pop();l.html+=`</${i==null?void 0:i.tag}>`}t===0&&(a(0,"<",l.type,l.id),l.template?h.templates[l.id]=l.html:l.type==="root"?m=l:k.set(l.id,l),l=J())}else n=E(t)}for(;r=W.exec(u);)if(r[1]!=="--"){if(l.template&&(l.html+=r[0]),c!=null){B.lastIndex=0,e=B.exec(r[0]);const t=e==null?null:e[0].length/2;if(e==null||t<=c){if(l.html+=`
|
|
2
|
+
`,a(t,"}",e==null?void 0:e[0]),o(t),c=null,x=!1,f=t,K.test(r[0]))continue}else{const i=r[0].replace(" ".repeat(c+1),"");a(t,"{",i),n.tag!=null&&o(t),x?x=!1:l.html+=`
|
|
3
|
+
`,p?l.html+=H(i):l.html+=i;continue}}if(r[0].trim()!=="")switch((C=(T=r[2])!=null?T:r[3])!=null?C:r[4]){case"#":if(y.lastIndex=0,e=y.exec(r[0]),e!=null){const t=((j=(I=e[1])==null?void 0:I.length)!=null?j:0)/2;(n.tag!=null||f!=null)&&(o(t),f=null),a(t,"id",e[2],e[3],e[4]),l.id=e[3],t===0&&(e[4]=="["?l.type="range":e[4]==='"'?l.type="text":e[2]!=null?l.type="bare":(l.type="embed",n.id=l.id));break}case"@":case"[":case"::":{if(q.lastIndex=0,e=((A=r[2])!=null?A:r[4]!=null)?null:q.exec(r[0]),e!=null){const t=((S=(O=e[1])==null?void 0:O.length)!=null?S:0)/2,i=e[2],s=e[3],d=e[4]==="{"||e[4]==="{{",R=d?null:e[4];if(a(t,"e",i,d,R),(n.tag!=null||n.indent>t)&&o(t),n.indent=t,n.tag=i,f=null,t===0&&l.id==null&&(m!=null?g=!0:(l.type="root",m=l)),s!=null)for(a(t,"a",s);e=Q.exec(s);)e[1]==="#"?n.id=e[2]:e[1]==="."?n.class==null?n.class=e[2]:n.class+=" "+e[2]:e[3]==="id"?n.id==null&&(n.id=e[4]):e[3]==="class"?n.class==null?n.class=e[4]:n.class+=" "+e[4]:n.attrs[e[3]]=e[4];!d&&R!=null?n.text=R:d&&(x=!0,c=t,p=e[4]==="{");break}if(U.lastIndex=0,e=r[2]!=null?null:U.exec(r[0]),e!=null&&n.tag!=null){a("a",e[2],e[3]),e[2]==="id"?n.id==null&&(n.id=e[3].trim()):e[2]==="class"?n.class!=null?n.class+=" "+e[3].trim():n.class=e[3].trim():n.attrs[e[2]]!=null?n.attrs[e[2]]+=e[3]:n.attrs[e[2]]=e[3];break}if(L.lastIndex=0,e=r[3]!=null?null:L.exec(r[0]),e!=null){const t=((_=(P=e[1])==null?void 0:P.length)!=null?_:0)/2;switch((n.tag!=null||f!=null)&&o(t),a(t,"d",e[2],e[3]),e[2]){case"doctype":{l.html+=`<!doctype ${(z=e[3])!=null?z:"html"}>`;break}case"xml":{l.html+=`<?xml ${(M=e[3])!=null?M:'version="1.0" encoding="UTF-8"'}?>`;break}case"template":{let i=!1;for(l.template=t===0,$.lastIndex=W.lastIndex;e=$.exec(u);){if(e[1]==null&&!i)y.lastIndex=0,G=y.exec(e[0]),l.id=G[3],l.html+=e[0];else if(e[1]==null&&i){W.lastIndex=$.lastIndex-1,o(0);break}else l.html+=`
|
|
4
|
+
`+e[0];i=!0}}}break}}default:{if(e=N.exec(r[0]),e==null)break;const t=e[1].length/2,i=e[2].trim();for(a(t,"t",e[2]),n.tag!=null?(o(t),l.html+=i):l.type==="text"&&l.html===""?l.html+=i:l.html+=" "+i,f=t;e=V.exec(i);){const s=l.html.length+e.index-i.length;l.refs.push({id:e[1],start:s,end:s+e[0].length})}break}}}o(0);const F=Array.from(k.values());function v(t){for(let i=t.refs.length-1;i>=0;i--){const s=t.refs[i];if(w.has(s.id)||!k.has(s.id))t.html=t.html.slice(0,s.start)+t.html.slice(s.end);else{const d=v(k.get(s.id));t.html=t.html.slice(0,s.start)+d.html+t.html.slice(s.end),d.type==="embed"&&w.add(d.id)}}return t.refs=[],t}for(let t=0;t<k.size+1;t++){let i;t===0&&m==null||(t===0?i=m:i=F[t-1],i.refs.length!==0&&v(i))}(m==null?void 0:m.html)!=null&&(h.root=m.html,h.selector="[data-lf-root]");for(let t=0;t<F.length;t++){let i;const s=F[t];s==null||w.has(s.id)||(s.type==="embed"?i=`[id=${s.id}]`:s.type==="bare"?i=`[data-lf=${s.id}]`:s.type==="range"&&(i=`[data-lf=${s.id}]`),h.fragments[s.id]={id:s.id,selector:i,type:s.type,html:s.html})}return h}const ee=/(?:#{([\w][\w\-_]*)})|(?:#\[([\w][\w\-_]+)\])/g;export function processTemplate(u,a,g){var p,c;const f=u.replace(ee,(x,n,b)=>{if(b!=null){const l=g(b);return l==null?"":l}return a[n]!=null?H(a[n].toString()):""});return(c=(p=Object.values(longform(f).fragments)[0])==null?void 0:p.html)!=null?c:null}
|
|
5
|
+
//# sourceMappingURL=longform.min.js.map
|
|
Binary file
|