@jxsuite/parser 1.8.2 → 2.0.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 +1 -1
- package/README.md +33 -0
- package/dist/content-loader.js +34124 -62
- package/dist/content.js +119 -3
- package/dist/markdown.js +1113 -91
- package/dist/serialize.js +177 -0
- package/package.json +7 -7
- package/schemas/project.fragment.schema.json +138 -6
- package/src/Content.class.json +6 -3
- package/src/Markdown.class.json +14 -3
- package/src/alerts.ts +257 -0
- package/src/content-links.ts +343 -0
- package/src/content-loader.ts +863 -75
- package/src/content-routes.ts +369 -0
- package/src/content-rules.ts +474 -0
- package/src/content.ts +49 -13
- package/src/grammars/caddyfile.ts +86 -0
- package/src/highlight.ts +49 -9
- package/src/inert.ts +101 -0
- package/src/markdown.ts +43 -17
- package/src/md.ts +29 -6
- package/src/transpile.ts +60 -4
- package/src/types.ts +17 -0
- package/src/walk.ts +97 -0
package/dist/content.js
CHANGED
|
@@ -1,3 +1,102 @@
|
|
|
1
|
+
// ../../packages/schema/src/locale.ts
|
|
2
|
+
var RTL_SCRIPTS = new Set([
|
|
3
|
+
"Adlm",
|
|
4
|
+
"Arab",
|
|
5
|
+
"Aran",
|
|
6
|
+
"Armi",
|
|
7
|
+
"Avst",
|
|
8
|
+
"Cprt",
|
|
9
|
+
"Egyd",
|
|
10
|
+
"Egyh",
|
|
11
|
+
"Elym",
|
|
12
|
+
"Gara",
|
|
13
|
+
"Hatr",
|
|
14
|
+
"Hebr",
|
|
15
|
+
"Hluw",
|
|
16
|
+
"Hung",
|
|
17
|
+
"Khar",
|
|
18
|
+
"Lydi",
|
|
19
|
+
"Mand",
|
|
20
|
+
"Mani",
|
|
21
|
+
"Mend",
|
|
22
|
+
"Merc",
|
|
23
|
+
"Mero",
|
|
24
|
+
"Narb",
|
|
25
|
+
"Nbat",
|
|
26
|
+
"Nkoo",
|
|
27
|
+
"Orkh",
|
|
28
|
+
"Palm",
|
|
29
|
+
"Phli",
|
|
30
|
+
"Phlp",
|
|
31
|
+
"Phnx",
|
|
32
|
+
"Prti",
|
|
33
|
+
"Rohg",
|
|
34
|
+
"Samr",
|
|
35
|
+
"Sarb",
|
|
36
|
+
"Sogd",
|
|
37
|
+
"Sogo",
|
|
38
|
+
"Syrc",
|
|
39
|
+
"Thaa",
|
|
40
|
+
"Todr",
|
|
41
|
+
"Yezi"
|
|
42
|
+
]);
|
|
43
|
+
function canonicalizeLocale(tag) {
|
|
44
|
+
if (typeof tag !== "string" || tag.trim() === "") {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return new Intl.Locale(tag.trim()).toString();
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var DEFAULT_ROUTING = "prefix-except-default";
|
|
54
|
+
function resolveI18n(projectConfig) {
|
|
55
|
+
const raw = projectConfig.i18n;
|
|
56
|
+
const errors = [];
|
|
57
|
+
if (!raw || typeof raw !== "object") {
|
|
58
|
+
return { errors, i18n: null };
|
|
59
|
+
}
|
|
60
|
+
const declared = Array.isArray(raw.locales) ? raw.locales : [];
|
|
61
|
+
const locales = [];
|
|
62
|
+
for (const tag of declared) {
|
|
63
|
+
const canonical = canonicalizeLocale(tag);
|
|
64
|
+
if (canonical === null) {
|
|
65
|
+
errors.push(`i18n.locales: "${String(tag)}" is not a well-formed BCP 47 language tag.`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!locales.includes(canonical)) {
|
|
69
|
+
locales.push(canonical);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const defaultLocale = canonicalizeLocale(raw.defaultLocale) ?? locales[0] ?? null;
|
|
73
|
+
if (raw.defaultLocale !== undefined && canonicalizeLocale(raw.defaultLocale) === null) {
|
|
74
|
+
errors.push(`i18n.defaultLocale: "${String(raw.defaultLocale)}" is not a well-formed BCP 47 language tag.`);
|
|
75
|
+
}
|
|
76
|
+
if (defaultLocale === null) {
|
|
77
|
+
errors.push("i18n is declared with no usable locale — set `defaultLocale` or `locales`.");
|
|
78
|
+
return { errors, i18n: null };
|
|
79
|
+
}
|
|
80
|
+
if (!locales.includes(defaultLocale)) {
|
|
81
|
+
locales.unshift(defaultLocale);
|
|
82
|
+
}
|
|
83
|
+
const routing = raw.routing === "prefix-always" || raw.routing === "prefix-except-default" ? raw.routing : DEFAULT_ROUTING;
|
|
84
|
+
return { errors, i18n: { defaultLocale, locales, routing } };
|
|
85
|
+
}
|
|
86
|
+
function localeUrlPrefix(locale, i18n) {
|
|
87
|
+
if (i18n === null) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
const canonical = canonicalizeLocale(locale);
|
|
91
|
+
if (canonical === null || !i18n.locales.includes(canonical)) {
|
|
92
|
+
return "";
|
|
93
|
+
}
|
|
94
|
+
if (canonical === i18n.defaultLocale && i18n.routing === "prefix-except-default") {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
return `/${canonical.toLowerCase()}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
1
100
|
// src/dates.ts
|
|
2
101
|
var DATE_FORMATS = ["date", "date-time"];
|
|
3
102
|
function isDateFormat(format) {
|
|
@@ -209,12 +308,32 @@ class ContentEntry {
|
|
|
209
308
|
constructor(config) {
|
|
210
309
|
this.config = config;
|
|
211
310
|
}
|
|
311
|
+
#pageRoute() {
|
|
312
|
+
const { _project, _document } = this.config;
|
|
313
|
+
let path = _document?.route?.urlPattern;
|
|
314
|
+
if (typeof path !== "string") {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const { i18n } = resolveI18n(_project?.config ?? {});
|
|
318
|
+
const prefix = localeUrlPrefix(_document?.route?.locale, i18n);
|
|
319
|
+
if (prefix !== "" && (path === prefix || path.startsWith(`${prefix}/`))) {
|
|
320
|
+
path = path.slice(prefix.length);
|
|
321
|
+
}
|
|
322
|
+
return path.replace(/\/+$/, "") || "/";
|
|
323
|
+
}
|
|
212
324
|
resolve() {
|
|
213
325
|
const { contentType, id, field, _project, _document } = this.config;
|
|
214
326
|
const entries = _project?.content?.get(contentType ?? "");
|
|
215
327
|
if (!entries) {
|
|
216
328
|
return null;
|
|
217
329
|
}
|
|
330
|
+
const wanted = _document?.route?.locale;
|
|
331
|
+
const localized = entries.some((e) => e._meta?.locale !== undefined);
|
|
332
|
+
const scoped = localized && typeof wanted === "string" ? entries.filter((e) => e._meta?.locale === wanted) : entries;
|
|
333
|
+
if (id === undefined && field === undefined) {
|
|
334
|
+
const route = this.#pageRoute();
|
|
335
|
+
return route === undefined ? null : scoped.find((e) => e._meta?.route === route) ?? null;
|
|
336
|
+
}
|
|
218
337
|
let resolvedId = id;
|
|
219
338
|
if (resolvedId && typeof resolvedId === "object" && resolvedId.$ref?.startsWith("#/$params/")) {
|
|
220
339
|
const paramName = resolvedId.$ref.replace("#/$params/", "");
|
|
@@ -223,9 +342,6 @@ class ContentEntry {
|
|
|
223
342
|
if (!resolvedId) {
|
|
224
343
|
return null;
|
|
225
344
|
}
|
|
226
|
-
const wanted = _document?.route?.locale;
|
|
227
|
-
const localized = entries.some((e) => e._meta?.locale !== undefined);
|
|
228
|
-
const scoped = localized && typeof wanted === "string" ? entries.filter((e) => e._meta?.locale === wanted) : entries;
|
|
229
345
|
if (field && field !== "id") {
|
|
230
346
|
return scoped.find((e) => e.data[field] === resolvedId) ?? null;
|
|
231
347
|
}
|