@intlayer/core 9.4.4 → 9.5.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/README.md +0 -2
- package/dist/cjs/dictionaryManipulator/qualifiedDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -8
- package/dist/cjs/interpreter/getPlural.cjs.map +1 -1
- package/dist/cjs/markdown/compiler.cjs +437 -209
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/markdown/constants.cjs +32 -50
- package/dist/cjs/markdown/constants.cjs.map +1 -1
- package/dist/cjs/markdown/elementScanner.cjs +191 -0
- package/dist/cjs/markdown/elementScanner.cjs.map +1 -0
- package/dist/cjs/markdown/index.cjs +5 -8
- package/dist/cjs/markdown/parser.cjs +90 -48
- package/dist/cjs/markdown/parser.cjs.map +1 -1
- package/dist/cjs/markdown/renderer.cjs +14 -11
- package/dist/cjs/markdown/renderer.cjs.map +1 -1
- package/dist/cjs/markdown/utils.cjs +123 -34
- package/dist/cjs/markdown/utils.cjs.map +1 -1
- package/dist/esm/dictionaryManipulator/qualifiedDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/interpreter/getPlural.mjs.map +1 -1
- package/dist/esm/markdown/compiler.mjs +438 -211
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/markdown/constants.mjs +29 -43
- package/dist/esm/markdown/constants.mjs.map +1 -1
- package/dist/esm/markdown/elementScanner.mjs +183 -0
- package/dist/esm/markdown/elementScanner.mjs.map +1 -0
- package/dist/esm/markdown/index.mjs +3 -3
- package/dist/esm/markdown/parser.mjs +90 -48
- package/dist/esm/markdown/parser.mjs.map +1 -1
- package/dist/esm/markdown/renderer.mjs +14 -11
- package/dist/esm/markdown/renderer.mjs.map +1 -1
- package/dist/esm/markdown/utils.mjs +124 -35
- package/dist/esm/markdown/utils.mjs.map +1 -1
- package/dist/types/dictionaryManipulator/qualifiedDictionary.d.ts +3 -3
- package/dist/types/dictionaryManipulator/qualifiedDictionary.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/interpreter/getPlural.d.ts +3 -3
- package/dist/types/interpreter/getPlural.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +43 -0
- package/dist/types/markdown/compiler.d.ts.map +1 -1
- package/dist/types/markdown/constants.d.ts +26 -17
- package/dist/types/markdown/constants.d.ts.map +1 -1
- package/dist/types/markdown/elementScanner.d.ts +14 -0
- package/dist/types/markdown/elementScanner.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +4 -4
- package/dist/types/markdown/parser.d.ts +0 -5
- package/dist/types/markdown/parser.d.ts.map +1 -1
- package/dist/types/markdown/renderer.d.ts +0 -4
- package/dist/types/markdown/renderer.d.ts.map +1 -1
- package/dist/types/markdown/types.d.ts +13 -0
- package/dist/types/markdown/types.d.ts.map +1 -1
- package/dist/types/markdown/utils.d.ts +7 -2
- package/dist/types/markdown/utils.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/dictionaryManipulator/qualifiedDynamicLoader.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getDictionaryAsync.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getEnumeration.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getGender.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getInsertion.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getPlural.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getSelect.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/index.d.ts +0 -7
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/interpolableNode.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/transpiler/index.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/transpiler/nesting/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/transpiler/nesting/nesting.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/dictionaryManipulator/qualifiedDynamicLoader.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getDictionaryAsync.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getEnumeration.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getGender.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getInsertion.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getPlural.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/getSelect.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/index.d.ts +0 -7
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/interpreter/interpolableNode.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/intlayer/dist/types/index.d.ts +0 -6
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/transpiler/index.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/transpiler/nesting/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/@intlayer/core/dist/types/transpiler/nesting/nesting.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/dictionaryManipulator/plainDynamicLoader.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/dictionaryManipulator/qualifiedDynamicLoader.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/formatters/compact.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/currency.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/date.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/index.d.ts +0 -9
- package/dist/types/@intlayer/core/dist/types/formatters/list.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/number.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/percentage.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/relativeTime.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/formatters/units.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/interpreter/dictionaryTransformCache.d.ts +0 -4
- package/dist/types/@intlayer/core/dist/types/interpreter/getCondition.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/interpreter/getContent/deepTransform.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/interpreter/getContent/getContent.d.ts +0 -3
- package/dist/types/@intlayer/core/dist/types/interpreter/getContent/index.d.ts +0 -3
- package/dist/types/@intlayer/core/dist/types/interpreter/getContent/plugins.d.ts +0 -7
- package/dist/types/@intlayer/core/dist/types/interpreter/getDictionary.d.ts +0 -4
- package/dist/types/@intlayer/core/dist/types/interpreter/getDictionaryAsync.d.ts +0 -6
- package/dist/types/@intlayer/core/dist/types/interpreter/getEnumeration.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/interpreter/getGender.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/interpreter/getInsertion.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/interpreter/getIntlayer.d.ts +0 -4
- package/dist/types/@intlayer/core/dist/types/interpreter/getIntlayerAsync.d.ts +0 -4
- package/dist/types/@intlayer/core/dist/types/interpreter/getNesting.d.ts +0 -6
- package/dist/types/@intlayer/core/dist/types/interpreter/getPlural.d.ts +0 -3
- package/dist/types/@intlayer/core/dist/types/interpreter/getSelect.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/interpreter/getTranslation.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/interpreter/index.d.ts +0 -18
- package/dist/types/@intlayer/core/dist/types/interpreter/interpolableNode.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/intlayer/dist/types/index.d.ts +0 -6
- package/dist/types/@intlayer/core/dist/types/localization/comparePaths.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/domainUtils.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/generateSitemap.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/getBrowserLocale.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/getCanonicalPath.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/getHTMLTextDir.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/getLocale.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/getLocaleFromPath.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/getLocaleLang.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/getLocaleName.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/getLocalizedPath.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/getLocalizedUrl.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/getMultilingualUrls.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/getPathWithoutLocale.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/getPrefix.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/index.d.ts +0 -22
- package/dist/types/@intlayer/core/dist/types/localization/localeDetector.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/localeMapper.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/localeResolver.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/resolveBrowserLocale.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/rewriteMatch.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/localization/rewriteUtils.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/localization/validatePrefix.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/markdown/index.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/transpiler/condition/condition.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/condition/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/enumeration/enumeration.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/enumeration/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/file/file.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/file/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/gender/gender.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/gender/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/html/html.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/html/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/index.d.ts +0 -22
- package/dist/types/@intlayer/core/dist/types/transpiler/insertion/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/insertion/insertion.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/markdown/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/markdown/markdown.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/nesting/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/nesting/nesting.d.ts +0 -4
- package/dist/types/@intlayer/core/dist/types/transpiler/plural/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/plural/plural.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/select/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/select/select.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/translation/index.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/transpiler/translation/translation.d.ts +0 -2
- package/dist/types/@intlayer/core/dist/types/utils/index.d.ts +0 -3
- package/dist/types/@intlayer/core/dist/types/utils/intl.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/utils/isSameKeyPath.d.ts +0 -1
- package/dist/types/@intlayer/core/dist/types/utils/localeStorage.d.ts +0 -2
- package/dist/types/intlayer/dist/types/index.d.ts +0 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ATTRIBUTES_TO_SANITIZE, CAPTURE_LETTER_AFTER_HYPHEN, FENCE_DELIMITER_R, HTML_CUSTOM_ATTR_R, INTERPOLATION_R,
|
|
1
|
+
import { ATTRIBUTES_TO_SANITIZE, CAPTURE_LETTER_AFTER_HYPHEN, CR_NEWLINE_R, FENCE_DELIMITER_R, FORMFEED_R, HTML_CUSTOM_ATTR_R, INTERPOLATION_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, UNESCAPE_R } from "./constants.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/markdown/utils.ts
|
|
4
4
|
/**
|
|
@@ -6,8 +6,8 @@ import { ATTRIBUTES_TO_SANITIZE, CAPTURE_LETTER_AFTER_HYPHEN, FENCE_DELIMITER_R,
|
|
|
6
6
|
*/
|
|
7
7
|
const trimEnd = (str) => {
|
|
8
8
|
let end = str.length;
|
|
9
|
-
while (end > 0 && str
|
|
10
|
-
return str.slice(0, end);
|
|
9
|
+
while (end > 0 && str.charCodeAt(end - 1) <= 32) end--;
|
|
10
|
+
return end === str.length ? str : str.slice(0, end);
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
* Check if string starts with prefix.
|
|
@@ -26,7 +26,7 @@ const unquote = (str) => {
|
|
|
26
26
|
/**
|
|
27
27
|
* Unescape backslash-escaped characters.
|
|
28
28
|
*/
|
|
29
|
-
const unescapeString = (rawString) => rawString ? rawString.replace(UNESCAPE_R, "$1") : rawString;
|
|
29
|
+
const unescapeString = (rawString) => rawString && rawString.indexOf("\\") !== -1 ? rawString.replace(UNESCAPE_R, "$1") : rawString;
|
|
30
30
|
/**
|
|
31
31
|
* Join class names, filtering out falsy values.
|
|
32
32
|
*/
|
|
@@ -35,6 +35,7 @@ const cx = (...args) => args.filter(Boolean).join(" ");
|
|
|
35
35
|
* Get a nested property from an object using dot notation.
|
|
36
36
|
*/
|
|
37
37
|
const get = (src, path, fb) => {
|
|
38
|
+
if (path.indexOf(".") === -1) return src?.[path] ?? fb;
|
|
38
39
|
let ptr = src;
|
|
39
40
|
const frags = path.split(".");
|
|
40
41
|
while (frags.length) {
|
|
@@ -57,16 +58,18 @@ const SLUGIFY_REPLACEMENTS = [
|
|
|
57
58
|
[/[Ññ]/g, "n"],
|
|
58
59
|
[/[øØœŒÕõÔôÓóÒò]/g, "o"],
|
|
59
60
|
[/[ÜüÛûÚúÙù]/g, "u"],
|
|
60
|
-
[/[ŸÿÝý]/g, "y"]
|
|
61
|
-
[/[^a-z0-9- ]/gi, ""],
|
|
62
|
-
[/ /gi, "-"]
|
|
61
|
+
[/[ŸÿÝý]/g, "y"]
|
|
63
62
|
];
|
|
63
|
+
const NON_ASCII_R = /[\u0080-\uffff]/;
|
|
64
|
+
const SLUGIFY_STRIP_R = /[^a-z0-9- ]/gi;
|
|
65
|
+
const SLUGIFY_SPACE_R = / /g;
|
|
64
66
|
const slugify = (str) => {
|
|
65
67
|
let result = str;
|
|
66
|
-
for (let i = 0; i < SLUGIFY_REPLACEMENTS.length; i++) {
|
|
68
|
+
if (NON_ASCII_R.test(result)) for (let i = 0; i < SLUGIFY_REPLACEMENTS.length; i++) {
|
|
67
69
|
const [pattern, replacement] = SLUGIFY_REPLACEMENTS[i];
|
|
68
70
|
result = result.replace(pattern, replacement);
|
|
69
71
|
}
|
|
72
|
+
result = result.replace(SLUGIFY_STRIP_R, "").replace(SLUGIFY_SPACE_R, "-");
|
|
70
73
|
return result.toLowerCase();
|
|
71
74
|
};
|
|
72
75
|
const SANITIZE_R = /(javascript|vbscript|data(?!:image)):/i;
|
|
@@ -92,11 +95,13 @@ const sanitizer = (input) => {
|
|
|
92
95
|
/**
|
|
93
96
|
* Normalize whitespace in source string.
|
|
94
97
|
*/
|
|
95
|
-
const normalizeWhitespace = (source) =>
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const normalizeWhitespace = (source) => {
|
|
99
|
+
let normalized = source;
|
|
100
|
+
if (normalized.indexOf(" ") !== -1) normalized = normalized.replace(TAB_R, " ");
|
|
101
|
+
if (normalized.indexOf("\r") !== -1) normalized = normalized.replace(CR_NEWLINE_R, "\n");
|
|
102
|
+
if (normalized.indexOf("\f") !== -1) normalized = normalized.replace(FORMFEED_R, "");
|
|
103
|
+
return normalized;
|
|
104
|
+
};
|
|
100
105
|
/**
|
|
101
106
|
* Safely remove a uniform leading indentation from lines, but do NOT touch
|
|
102
107
|
* the content inside fenced code blocks (``` or ~~~).
|
|
@@ -203,6 +208,7 @@ const attributeValueToNodePropValue = (tag, key, value, sanitizeUrlFn) => {
|
|
|
203
208
|
* Parse table alignment from a separator row.
|
|
204
209
|
*/
|
|
205
210
|
const parseTableAlignCapture = (alignCapture) => {
|
|
211
|
+
if (alignCapture.indexOf(":") === -1) return "left";
|
|
206
212
|
if (TABLE_RIGHT_ALIGN.test(alignCapture)) return "right";
|
|
207
213
|
else if (TABLE_CENTER_ALIGN.test(alignCapture)) return "center";
|
|
208
214
|
else if (TABLE_LEFT_ALIGN.test(alignCapture)) return "left";
|
|
@@ -220,25 +226,88 @@ const parseTableAlign = (source) => {
|
|
|
220
226
|
const parseTableRow = (source, parse, state, tableOutput) => {
|
|
221
227
|
const prevInTable = state.inTable;
|
|
222
228
|
state.inTable = true;
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
let rStart = 0;
|
|
230
|
+
let rEnd = source.length;
|
|
231
|
+
while (rStart < rEnd) {
|
|
232
|
+
const c = source.charCodeAt(rStart);
|
|
233
|
+
if (c === 32 || c === 9) rStart++;
|
|
234
|
+
else break;
|
|
235
|
+
}
|
|
236
|
+
while (rEnd > rStart) {
|
|
237
|
+
const c = source.charCodeAt(rEnd - 1);
|
|
238
|
+
if (c === 32 || c === 9) rEnd--;
|
|
239
|
+
else break;
|
|
240
|
+
}
|
|
241
|
+
if (rStart < rEnd && source.charCodeAt(rStart) === 124) rStart++;
|
|
242
|
+
if (rEnd > rStart && source.charCodeAt(rEnd - 1) === 124 && (rEnd - 2 < rStart || source.charCodeAt(rEnd - 2) !== 92)) rEnd--;
|
|
243
|
+
if (!tableOutput) {
|
|
244
|
+
const cell = parse(source.slice(rStart, rEnd), state);
|
|
245
|
+
state.inTable = prevInTable;
|
|
246
|
+
return [cell];
|
|
247
|
+
}
|
|
248
|
+
const cells = [];
|
|
249
|
+
const len = source.length;
|
|
250
|
+
let cellStart = rStart;
|
|
251
|
+
let i = rStart;
|
|
252
|
+
/**
|
|
253
|
+
* Parse one cell, dropping the padding an aligned table pads it with.
|
|
254
|
+
*
|
|
255
|
+
* GFM strips a cell's surrounding whitespace, so trimming is both the correct
|
|
256
|
+
* output and the cheap one: the padding of a column-aligned table is a large
|
|
257
|
+
* share of its bytes, and every space handed to `parse` costs a rule dispatch,
|
|
258
|
+
* a capture and a lookbehind update. `trim` is a native scan, and walking the
|
|
259
|
+
* padding back from the delimiter in JavaScript instead costs half as much
|
|
260
|
+
* again as the whole row scan.
|
|
261
|
+
*/
|
|
262
|
+
const parseCell = (from, to) => {
|
|
263
|
+
const cell = source.slice(from, to).trim();
|
|
264
|
+
return cell === "" ? [] : parse(cell, state);
|
|
230
265
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
266
|
+
let pipeAt = -1;
|
|
267
|
+
let escapeAt = -1;
|
|
268
|
+
let backtickAt = -1;
|
|
269
|
+
while (i < rEnd) {
|
|
270
|
+
if (pipeAt < i) {
|
|
271
|
+
const at = source.indexOf("|", i);
|
|
272
|
+
pipeAt = at === -1 ? len : at;
|
|
273
|
+
}
|
|
274
|
+
if (escapeAt < i) {
|
|
275
|
+
const at = source.indexOf("\\", i);
|
|
276
|
+
escapeAt = at === -1 ? len : at;
|
|
277
|
+
}
|
|
278
|
+
if (backtickAt < i) {
|
|
279
|
+
const at = source.indexOf("`", i);
|
|
280
|
+
backtickAt = at === -1 ? len : at;
|
|
281
|
+
}
|
|
282
|
+
i = Math.min(pipeAt, escapeAt, backtickAt);
|
|
283
|
+
if (i >= rEnd) break;
|
|
284
|
+
if (i === escapeAt) {
|
|
285
|
+
i += i + 1 < rEnd ? 2 : 1;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (i === backtickAt) {
|
|
289
|
+
let backticks = 0;
|
|
290
|
+
while (i < rEnd && source.charCodeAt(i) === 96) {
|
|
291
|
+
backticks++;
|
|
292
|
+
i++;
|
|
293
|
+
}
|
|
294
|
+
let found = false;
|
|
295
|
+
while (i < rEnd && !found) {
|
|
296
|
+
let closeBackticks = 0;
|
|
297
|
+
while (i < rEnd && source.charCodeAt(i) === 96) {
|
|
298
|
+
closeBackticks++;
|
|
299
|
+
i++;
|
|
300
|
+
}
|
|
301
|
+
if (closeBackticks === backticks) found = true;
|
|
302
|
+
else if (closeBackticks === 0) i++;
|
|
237
303
|
}
|
|
304
|
+
continue;
|
|
238
305
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
306
|
+
cells.push(parseCell(cellStart, i));
|
|
307
|
+
i++;
|
|
308
|
+
cellStart = i;
|
|
309
|
+
}
|
|
310
|
+
cells.push(parseCell(cellStart, rEnd));
|
|
242
311
|
state.inTable = prevInTable;
|
|
243
312
|
return cells;
|
|
244
313
|
};
|
|
@@ -246,7 +315,27 @@ const parseTableRow = (source, parse, state, tableOutput) => {
|
|
|
246
315
|
* Parse table cells (multiple rows).
|
|
247
316
|
*/
|
|
248
317
|
const parseTableCells = (source, parse, state) => {
|
|
249
|
-
|
|
318
|
+
if (!source) return [];
|
|
319
|
+
const result = [];
|
|
320
|
+
let start = 0;
|
|
321
|
+
const len = source.length;
|
|
322
|
+
while (start < len) {
|
|
323
|
+
let nextNewline = source.indexOf("\n", start);
|
|
324
|
+
if (nextNewline === -1) nextNewline = len;
|
|
325
|
+
const rowText = source.slice(start, nextNewline);
|
|
326
|
+
start = nextNewline + 1;
|
|
327
|
+
let hasContent = false;
|
|
328
|
+
for (let j = 0; j < rowText.length; j++) {
|
|
329
|
+
const c = rowText.charCodeAt(j);
|
|
330
|
+
if (c !== 32 && c !== 9 && c !== 13) {
|
|
331
|
+
hasContent = true;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!hasContent) continue;
|
|
336
|
+
result.push(parseTableRow(rowText, parse, state, true));
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
250
339
|
};
|
|
251
340
|
/**
|
|
252
341
|
* Check if a rule qualifies for the current source and state.
|
|
@@ -344,11 +433,11 @@ const captureNothing = () => ({});
|
|
|
344
433
|
* Helper that renders nothing (null).
|
|
345
434
|
*/
|
|
346
435
|
const renderNothing = () => null;
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
436
|
+
const some = (probes, input) => {
|
|
437
|
+
for (let i = 0; i < probes.length; i++) {
|
|
438
|
+
const probe = probes[i];
|
|
439
|
+
if (typeof probe === "function" ? probe(input) : probe.test(input)) return true;
|
|
440
|
+
}
|
|
352
441
|
return false;
|
|
353
442
|
};
|
|
354
443
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/markdown/utils.ts"],"sourcesContent":["import {\n ATTRIBUTES_TO_SANITIZE,\n CAPTURE_LETTER_AFTER_HYPHEN,\n FENCE_DELIMITER_R,\n HTML_CUSTOM_ATTR_R,\n INTERPOLATION_R,\n NORMALIZE_WHITESPACE_R,\n TABLE_CENTER_ALIGN,\n TABLE_LEFT_ALIGN,\n TABLE_RIGHT_ALIGN,\n TABLE_TRIM_PIPES,\n UNESCAPE_R,\n} from './constants';\nimport type { NestedParser, ParserResult, ParseState, Rule } from './types';\n\n// ============================================================================\n// STRING UTILITIES\n// ============================================================================\n\n/**\n * Trim trailing whitespace from a string.\n */\nexport const trimEnd = (str: string): string => {\n let end = str.length;\n\n while (end > 0 && str[end - 1]! <= ' ') end--;\n\n return str.slice(0, end);\n};\n\n/**\n * Check if string starts with prefix.\n */\nexport const startsWith = (str: string, prefix: string): boolean => {\n return str.startsWith(prefix);\n};\n\n/**\n * Remove symmetrical leading and trailing quotes.\n */\nexport const unquote = (str: string): string => {\n const first = str[0];\n\n if (\n (first === '\"' || first === \"'\") &&\n str.length >= 2 &&\n str[str.length - 1] === first\n ) {\n return str.slice(1, -1);\n }\n\n return str;\n};\n\n/**\n * Unescape backslash-escaped characters.\n */\nexport const unescapeString = (rawString: string): string =>\n rawString ? rawString.replace(UNESCAPE_R, '$1') : rawString;\n\n/**\n * Join class names, filtering out falsy values.\n */\nexport const cx = (...args: any[]): string => args.filter(Boolean).join(' ');\n\n/**\n * Get a nested property from an object using dot notation.\n */\nexport const get = (src: any, path: string, fb?: any): any => {\n let ptr = src;\n const frags = path.split('.');\n\n while (frags.length) {\n ptr = ptr[frags[0]!];\n\n if (ptr === undefined) break;\n else frags.shift();\n }\n\n return ptr ?? fb;\n};\n\n// ============================================================================\n// SLUGIFY\n// ============================================================================\n\n/**\n * Convert a string to a URL-safe slug.\n * Based on https://stackoverflow.com/a/18123682/1141611\n */\nconst SLUGIFY_REPLACEMENTS: [pattern: RegExp, replacement: string][] = [\n [/[ÀÁÂÃÄÅàáâãä忯]/g, 'a'],\n [/[çÇ]/g, 'c'],\n [/[ðÐ]/g, 'd'],\n [/[ÈÉÊËéèêë]/g, 'e'],\n [/[ÏïÎîÍíÌì]/g, 'i'],\n [/[Ññ]/g, 'n'],\n [/[øØœŒÕõÔôÓóÒò]/g, 'o'],\n [/[ÜüÛûÚúÙù]/g, 'u'],\n [/[ŸÿÝý]/g, 'y'],\n [/[^a-z0-9- ]/gi, ''],\n [/ /gi, '-'],\n];\n\nexport const slugify = (str: string): string => {\n let result = str;\n\n for (let i = 0; i < SLUGIFY_REPLACEMENTS.length; i++) {\n const [pattern, replacement] = SLUGIFY_REPLACEMENTS[i]!;\n result = result.replace(pattern, replacement);\n }\n\n return result.toLowerCase();\n};\n\n// ============================================================================\n// SANITIZER\n// ============================================================================\n\nconst SANITIZE_R = /(javascript|vbscript|data(?!:image)):/i;\nconst SANITIZE_STRIP_R = /[^A-Za-z0-9/:]/g;\n\n/**\n * Sanitize URLs to prevent XSS attacks.\n * Returns null if the URL is unsafe.\n */\nexport const sanitizer = (input: string): string | null => {\n // `SANITIZE_R` only ever matches on a colon, and decoding can introduce one\n // solely through a percent escape — so a value with neither is safe as-is,\n // and skipping the decode avoids the bulk of the work on ordinary links.\n if (input.indexOf(':') === -1 && input.indexOf('%') === -1) return input;\n\n try {\n const decoded = decodeURIComponent(input).replace(SANITIZE_STRIP_R, '');\n\n if (SANITIZE_R.test(decoded)) {\n console.warn(\n 'Input contains an unsafe JavaScript/VBScript/data expression, it will not be rendered.',\n decoded\n );\n\n return null;\n }\n } catch (_e) {\n console.warn(\n 'Input could not be decoded due to malformed syntax or characters, it will not be rendered.',\n input\n );\n\n // decodeURIComponent sometimes throws a URIError\n return null;\n }\n\n return input;\n};\n\n// ============================================================================\n// WHITESPACE NORMALIZATION\n// ============================================================================\n\n/**\n * Normalize whitespace in source string.\n */\nexport const normalizeWhitespace = (source: string): string =>\n // `\\r`, `\\f` and `\\t` are disjoint, so one pass over the source replaces\n // what used to take three full scans.\n source.replace(NORMALIZE_WHITESPACE_R, (match) => {\n if (match === '\\t') return ' ';\n if (match === '\\f') return '';\n\n return '\\n';\n });\n\n/**\n * Safely remove a uniform leading indentation from lines, but do NOT touch\n * the content inside fenced code blocks (``` or ~~~).\n *\n * Inside a fenced block the structural indentation is irrelevant: what matters\n * is the indentation of the opening fence itself, which is the only amount\n * CommonMark strips from the code lines. A block nested in an indented HTML\n * element but written with its fence at column 0 therefore keeps its code\n * verbatim, instead of losing the first level of indentation.\n */\nexport const trimLeadingWhitespaceOutsideFences = (\n text: string,\n whitespace: string\n): string => {\n if (!whitespace) return text;\n\n const lines = text.split('\\n');\n\n /** Indentation and marker of the fence currently open, if any. */\n let openFence: { indentation: string; marker: string } | null = null;\n\n const removePrefix = (line: string, prefix: string): string =>\n prefix && line.startsWith(prefix) ? line.slice(prefix.length) : line;\n\n // Outside fences, strip the base structural indentation from every line.\n // Lines that don't start with the whitespace prefix are left as-is.\n const result = lines\n .map((line) => {\n const fenceMatch = line.match(FENCE_DELIMITER_R);\n\n if (!openFence) {\n if (fenceMatch)\n openFence = { indentation: fenceMatch[1]!, marker: fenceMatch[2]! };\n return removePrefix(line, whitespace);\n }\n\n const isClosingFence = fenceMatch?.[2]?.startsWith(openFence.marker);\n const { indentation } = openFence;\n\n if (isClosingFence) openFence = null;\n\n return removePrefix(line, indentation);\n })\n .join('\\n');\n\n return result;\n};\n\n/**\n * Normalize HTML attribute key to JSX prop name.\n */\nexport const normalizeAttributeKey = (key: string): string => {\n const hyphenIndex = key.indexOf('-');\n\n if (hyphenIndex !== -1 && key.match(HTML_CUSTOM_ATTR_R) === null) {\n key = key.replace(CAPTURE_LETTER_AFTER_HYPHEN, (_, letter) => {\n return letter.toUpperCase();\n });\n }\n\n return key;\n};\n\ntype StyleTuple = [key: string, value: string];\n\n/**\n * Parse a CSS style string into an array of [key, value] tuples.\n */\nexport const parseStyleAttribute = (styleString: string): StyleTuple[] => {\n const styles: StyleTuple[] = [];\n let buffer = '';\n let inUrl = false;\n let inQuotes = false;\n let quoteChar: '\"' | \"'\" | '' = '';\n\n if (!styleString) return styles;\n\n for (let i = 0; i < styleString.length; i++) {\n const char = styleString[i];\n\n if ((char === '\"' || char === \"'\") && !inUrl) {\n if (!inQuotes) {\n inQuotes = true;\n quoteChar = char;\n } else if (char === quoteChar) {\n inQuotes = false;\n quoteChar = '';\n }\n }\n\n if (char === '(' && buffer.endsWith('url')) {\n inUrl = true;\n } else if (char === ')' && inUrl) {\n inUrl = false;\n }\n\n if (char === ';' && !inQuotes && !inUrl) {\n const declaration = buffer.trim();\n\n if (declaration) {\n const colonIndex = declaration.indexOf(':');\n\n if (colonIndex > 0) {\n const key = declaration.slice(0, colonIndex).trim();\n const value = declaration.slice(colonIndex + 1).trim();\n styles.push([key, value]);\n }\n }\n buffer = '';\n } else {\n buffer += char;\n }\n }\n\n const declaration = buffer.trim();\n\n if (declaration) {\n const colonIndex = declaration.indexOf(':');\n if (colonIndex > 0) {\n const key = declaration.slice(0, colonIndex).trim();\n const value = declaration.slice(colonIndex + 1).trim();\n styles.push([key, value]);\n }\n }\n\n return styles;\n};\n\n/**\n * Convert an attribute value to a Node prop value.\n */\nexport const attributeValueToNodePropValue = (\n tag: string,\n key: string,\n value: string,\n sanitizeUrlFn: (\n value: string,\n tag: string,\n attribute: string\n ) => string | null\n): any => {\n if (key === 'style') {\n return parseStyleAttribute(value).reduce(\n (styles, [styleKey, styleValue]) => {\n const camelCasedKey = styleKey.replace(/(-[a-z])/g, (substr) =>\n substr[1]!.toUpperCase()\n );\n\n (styles as Record<string, any>)[camelCasedKey] = sanitizeUrlFn(\n styleValue,\n tag,\n styleKey\n );\n\n return styles;\n },\n {} as Record<string, any>\n );\n } else if (ATTRIBUTES_TO_SANITIZE.indexOf(key) !== -1) {\n return sanitizeUrlFn(unescapeString(value), tag, key);\n } else if (value.match(INTERPOLATION_R)) {\n value = unescapeString(value.slice(1, value.length - 1));\n }\n\n if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n return value;\n};\n\n// ============================================================================\n// TABLE PARSING\n// ============================================================================\n\n/**\n * Parse table alignment from a separator row.\n */\nexport const parseTableAlignCapture = (\n alignCapture: string\n): 'left' | 'right' | 'center' => {\n if (TABLE_RIGHT_ALIGN.test(alignCapture)) {\n return 'right';\n } else if (TABLE_CENTER_ALIGN.test(alignCapture)) {\n return 'center';\n } else if (TABLE_LEFT_ALIGN.test(alignCapture)) {\n return 'left';\n }\n\n return 'left';\n};\n\n/**\n * Parse table alignment row.\n */\nexport const parseTableAlign = (\n source: string\n): ('left' | 'right' | 'center')[] => {\n const alignText = source.replace(TABLE_TRIM_PIPES, '').split('|');\n return alignText.map(parseTableAlignCapture);\n};\n\n/**\n * Parse a single table row.\n */\nexport const parseTableRow = (\n source: string,\n parse: NestedParser,\n state: ParseState,\n tableOutput: boolean\n): ParserResult[][] => {\n const prevInTable = state.inTable;\n\n state.inTable = true;\n\n const cells: ParserResult[][] = [[]];\n let acc = '';\n\n const flush = (): void => {\n if (!acc) return;\n\n const cell = cells[cells.length - 1]!;\n cell.push.apply(cell, parse(acc, state));\n acc = '';\n };\n\n source\n .trim()\n .split(/(`[^`]*`|\\\\\\||\\|)/)\n .filter(Boolean)\n .forEach((fragment, i, arr) => {\n if (fragment.trim() === '|') {\n flush();\n\n if (tableOutput) {\n if (i !== 0 && i !== arr.length - 1) {\n cells.push([]);\n }\n\n return;\n }\n }\n\n acc += fragment;\n });\n\n flush();\n\n state.inTable = prevInTable;\n\n return cells;\n};\n\n/**\n * Parse table cells (multiple rows).\n */\nexport const parseTableCells = (\n source: string,\n parse: NestedParser,\n state: ParseState\n): ParserResult[][][] => {\n const rowsText = source.trim().split('\\n');\n\n const result = rowsText.map((rowText) =>\n parseTableRow(rowText, parse, state, true)\n );\n\n return result;\n};\n\n// ============================================================================\n// PARSING HELPERS\n// ============================================================================\n\n/**\n * Check if a rule qualifies for the current source and state.\n */\nexport const qualifies = (\n source: string,\n state: ParseState,\n qualify: NonNullable<Rule<any>['_qualify']>\n): boolean => {\n if (Array.isArray(qualify)) {\n for (let i = 0; i < qualify.length; i++) {\n if (startsWith(source, qualify[i]!)) return true;\n }\n\n return false;\n }\n\n return (qualify as (source: string, state: ParseState) => boolean)(\n source,\n state\n );\n};\n\n/**\n * Marks a matcher function as eligible for being run inside an inline context.\n */\nexport const allowInline = <T extends (...args: any[]) => any>(\n fn: T\n): T & { inline: 1 } => {\n (fn as any).inline = 1;\n return fn as T & { inline: 1 };\n};\n\n/**\n * Creates a match function for an inline scoped element from a regex.\n */\nexport const inlineRegex = (regex: RegExp) =>\n allowInline((source: string, state: ParseState): RegExpMatchArray | null => {\n if (state.inline) {\n return regex.exec(source);\n } else {\n return null;\n }\n });\n\n/**\n * Creates a match function for inline elements except links.\n */\nexport const simpleInlineRegex = (regex: RegExp) =>\n allowInline((source: string, state: ParseState): RegExpMatchArray | null => {\n if (state.inline || state.simple) {\n return regex.exec(source);\n } else {\n return null;\n }\n });\n\n/**\n * Creates a match function for a block scoped element from a regex.\n */\nexport const blockRegex =\n (regex: RegExp) =>\n (source: string, state: ParseState): RegExpMatchArray | null => {\n if (state.inline || state.simple) {\n return null;\n } else {\n return regex.exec(source);\n }\n };\n\n/**\n * Creates a match function from a regex, ignoring block/inline scope.\n */\nexport const anyScopeRegex = (\n fn: RegExp | ((source: string, state: ParseState) => RegExpMatchArray | null)\n) =>\n allowInline((source: string, state: ParseState): RegExpMatchArray | null => {\n if (typeof fn === 'function') {\n return fn(source, state);\n }\n return fn.exec(source);\n });\n\n/**\n * Parse inline content (including links).\n */\nexport const parseInline = (\n parse: NestedParser,\n children: string,\n state: ParseState\n): ParserResult[] => {\n const isCurrentlyInline = state.inline ?? false;\n const isCurrentlySimple = state.simple ?? false;\n state.inline = true;\n state.simple = true;\n const result = parse(children, state);\n state.inline = isCurrentlyInline;\n state.simple = isCurrentlySimple;\n\n return result;\n};\n\n/**\n * Parse simple inline content (no links).\n */\nexport const parseSimpleInline = (\n parse: NestedParser,\n children: string,\n state: ParseState\n): ParserResult[] => {\n const isCurrentlyInline = state.inline ?? false;\n const isCurrentlySimple = state.simple ?? false;\n\n state.inline = false;\n state.simple = true;\n const result = parse(children, state);\n state.inline = isCurrentlyInline;\n state.simple = isCurrentlySimple;\n\n return result;\n};\n\n/**\n * Parse block content.\n */\nexport const parseBlock = (\n parse: NestedParser,\n children: string,\n state: ParseState = {}\n): ParserResult[] => {\n const isCurrentlyInline = state.inline || false;\n state.inline = false;\n const normalizedChildren = trimEnd(children);\n const needsTerminator = /\\n\\n$/.test(normalizedChildren) === false;\n const blockInput = needsTerminator\n ? normalizedChildren.endsWith('\\n')\n ? `${normalizedChildren}\\n`\n : `${normalizedChildren}\\n\\n`\n : normalizedChildren;\n\n const result = parse(blockInput, state);\n state.inline = isCurrentlyInline;\n\n return result;\n};\n\n/**\n * Helper to parse capture group 2 as inline content.\n */\nexport const parseCaptureInline = (\n capture: RegExpMatchArray,\n parse: NestedParser,\n state: ParseState\n): { children: ParserResult[] } => {\n return {\n children: parseInline(parse, capture[2] ?? '', state),\n };\n};\n\n/**\n * Helper that captures nothing (empty object).\n */\nexport const captureNothing = (): Record<string, never> => ({});\n\n/**\n * Helper that renders nothing (null).\n */\nexport const renderNothing = (): null => null;\n\n/**\n * Check if any regex in a list matches the input.\n */\nexport const some = (regexes: RegExp[], input: string): boolean => {\n for (let i = 0; i < regexes.length; i++) {\n if (regexes[i]!.test(input)) {\n return true;\n }\n }\n return false;\n};\n"],"mappings":";;;;;;AAsBA,MAAa,WAAW,QAAwB;CAC9C,IAAI,MAAM,IAAI;CAEd,OAAO,MAAM,KAAK,IAAI,MAAM,MAAO,KAAK;CAExC,OAAO,IAAI,MAAM,GAAG,GAAG;AACzB;;;;AAKA,MAAa,cAAc,KAAa,WAA4B;CAClE,OAAO,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AAM,SAAS;CACf,MAAM,SAAS;CACf,MAAM,SAAS,MAAM,UAAU,KAAK;CACpC,MAAM,SAAS;CACf,MAAM,SAAS;CAEf,OAAO;AACT;;;;AAKA,MAAa,qBACX,OACA,UACA,UACmB;CACnB,MAAM,oBAAoB,MAAM,UAAU;CAC1C,MAAM,oBAAoB,MAAM,UAAU;CAE1C,MAAM,SAAS;CACf,MAAM,SAAS;CACf,MAAM,SAAS,MAAM,UAAU,KAAK;CACpC,MAAM,SAAS;CACf,MAAM,SAAS;CAEf,OAAO;AACT;;;;AAKA,MAAa,cACX,OACA,UACA,QAAoB,CAAC,MACF;CACnB,MAAM,oBAAoB,MAAM,UAAU;CAC1C,MAAM,SAAS;CACf,MAAM,qBAAqB,QAAQ,QAAQ;CAQ3C,MAAM,SAAS,MAPS,QAAQ,KAAK,kBAAkB,MAAM,QAEzD,mBAAmB,SAAS,IAAI,IAC9B,GAAG,mBAAmB,MACtB,GAAG,mBAAmB,QACxB,oBAE6B,KAAK;CACtC,MAAM,SAAS;CAEf,OAAO;AACT;;;;AAKA,MAAa,sBACX,SACA,OACA,UACiC;CACjC,OAAO,EACL,UAAU,YAAY,OAAO,QAAQ,MAAM,IAAI,KAAK,EACtD;AACF;;;;AAKA,MAAa,wBAA+C,CAAC;;;;AAK7D,MAAa,sBAA4B;;;;AAKzC,MAAa,QAAQ,SAAmB,UAA2B;CACjE,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAClC,IAAI,QAAQ,EAAE,CAAE,KAAK,KAAK,GACxB,OAAO;CAGX,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../../src/markdown/utils.ts"],"sourcesContent":["import {\n ATTRIBUTES_TO_SANITIZE,\n CAPTURE_LETTER_AFTER_HYPHEN,\n CR_NEWLINE_R,\n FENCE_DELIMITER_R,\n FORMFEED_R,\n HTML_CUSTOM_ATTR_R,\n INTERPOLATION_R,\n TAB_R,\n TABLE_CENTER_ALIGN,\n TABLE_LEFT_ALIGN,\n TABLE_RIGHT_ALIGN,\n TABLE_TRIM_PIPES,\n UNESCAPE_R,\n} from './constants';\nimport type { NestedParser, ParserResult, ParseState, Rule } from './types';\n\n// ============================================================================\n// STRING UTILITIES\n// ============================================================================\n\n/**\n * Trim trailing whitespace from a string.\n */\nexport const trimEnd = (str: string): string => {\n let end = str.length;\n\n while (end > 0 && str.charCodeAt(end - 1) <= 32) end--;\n\n return end === str.length ? str : str.slice(0, end);\n};\n\n/**\n * Check if string starts with prefix.\n */\nexport const startsWith = (str: string, prefix: string): boolean => {\n return str.startsWith(prefix);\n};\n\n/**\n * Remove symmetrical leading and trailing quotes.\n */\nexport const unquote = (str: string): string => {\n const first = str[0];\n\n if (\n (first === '\"' || first === \"'\") &&\n str.length >= 2 &&\n str[str.length - 1] === first\n ) {\n return str.slice(1, -1);\n }\n\n return str;\n};\n\n/**\n * Unescape backslash-escaped characters.\n */\nexport const unescapeString = <T extends string | undefined>(rawString: T): T =>\n (rawString && rawString.indexOf('\\\\') !== -1\n ? rawString.replace(UNESCAPE_R, '$1')\n : rawString) as T;\n\n/**\n * Join class names, filtering out falsy values.\n */\nexport const cx = (...args: any[]): string => args.filter(Boolean).join(' ');\n\n/**\n * Get a nested property from an object using dot notation.\n */\nexport const get = (src: any, path: string, fb?: any): any => {\n // The overwhelming majority of paths are a single segment (a tag name), and\n // splitting those allocated two arrays per lookup.\n if (path.indexOf('.') === -1) return src?.[path] ?? fb;\n\n let ptr = src;\n const frags = path.split('.');\n\n while (frags.length) {\n ptr = ptr[frags[0]!];\n\n if (ptr === undefined) break;\n else frags.shift();\n }\n\n return ptr ?? fb;\n};\n\n// ============================================================================\n// SLUGIFY\n// ============================================================================\n\n/**\n * Convert a string to a URL-safe slug.\n * Based on https://stackoverflow.com/a/18123682/1141611\n */\nconst SLUGIFY_REPLACEMENTS: [pattern: RegExp, replacement: string][] = [\n [/[ÀÁÂÃÄÅàáâãä忯]/g, 'a'],\n [/[çÇ]/g, 'c'],\n [/[ðÐ]/g, 'd'],\n [/[ÈÉÊËéèêë]/g, 'e'],\n [/[ÏïÎîÍíÌì]/g, 'i'],\n [/[Ññ]/g, 'n'],\n [/[øØœŒÕõÔôÓóÒò]/g, 'o'],\n [/[ÜüÛûÚúÙù]/g, 'u'],\n [/[ŸÿÝý]/g, 'y'],\n];\nconst NON_ASCII_R = /[\\u0080-\\uffff]/;\nconst SLUGIFY_STRIP_R = /[^a-z0-9- ]/gi;\nconst SLUGIFY_SPACE_R = / /g;\n\nexport const slugify = (str: string): string => {\n let result = str;\n\n // Every transliteration matches non-ASCII only, so an ASCII heading — the\n // overwhelmingly common case — skips nine full passes over the string.\n if (NON_ASCII_R.test(result)) {\n for (let i = 0; i < SLUGIFY_REPLACEMENTS.length; i++) {\n const [pattern, replacement] = SLUGIFY_REPLACEMENTS[i]!;\n result = result.replace(pattern, replacement);\n }\n }\n\n result = result.replace(SLUGIFY_STRIP_R, '').replace(SLUGIFY_SPACE_R, '-');\n\n return result.toLowerCase();\n};\n\n// ============================================================================\n// SANITIZER\n// ============================================================================\n\nconst SANITIZE_R = /(javascript|vbscript|data(?!:image)):/i;\nconst SANITIZE_STRIP_R = /[^A-Za-z0-9/:]/g;\n\n/**\n * Sanitize URLs to prevent XSS attacks.\n * Returns null if the URL is unsafe.\n */\nexport const sanitizer = (input: string): string | null => {\n // `SANITIZE_R` only ever matches on a colon, and decoding can introduce one\n // solely through a percent escape — so a value with neither is safe as-is,\n // and skipping the decode avoids the bulk of the work on ordinary links.\n if (input.indexOf(':') === -1 && input.indexOf('%') === -1) return input;\n\n try {\n const decoded = decodeURIComponent(input).replace(SANITIZE_STRIP_R, '');\n\n if (SANITIZE_R.test(decoded)) {\n console.warn(\n 'Input contains an unsafe JavaScript/VBScript/data expression, it will not be rendered.',\n decoded\n );\n\n return null;\n }\n } catch (_e) {\n console.warn(\n 'Input could not be decoded due to malformed syntax or characters, it will not be rendered.',\n input\n );\n\n // decodeURIComponent sometimes throws a URIError\n return null;\n }\n\n return input;\n};\n\n// ============================================================================\n// WHITESPACE NORMALIZATION\n// ============================================================================\n\n/**\n * Normalize whitespace in source string.\n */\nexport const normalizeWhitespace = (source: string): string => {\n // Three `indexOf` probes beat one character-class regex here by a wide margin:\n // each is a native memchr over the source, and none of them normally match.\n // Each probe guards its own replacement too, so a source carrying only tabs —\n // the usual case — never rewrites for the other two, and every replacement is\n // a constant string instead of a callback the engine has to re-enter.\n let normalized = source;\n\n if (normalized.indexOf('\\t') !== -1) {\n normalized = normalized.replace(TAB_R, ' ');\n }\n if (normalized.indexOf('\\r') !== -1) {\n normalized = normalized.replace(CR_NEWLINE_R, '\\n');\n }\n if (normalized.indexOf('\\f') !== -1) {\n normalized = normalized.replace(FORMFEED_R, '');\n }\n\n return normalized;\n};\n\n/**\n * Safely remove a uniform leading indentation from lines, but do NOT touch\n * the content inside fenced code blocks (``` or ~~~).\n *\n * Inside a fenced block the structural indentation is irrelevant: what matters\n * is the indentation of the opening fence itself, which is the only amount\n * CommonMark strips from the code lines. A block nested in an indented HTML\n * element but written with its fence at column 0 therefore keeps its code\n * verbatim, instead of losing the first level of indentation.\n */\nexport const trimLeadingWhitespaceOutsideFences = (\n text: string,\n whitespace: string\n): string => {\n if (!whitespace) return text;\n\n const lines = text.split('\\n');\n\n /** Indentation and marker of the fence currently open, if any. */\n let openFence: { indentation: string; marker: string } | null = null;\n\n const removePrefix = (line: string, prefix: string): string =>\n prefix && line.startsWith(prefix) ? line.slice(prefix.length) : line;\n\n // Outside fences, strip the base structural indentation from every line.\n // Lines that don't start with the whitespace prefix are left as-is.\n const result = lines\n .map((line) => {\n const fenceMatch = line.match(FENCE_DELIMITER_R);\n\n if (!openFence) {\n if (fenceMatch)\n openFence = { indentation: fenceMatch[1]!, marker: fenceMatch[2]! };\n return removePrefix(line, whitespace);\n }\n\n const isClosingFence = fenceMatch?.[2]?.startsWith(openFence.marker);\n const { indentation } = openFence;\n\n if (isClosingFence) openFence = null;\n\n return removePrefix(line, indentation);\n })\n .join('\\n');\n\n return result;\n};\n\n/**\n * Normalize HTML attribute key to JSX prop name.\n */\nexport const normalizeAttributeKey = (key: string): string => {\n const hyphenIndex = key.indexOf('-');\n\n if (hyphenIndex !== -1 && key.match(HTML_CUSTOM_ATTR_R) === null) {\n key = key.replace(CAPTURE_LETTER_AFTER_HYPHEN, (_, letter) => {\n return letter.toUpperCase();\n });\n }\n\n return key;\n};\n\ntype StyleTuple = [key: string, value: string];\n\n/**\n * Parse a CSS style string into an array of [key, value] tuples.\n */\nexport const parseStyleAttribute = (styleString: string): StyleTuple[] => {\n const styles: StyleTuple[] = [];\n let buffer = '';\n let inUrl = false;\n let inQuotes = false;\n let quoteChar: '\"' | \"'\" | '' = '';\n\n if (!styleString) return styles;\n\n for (let i = 0; i < styleString.length; i++) {\n const char = styleString[i];\n\n if ((char === '\"' || char === \"'\") && !inUrl) {\n if (!inQuotes) {\n inQuotes = true;\n quoteChar = char;\n } else if (char === quoteChar) {\n inQuotes = false;\n quoteChar = '';\n }\n }\n\n if (char === '(' && buffer.endsWith('url')) {\n inUrl = true;\n } else if (char === ')' && inUrl) {\n inUrl = false;\n }\n\n if (char === ';' && !inQuotes && !inUrl) {\n const declaration = buffer.trim();\n\n if (declaration) {\n const colonIndex = declaration.indexOf(':');\n\n if (colonIndex > 0) {\n const key = declaration.slice(0, colonIndex).trim();\n const value = declaration.slice(colonIndex + 1).trim();\n styles.push([key, value]);\n }\n }\n buffer = '';\n } else {\n buffer += char;\n }\n }\n\n const declaration = buffer.trim();\n\n if (declaration) {\n const colonIndex = declaration.indexOf(':');\n if (colonIndex > 0) {\n const key = declaration.slice(0, colonIndex).trim();\n const value = declaration.slice(colonIndex + 1).trim();\n styles.push([key, value]);\n }\n }\n\n return styles;\n};\n\n/**\n * Convert an attribute value to a Node prop value.\n */\nexport const attributeValueToNodePropValue = (\n tag: string,\n key: string,\n value: string,\n sanitizeUrlFn: (\n value: string,\n tag: string,\n attribute: string\n ) => string | null\n): any => {\n if (key === 'style') {\n return parseStyleAttribute(value).reduce(\n (styles, [styleKey, styleValue]) => {\n const camelCasedKey = styleKey.replace(/(-[a-z])/g, (substr) =>\n substr[1]!.toUpperCase()\n );\n\n (styles as Record<string, any>)[camelCasedKey] = sanitizeUrlFn(\n styleValue,\n tag,\n styleKey\n );\n\n return styles;\n },\n {} as Record<string, any>\n );\n } else if (ATTRIBUTES_TO_SANITIZE.indexOf(key) !== -1) {\n return sanitizeUrlFn(unescapeString(value), tag, key);\n } else if (value.match(INTERPOLATION_R)) {\n value = unescapeString(value.slice(1, value.length - 1));\n }\n\n if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n }\n\n return value;\n};\n\n// ============================================================================\n// TABLE PARSING\n// ============================================================================\n\n/**\n * Parse table alignment from a separator row.\n */\nexport const parseTableAlignCapture = (\n alignCapture: string\n): 'left' | 'right' | 'center' => {\n // All three patterns need a colon, and the right-align one backtracks across\n // the whole cell before failing — so reject colon-free cells up front.\n if (alignCapture.indexOf(':') === -1) return 'left';\n\n if (TABLE_RIGHT_ALIGN.test(alignCapture)) {\n return 'right';\n } else if (TABLE_CENTER_ALIGN.test(alignCapture)) {\n return 'center';\n } else if (TABLE_LEFT_ALIGN.test(alignCapture)) {\n return 'left';\n }\n\n return 'left';\n};\n\n/**\n * Parse table alignment row.\n */\nexport const parseTableAlign = (\n source: string\n): ('left' | 'right' | 'center')[] => {\n const alignText = source.replace(TABLE_TRIM_PIPES, '').split('|');\n return alignText.map(parseTableAlignCapture);\n};\n\n/**\n * Parse a single table row.\n */\nexport const parseTableRow = (\n source: string,\n parse: NestedParser,\n state: ParseState,\n tableOutput: boolean\n): ParserResult[][] => {\n const prevInTable = state.inTable;\n state.inTable = true;\n\n let rStart = 0;\n let rEnd = source.length;\n\n while (rStart < rEnd) {\n const c = source.charCodeAt(rStart);\n if (c === 32 || c === 9) rStart++;\n else break;\n }\n while (rEnd > rStart) {\n const c = source.charCodeAt(rEnd - 1);\n if (c === 32 || c === 9) rEnd--;\n else break;\n }\n\n // Trim leading pipe if present\n if (rStart < rEnd && source.charCodeAt(rStart) === 124 /* | */) {\n rStart++;\n }\n // Trim trailing pipe if present (and not escaped)\n if (\n rEnd > rStart &&\n source.charCodeAt(rEnd - 1) === 124 /* | */ &&\n (rEnd - 2 < rStart || source.charCodeAt(rEnd - 2) !== 92) /* \\ */\n ) {\n rEnd--;\n }\n\n if (!tableOutput) {\n const cell = parse(source.slice(rStart, rEnd), state);\n state.inTable = prevInTable;\n return [cell];\n }\n\n const cells: ParserResult[][] = [];\n const len = source.length;\n let cellStart = rStart;\n let i = rStart;\n\n /**\n * Parse one cell, dropping the padding an aligned table pads it with.\n *\n * GFM strips a cell's surrounding whitespace, so trimming is both the correct\n * output and the cheap one: the padding of a column-aligned table is a large\n * share of its bytes, and every space handed to `parse` costs a rule dispatch,\n * a capture and a lookbehind update. `trim` is a native scan, and walking the\n * padding back from the delimiter in JavaScript instead costs half as much\n * again as the whole row scan.\n */\n const parseCell = (from: number, to: number): ParserResult[] => {\n const cell = source.slice(from, to).trim();\n return cell === '' ? [] : parse(cell, state);\n };\n\n // Cursors on the only three characters that can end a run of ordinary cell\n // text. Each moves forward only, so the row is swept three times in total by\n // `indexOf` — cheaper than re-entering the regex engine once per character\n // found, which is what an anchored run scanner costs on a wide row.\n let pipeAt = -1;\n let escapeAt = -1;\n let backtickAt = -1;\n\n while (i < rEnd) {\n if (pipeAt < i) {\n const at = source.indexOf('|', i);\n pipeAt = at === -1 ? len : at;\n }\n if (escapeAt < i) {\n const at = source.indexOf('\\\\', i);\n escapeAt = at === -1 ? len : at;\n }\n if (backtickAt < i) {\n const at = source.indexOf('`', i);\n backtickAt = at === -1 ? len : at;\n }\n\n i = Math.min(pipeAt, escapeAt, backtickAt);\n if (i >= rEnd) break;\n\n // Escape: \\|\n if (i === escapeAt) {\n i += i + 1 < rEnd ? 2 : 1;\n continue;\n }\n // Code span: `...`\n if (i === backtickAt) {\n let backticks = 0;\n while (i < rEnd && source.charCodeAt(i) === 96) {\n backticks++;\n i++;\n }\n let found = false;\n while (i < rEnd && !found) {\n let closeBackticks = 0;\n while (i < rEnd && source.charCodeAt(i) === 96) {\n closeBackticks++;\n i++;\n }\n if (closeBackticks === backticks) {\n found = true;\n } else if (closeBackticks === 0) {\n i++;\n }\n }\n continue;\n }\n // Cell delimiter: |\n cells.push(parseCell(cellStart, i));\n i++;\n cellStart = i;\n }\n\n cells.push(parseCell(cellStart, rEnd));\n\n state.inTable = prevInTable;\n return cells;\n};\n\n/**\n * Parse table cells (multiple rows).\n */\nexport const parseTableCells = (\n source: string,\n parse: NestedParser,\n state: ParseState\n): ParserResult[][][] => {\n if (!source) return [];\n\n const result: ParserResult[][][] = [];\n let start = 0;\n const len = source.length;\n\n while (start < len) {\n let nextNewline = source.indexOf('\\n', start);\n if (nextNewline === -1) nextNewline = len;\n const rowText = source.slice(start, nextNewline);\n start = nextNewline + 1;\n\n // Check if row has non-whitespace content\n let hasContent = false;\n for (let j = 0; j < rowText.length; j++) {\n const c = rowText.charCodeAt(j);\n if (c !== 32 && c !== 9 && c !== 13) {\n hasContent = true;\n break;\n }\n }\n if (!hasContent) continue;\n\n result.push(parseTableRow(rowText, parse, state, true));\n }\n\n return result;\n};\n\n// ============================================================================\n// PARSING HELPERS\n// ============================================================================\n\n/**\n * Check if a rule qualifies for the current source and state.\n */\nexport const qualifies = (\n source: string,\n state: ParseState,\n qualify: NonNullable<Rule<any>['_qualify']>\n): boolean => {\n if (Array.isArray(qualify)) {\n for (let i = 0; i < qualify.length; i++) {\n if (startsWith(source, qualify[i]!)) return true;\n }\n\n return false;\n }\n\n return (qualify as (source: string, state: ParseState) => boolean)(\n source,\n state\n );\n};\n\n/**\n * Marks a matcher function as eligible for being run inside an inline context.\n */\nexport const allowInline = <T extends (...args: any[]) => any>(\n fn: T\n): T & { inline: 1 } => {\n (fn as any).inline = 1;\n return fn as T & { inline: 1 };\n};\n\n/**\n * Creates a match function for an inline scoped element from a regex.\n */\nexport const inlineRegex = (regex: RegExp) =>\n allowInline((source: string, state: ParseState): RegExpMatchArray | null => {\n if (state.inline) {\n return regex.exec(source);\n } else {\n return null;\n }\n });\n\n/**\n * Creates a match function for inline elements except links.\n */\nexport const simpleInlineRegex = (regex: RegExp) =>\n allowInline((source: string, state: ParseState): RegExpMatchArray | null => {\n if (state.inline || state.simple) {\n return regex.exec(source);\n } else {\n return null;\n }\n });\n\n/**\n * Creates a match function for a block scoped element from a regex.\n */\nexport const blockRegex =\n (regex: RegExp) =>\n (source: string, state: ParseState): RegExpMatchArray | null => {\n if (state.inline || state.simple) {\n return null;\n } else {\n return regex.exec(source);\n }\n };\n\n/**\n * Creates a match function from a regex, ignoring block/inline scope.\n */\nexport const anyScopeRegex = (\n fn: RegExp | ((source: string, state: ParseState) => RegExpMatchArray | null)\n) =>\n allowInline((source: string, state: ParseState): RegExpMatchArray | null => {\n if (typeof fn === 'function') {\n return fn(source, state);\n }\n return fn.exec(source);\n });\n\n/**\n * Parse inline content (including links).\n */\nexport const parseInline = (\n parse: NestedParser,\n children: string,\n state: ParseState\n): ParserResult[] => {\n const isCurrentlyInline = state.inline ?? false;\n const isCurrentlySimple = state.simple ?? false;\n state.inline = true;\n state.simple = true;\n const result = parse(children, state);\n state.inline = isCurrentlyInline;\n state.simple = isCurrentlySimple;\n\n return result;\n};\n\n/**\n * Parse simple inline content (no links).\n */\nexport const parseSimpleInline = (\n parse: NestedParser,\n children: string,\n state: ParseState\n): ParserResult[] => {\n const isCurrentlyInline = state.inline ?? false;\n const isCurrentlySimple = state.simple ?? false;\n\n state.inline = false;\n state.simple = true;\n const result = parse(children, state);\n state.inline = isCurrentlyInline;\n state.simple = isCurrentlySimple;\n\n return result;\n};\n\n/**\n * Parse block content.\n */\nexport const parseBlock = (\n parse: NestedParser,\n children: string,\n state: ParseState = {}\n): ParserResult[] => {\n const isCurrentlyInline = state.inline || false;\n state.inline = false;\n const normalizedChildren = trimEnd(children);\n const needsTerminator = /\\n\\n$/.test(normalizedChildren) === false;\n const blockInput = needsTerminator\n ? normalizedChildren.endsWith('\\n')\n ? `${normalizedChildren}\\n`\n : `${normalizedChildren}\\n\\n`\n : normalizedChildren;\n\n const result = parse(blockInput, state);\n state.inline = isCurrentlyInline;\n\n return result;\n};\n\n/**\n * Helper to parse capture group 2 as inline content.\n */\nexport const parseCaptureInline = (\n capture: RegExpMatchArray,\n parse: NestedParser,\n state: ParseState\n): { children: ParserResult[] } => {\n return {\n children: parseInline(parse, capture[2] ?? '', state),\n };\n};\n\n/**\n * Helper that captures nothing (empty object).\n */\nexport const captureNothing = (): Record<string, never> => ({});\n\n/**\n * Helper that renders nothing (null).\n */\nexport const renderNothing = (): null => null;\n\n/**\n * Check if any regex in a list matches the input.\n */\n/**\n * A block-syntax probe: either a regex to test, or a predicate for the rules\n * whose regex was replaced by a linear scanner.\n */\nexport type BlockSyntaxProbe = RegExp | ((input: string) => boolean);\n\nexport const some = (probes: BlockSyntaxProbe[], input: string): boolean => {\n for (let i = 0; i < probes.length; i++) {\n const probe = probes[i]!;\n if (typeof probe === 'function' ? probe(input) : probe.test(input)) {\n return true;\n }\n }\n return false;\n};\n"],"mappings":";;;;;;AAwBA,MAAa,WAAW,QAAwB;CAC9C,IAAI,MAAM,IAAI;CAEd,OAAO,MAAM,KAAK,IAAI,WAAW,MAAM,CAAC,KAAK,IAAI;CAEjD,OAAO,QAAQ,IAAI,SAAS,MAAM,IAAI,MAAM,GAAG,GAAG;AACpD;;;;AAKA,MAAa,cAAc,KAAa,WAA4B;CAClE,OAAO,IAAI,WAAW,MAAM;AAC9B;;;;AAKA,MAAa,WAAW,QAAwB;CAC9C,MAAM,QAAQ,IAAI;CAElB,KACG,UAAU,QAAO,UAAU,QAC5B,IAAI,UAAU,KACd,IAAI,IAAI,SAAS,OAAO,OAExB,OAAO,IAAI,MAAM,GAAG,EAAE;CAGxB,OAAO;AACT;;;;AAKA,MAAa,kBAAgD,cAC1D,aAAa,UAAU,QAAQ,IAAI,MAAM,KACtC,U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BAE6B,KAAK;CACtC,MAAM,SAAS;CAEf,OAAO;AACT;;;;AAKA,MAAa,sBACX,SACA,OACA,UACiC;CACjC,OAAO,EACL,UAAU,YAAY,OAAO,QAAQ,MAAM,IAAI,KAAK,EACtD;AACF;;;;AAKA,MAAa,wBAA+C,CAAC;;;;AAK7D,MAAa,sBAA4B;AAWzC,MAAa,QAAQ,QAA4B,UAA2B;CAC1E,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;EACrB,IAAI,OAAO,UAAU,aAAa,MAAM,KAAK,IAAI,MAAM,KAAK,KAAK,GAC/D,OAAO;CAEX;CACA,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dictionary, DictionarySelector, DictionaryVariantChain, DictionaryVariantValue,
|
|
1
|
+
import { Dictionary, DictionarySelector, DictionaryVariantChain, DictionaryVariantValue, ProviderVariantBase, QualifiedDictionaryGroup } from "@intlayer/types/dictionary";
|
|
2
2
|
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
3
|
//#region src/dictionaryManipulator/qualifiedDictionary.d.ts
|
|
4
4
|
/**
|
|
@@ -117,7 +117,7 @@ export declare const parseDictionarySelector: <L extends LocalesValues>(localeOr
|
|
|
117
117
|
* @param providerVariant - The `variant` prop of the surrounding provider.
|
|
118
118
|
* @param dictionaryKey - The key being read.
|
|
119
119
|
*/
|
|
120
|
-
export declare const resolveProviderVariant: (providerVariant:
|
|
120
|
+
export declare const resolveProviderVariant: (providerVariant: ProviderVariantBase | undefined, dictionaryKey: string) => DictionaryVariantChain | undefined;
|
|
121
121
|
/**
|
|
122
122
|
* Builds the effective second argument of a dictionary read by layering the
|
|
123
123
|
* provider defaults under the call-site one — the single place the `locale` and
|
|
@@ -135,7 +135,7 @@ export declare const resolveProviderVariant: (providerVariant: ProviderVariant |
|
|
|
135
135
|
export declare const resolveDictionaryArgument: (params: {
|
|
136
136
|
localeOrSelector?: LocalesValues | DictionarySelector;
|
|
137
137
|
contextLocale?: LocalesValues;
|
|
138
|
-
contextVariant?:
|
|
138
|
+
contextVariant?: ProviderVariantBase;
|
|
139
139
|
dictionaryKey: string;
|
|
140
140
|
}) => LocalesValues | DictionarySelector | undefined;
|
|
141
141
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qualifiedDictionary.d.ts","names":[],"sources":["../../../src/dictionaryManipulator/qualifiedDictionary.ts"],"mappings":";;;;;;;qBAgBa;;;;;;qBAOA;;;;;;;;;;;;;;;;;;;qBAqDA,mBAAgB,SAClB;;;;;;;;;;;;;qBA4BE,wBAAqB,SACvB;;;;;;;;;;;;;;;;qBA0BE,4BAAyB,+BACP,sBACP;;;;;;qBA4CX,6BAA0B,mBAEpC,SAAS;;;;;;;;;;;;qBAkBC,4BAAyB,OAC7B,0BAAwB,wBAE9B;;;;;;;;;;;;;;;;qBAkCU,6BAA0B,mBAClB,aAAa,0BAAwB,WAC7C,uBACV,aAAa;;;;;qBAoDH,0BAA2B,UAAU,eAAa,mBAC1C,IAAI;EACpB,SAAS;EAAG,WAAW;;;;;;;;;;;;;;;;;qBA0Bf,yBAAsB,iBAChB,
|
|
1
|
+
{"version":3,"file":"qualifiedDictionary.d.ts","names":[],"sources":["../../../src/dictionaryManipulator/qualifiedDictionary.ts"],"mappings":";;;;;;;qBAgBa;;;;;;qBAOA;;;;;;;;;;;;;;;;;;;qBAqDA,mBAAgB,SAClB;;;;;;;;;;;;;qBA4BE,wBAAqB,SACvB;;;;;;;;;;;;;;;;qBA0BE,4BAAyB,+BACP,sBACP;;;;;;qBA4CX,6BAA0B,mBAEpC,SAAS;;;;;;;;;;;;qBAkBC,4BAAyB,OAC7B,0BAAwB,wBAE9B;;;;;;;;;;;;;;;;qBAkCU,6BAA0B,mBAClB,aAAa,0BAAwB,WAC7C,uBACV,aAAa;;;;;qBAoDH,0BAA2B,UAAU,eAAa,mBAC1C,IAAI;EACpB,SAAS;EAAG,WAAW;;;;;;;;;;;;;;;;;qBA0Bf,yBAAsB,iBAChB,iCAA+B,0BAE/C;;;;;;;;;;;;;;;qBA0BU,4BAAyB;EACpC,mBAAmB,gBAAgB;EACnC,gBAAgB;EAChB,iBAAiB;EACjB;MACE,gBAAgB;;;;;qBAqCP,gCAA6B,WAC7B"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -101,12 +101,12 @@ import { getRewriteRules } from "./localization/rewriteMatch.js";
|
|
|
101
101
|
import { LocalizedPathResult, getInternalPath, getRewritePath, resolveLocalizedPath } from "./localization/rewriteUtils.js";
|
|
102
102
|
import { validatePrefix } from "./localization/validatePrefix.js";
|
|
103
103
|
import "./localization/index.js";
|
|
104
|
+
import { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, DO_NOT_PROCESS_HTML_ELEMENTS, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, ListType, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, PriorityValue, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleScope, RuleScopeValue, RuleType, RuleTypeValue, SCOPE_BLOCK, SCOPE_BOTH, SCOPE_INLINE, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex } from "./markdown/constants.js";
|
|
104
105
|
import { BlockQuoteNode, BoldTextNode, BreakLineNode, BreakThematicNode, CodeBlockNode, CodeFencedNode, CodeInlineNode, CompileOptions, ComponentOverrides, CustomComponentNode, ElementType, EscapedTextNode, FootnoteNode, FootnoteReferenceNode, GFMTaskNode, HTMLCommentNode, HTMLNode, HTMLSelfClosingNode, HTMLTag, HeadingNode, HeadingSetextNode, ImageNode, ItalicTextNode, LinkAngleBraceNode, LinkBareURLNode, LinkNode, MarkdownContext, MarkdownOptions, MarkdownRuntime, MarkedTextNode, NestedParser, NewlineNode, OrderedListNode, ParagraphNode, ParseState, Parser, ParserResult, ReferenceImageNode, ReferenceLinkNode, ReferenceNode, RenderRuleHook, Rule, RuleOutput, Rules, StrikethroughTextNode, TableNode, TableSeparatorNode, TextNode, UnorderedListNode } from "./markdown/types.js";
|
|
105
|
-
import { MarkdownReferences, ParsedMarkdown, compile, compileWithOptions, createCompiler, parseMarkdown, renderMarkdownAst } from "./markdown/compiler.js";
|
|
106
|
-
import { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_OPENING_TAG_R, CUSTOM_COMPONENT_R, DO_NOT_PROCESS_HTML_ELEMENTS, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_BLOCK_OPENING_TAG_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_SELF_CLOSING_OPENING_TAG_R, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, ListType, NAMED_CODES_TO_UNICODE, NORMALIZE_WHITESPACE_R, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, PriorityValue, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, RuleTypeValue, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex } from "./markdown/constants.js";
|
|
107
106
|
import { parserFor } from "./markdown/parser.js";
|
|
108
107
|
import { createRenderer, renderFor } from "./markdown/renderer.js";
|
|
109
|
-
import {
|
|
108
|
+
import { MarkdownReferences, ParsedMarkdown, compile, compileWithOptions, createCompiler, getRuleSet, parseMarkdown, renderMarkdownAst } from "./markdown/compiler.js";
|
|
109
|
+
import { BlockSyntaxProbe, allowInline, anyScopeRegex, attributeValueToNodePropValue, blockRegex, captureNothing, cx, get, inlineRegex, normalizeAttributeKey, normalizeWhitespace, parseBlock, parseCaptureInline, parseInline, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, qualifies, renderNothing, sanitizer, simpleInlineRegex, slugify, some, startsWith, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, unquote } from "./markdown/utils.js";
|
|
110
110
|
import "./markdown/index.js";
|
|
111
111
|
import { JsonValue, icuToIntlayerFormatter, intlayerToICUFormatter } from "./messageFormat/ICU.js";
|
|
112
112
|
import { i18nextToIntlayerFormatter, intlayerToI18nextFormatter } from "./messageFormat/i18next.js";
|
|
@@ -123,4 +123,4 @@ import { CookieBuildAttributes, LocaleStorage, LocaleStorageClient, LocaleStorag
|
|
|
123
123
|
import { YamlRecord, YamlValue, parseYaml } from "./utils/parseYaml.js";
|
|
124
124
|
import { stringifyYaml } from "./utils/stringifyYaml.js";
|
|
125
125
|
import "./utils/index.js";
|
|
126
|
-
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, type BlockQuoteNode, type BoldTextNode, type BreakLineNode, type BreakThematicNode, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R,
|
|
126
|
+
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, type BlockQuoteNode, BlockSyntaxProbe, type BoldTextNode, type BreakLineNode, type BreakThematicNode, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CachedIntl, CachedIntl as Intl, type CodeBlockNode, type CodeFencedNode, type CodeInlineNode, type CompileOptions, type ComponentOverrides, ConditionCond, ConditionContent, ConditionContentStates, CookieBuildAttributes, type CustomComponentNode, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, FileCond, type FileContent, type FileContentConstructor, type FootnoteNode, type FootnoteReferenceNode, type GFMTaskNode, GFM_TASK_R, Gender, GenderCond, GenderContent, GenderContentStates, type GenerateSitemapOptions, GetNestingResult, type GetPrefixOptions, type GetPrefixResult, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, type HTMLCommentNode, HTMLContent, HTMLContentConstructor, type HTMLNode, type HTMLSelfClosingNode, type HTMLTag, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_TAGS, type HeadingNode, type HeadingSetextNode, IInterpreterPlugin, IInterpreterPluginState, INLINE_SKIP_R, INTERPOLATION_R, type ImageNode, InsertionCond, InsertionContent, InsertionContentConstructor, InterpolableNode, IntlConstructorName, IsAny, type ItalicTextNode, JsonValue, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListFormatOptions, ListType, type LocaleDomainMap, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, MarkdownReferences, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, NestedFieldReferences, type NestedParser, type NewlineNode, NodeProps, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, type OrderedListNode, PARAGRAPH_R, PRELOADED_DYNAMIC_KEY, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, PlainDynamicLoaderMap, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, PreloadableDynamicLoaderMap, PreloadedDynamicEntry, Priority, PriorityValue, type ProxyMode, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, QualifiedDynamicLoaderMap, QualifiedDynamicLoaderTree, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, type ReferenceImageNode, type ReferenceLinkNode, type ReferenceNode, type RenderRuleHook, ResolvedDynamicLoader, type Rule, type RuleOutput, RuleScope, RuleScopeValue, RuleType, RuleTypeValue, type Rules, SCOPE_BLOCK, SCOPE_BOTH, SCOPE_INLINE, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, SelectCond, SelectContent, SelectContentStates, SelectSelector, type SitemapUrlEntry, type StrikethroughTextNode, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, type TableNode, type TableSeparatorNode, TaggedMessageToken, type TextNode, TranslationCond, TranslationContent, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, UnionKeys, type UnorderedListNode, VOID_HTML_ELEMENTS, ValidDotPathsFor, ValueAtKey, WrappedIntl, YamlRecord, YamlValue, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, findPlainDynamicLoader, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryAsync, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDictionaryTransformCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getIntlayerAsync, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPluginsCacheKey, getPlural, getPrefix, getPreloadLocale, getPreloadedDictionary, getReplacedValuesContent, getRewritePath, getRewriteRules, getRuleSet, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isDeclaredLocale, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, readTransformCache, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveBrowserLocale, resolveDictionaryArgument, resolveEffectiveVariantId, resolveLocalizedPath, resolveMessage, resolveMessageNode, resolvePlainDynamicLoader, resolveProviderVariant, resolveProxyMode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, serializeVariantChain, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter, writeTransformCache };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluralContentState } from "../transpiler/plural/plural.js";
|
|
2
|
-
import { LocalesValues } from "
|
|
3
|
-
import { DeclaredLocales } from "@intlayer/types";
|
|
2
|
+
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import { DeclaredLocales as DeclaredLocales$1 } from "@intlayer/types";
|
|
4
4
|
//#region src/interpreter/getPlural.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Picks content from a plural map based on a count and locale, using CLDR
|
|
@@ -17,6 +17,6 @@ import { DeclaredLocales } from "@intlayer/types";
|
|
|
17
17
|
* // '{{count}} items'
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare const getPlural: <const L extends LocalesValues = DeclaredLocales>(pluralContent: PluralContentState<string>, count: number, locale: L) => string;
|
|
20
|
+
export declare const getPlural: <const L extends LocalesValues = DeclaredLocales$1>(pluralContent: PluralContentState<string>, count: number, locale: L) => string;
|
|
21
21
|
//#endregion
|
|
22
22
|
//# sourceMappingURL=getPlural.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPlural.d.ts","names":[],"sources":["../../../src/interpreter/getPlural.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBAuBa,kBAAmB,UAAU,gBAAgB,
|
|
1
|
+
{"version":3,"file":"getPlural.d.ts","names":[],"sources":["../../../src/interpreter/getPlural.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBAuBa,kBAAmB,UAAU,gBAAgB,mBAAe,eACxD,4BAA0B,eAC5B,QACL"}
|
|
@@ -1,9 +1,52 @@
|
|
|
1
1
|
import { CompileOptions, MarkdownContext, MarkdownOptions, MarkdownRuntime } from "./types.js";
|
|
2
|
+
import { parserFor } from "./parser.js";
|
|
3
|
+
import { renderFor } from "./renderer.js";
|
|
2
4
|
//#region src/markdown/compiler.d.ts
|
|
5
|
+
type CreateElementFunction = (tag: any, props: Record<string, any> | null, ...children: any[]) => unknown;
|
|
3
6
|
type FootnoteDef = {
|
|
4
7
|
footnote: string;
|
|
5
8
|
identifier: string;
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Footnote and reference tables belonging to the document currently being
|
|
12
|
+
* parsed or rendered. Rules reach them through a ref so a rule set can outlive
|
|
13
|
+
* a single document and be reused.
|
|
14
|
+
*/
|
|
15
|
+
type DocumentScope = {
|
|
16
|
+
footnotes: FootnoteDef[];
|
|
17
|
+
references: MarkdownReferences;
|
|
18
|
+
};
|
|
19
|
+
type DocumentScopeRef = {
|
|
20
|
+
current: DocumentScope;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A cached rule set, together with the values it was built from. The signature
|
|
24
|
+
* holds every input that changes the shape of the rules; anything else (the
|
|
25
|
+
* markdown itself, the document scope) is free to vary between uses.
|
|
26
|
+
*/
|
|
27
|
+
type DocumentParser = ReturnType<typeof parserFor>;
|
|
28
|
+
type DocumentEmitter = ReturnType<typeof renderFor>;
|
|
29
|
+
type RuleSetCacheEntry = {
|
|
30
|
+
/** The inputs this set was built from, compared field by field on lookup. */
|
|
31
|
+
ctx: MarkdownContext<any>;
|
|
32
|
+
options: MarkdownOptions;
|
|
33
|
+
parseOnly: boolean;
|
|
34
|
+
createElement: CreateElementFunction;
|
|
35
|
+
scope: DocumentScopeRef;
|
|
36
|
+
/**
|
|
37
|
+
* Built with the rules, not per call. `parserFor` resolves precedence and
|
|
38
|
+
* fills the first-character dispatch tables, and `renderFor` walks the rule
|
|
39
|
+
* set — repeating either for every string was most of what compiling a
|
|
40
|
+
* dictionary of short strings cost.
|
|
41
|
+
*/
|
|
42
|
+
parse: DocumentParser;
|
|
43
|
+
emit: DocumentEmitter;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Returns the rule set for these options, building it only when no cached set
|
|
47
|
+
* was made from the same inputs.
|
|
48
|
+
*/
|
|
49
|
+
export declare const getRuleSet: (ctx: MarkdownContext<any>, options: MarkdownOptions, parseOnly: boolean) => RuleSetCacheEntry;
|
|
7
50
|
/** Link/image reference definitions (`[id]: target "title"`) collected while parsing. */
|
|
8
51
|
export type MarkdownReferences = Record<string, {
|
|
9
52
|
target: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","names":[],"sources":["../../../src/markdown/compiler.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","names":[],"sources":["../../../src/markdown/compiler.ts"],"mappings":";;;;KAgHK,yBACH,UACA,OAAO,+BACJ;KAGA;EAAgB;EAAkB;;;;;;;KA2KlC;EACH,WAAW;EACX,YAAY;;KAGT;EAAqB,SAAS;;;;;;;KAY9B,iBAAiB,kBAAkB;KACnC,kBAAkB,kBAAkB;KAEpC;;EAEH,KAAK;EACL,SAAS;EACT;EACA,eAAe;EACf,OAAO;;;;;;;EAOP,OAAO;EACP,MAAM;;;;;;qBAsCK,aAAU,KAChB,sBAAoB,SAChB,iBAAe,uBAEvB;;YA2/BS,qBAAqB;EAE7B;EAAgB;;YAGR;EACV;EACA,WAAW;;;;;;EAMX,YAAY;EACZ;;qBAsSW,gBAAa,kBACR,KACX,sBAAoB,UAChB,oBACR;qBAiBU,oBAAiB,QACpB,gBAAc,KACjB,sBAAoB,UAChB;qBAaE,UAAO,kBACF,KACX,sBAAoB,UAChB;qBA8BE,iBAAc,KACnB,0BAAoB,kBACT,UAAY;qBAGlB,qBAAkB,kBACb,SACP,iBAAe,UACf"}
|
|
@@ -61,6 +61,22 @@ export declare const Priority: {
|
|
|
61
61
|
readonly MIN: 4;
|
|
62
62
|
};
|
|
63
63
|
export type PriorityValue = (typeof Priority)[keyof typeof Priority];
|
|
64
|
+
/**
|
|
65
|
+
* Parsing scope for markdown rules.
|
|
66
|
+
* Bitmask representation for fast bitwise checking and bundle minification.
|
|
67
|
+
* - BLOCK (1): evaluated only when !state.inline && !state.simple
|
|
68
|
+
* - INLINE (2): evaluated only when state.inline || state.simple
|
|
69
|
+
* - BOTH (3): evaluated in both scopes (default)
|
|
70
|
+
*/
|
|
71
|
+
export declare const RuleScope: {
|
|
72
|
+
readonly BLOCK: 1;
|
|
73
|
+
readonly INLINE: 2;
|
|
74
|
+
readonly BOTH: 3;
|
|
75
|
+
};
|
|
76
|
+
export declare const SCOPE_BLOCK: 1;
|
|
77
|
+
export declare const SCOPE_INLINE: 2;
|
|
78
|
+
export declare const SCOPE_BOTH: 3;
|
|
79
|
+
export type RuleScopeValue = (typeof RuleScope)[keyof typeof RuleScope] | 'block' | 'inline' | 'both';
|
|
64
80
|
/**
|
|
65
81
|
* Map of HTML attributes to their JSX prop equivalents.
|
|
66
82
|
* Some renderers use camelCase for certain attributes.
|
|
@@ -107,20 +123,24 @@ export declare const GFM_TASK_R: RegExp;
|
|
|
107
123
|
export declare const HEADING_R: RegExp;
|
|
108
124
|
export declare const HEADING_ATX_COMPLIANT_R: RegExp;
|
|
109
125
|
export declare const HEADING_SETEXT_R: RegExp;
|
|
110
|
-
|
|
126
|
+
/** HTML patterns */
|
|
111
127
|
export declare const HTML_CHAR_CODE_R: RegExp;
|
|
112
128
|
export declare const HTML_COMMENT_R: RegExp;
|
|
113
129
|
export declare const HTML_CUSTOM_ATTR_R: RegExp;
|
|
114
|
-
export declare const HTML_SELF_CLOSING_ELEMENT_R: RegExp;
|
|
115
|
-
/** Custom component pattern */
|
|
116
|
-
export declare const CUSTOM_COMPONENT_R: RegExp;
|
|
117
130
|
/** Interpolation */
|
|
118
131
|
export declare const INTERPOLATION_R: RegExp;
|
|
119
132
|
/** Link patterns */
|
|
120
133
|
export declare const LINK_AUTOLINK_BARE_URL_R: RegExp;
|
|
121
134
|
export declare const LINK_AUTOLINK_R: RegExp;
|
|
122
135
|
export declare const CAPTURE_LETTER_AFTER_HYPHEN: RegExp;
|
|
123
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* Table patterns.
|
|
138
|
+
*
|
|
139
|
+
* The row scans spell "any character but a newline" as `[^\n]` rather than `.`:
|
|
140
|
+
* `.` is a four-range exclusion, and matching it over rows this wide costs a
|
|
141
|
+
* third more than the single-range class. It is also the more faithful reading
|
|
142
|
+
* — only `\n` ends a line here, and `\r` is normalized away before parsing.
|
|
143
|
+
*/
|
|
124
144
|
export declare const NP_TABLE_R: RegExp;
|
|
125
145
|
export declare const TABLE_TRIM_PIPES: RegExp;
|
|
126
146
|
export declare const TABLE_CENTER_ALIGN: RegExp;
|
|
@@ -132,20 +152,10 @@ export declare const PARAGRAPH_R: RegExp;
|
|
|
132
152
|
export declare const REFERENCE_IMAGE_OR_LINK: RegExp;
|
|
133
153
|
export declare const REFERENCE_IMAGE_R: RegExp;
|
|
134
154
|
export declare const REFERENCE_LINK_R: RegExp;
|
|
135
|
-
/**
|
|
136
|
-
* Cheap prefix probes used to reject a rule before its full (and far more
|
|
137
|
-
* expensive) block regex runs. Kept as module constants so the parser's inner
|
|
138
|
-
* loop never allocates a `RegExp` per candidate position.
|
|
139
|
-
*/
|
|
140
|
-
export declare const HTML_BLOCK_OPENING_TAG_R: RegExp;
|
|
141
|
-
export declare const HTML_SELF_CLOSING_OPENING_TAG_R: RegExp;
|
|
142
|
-
export declare const CUSTOM_COMPONENT_OPENING_TAG_R: RegExp;
|
|
143
155
|
/** Block detection */
|
|
144
156
|
export declare const SHOULD_RENDER_AS_BLOCK_R: RegExp;
|
|
145
|
-
/**
|
|
157
|
+
/** Tabs, which `normalizeWhitespace` widens to four spaces. */
|
|
146
158
|
export declare const TAB_R: RegExp;
|
|
147
|
-
/** Every character `normalizeWhitespace` rewrites, so it needs a single pass. */
|
|
148
|
-
export declare const NORMALIZE_WHITESPACE_R: RegExp;
|
|
149
159
|
export declare const TRIM_STARTING_NEWLINES: RegExp;
|
|
150
160
|
export declare const HTML_LEFT_TRIM_AMOUNT_R: RegExp;
|
|
151
161
|
/** List patterns */
|
|
@@ -154,7 +164,6 @@ export declare const UNORDERED_LIST_BULLET = "(?:[*+-])";
|
|
|
154
164
|
/** Text formatting patterns */
|
|
155
165
|
export declare const TEXT_ESCAPED_R: RegExp;
|
|
156
166
|
export declare const UNESCAPE_R: RegExp;
|
|
157
|
-
export declare const TEXT_PLAIN_R: RegExp;
|
|
158
167
|
/** Shortcode pattern */
|
|
159
168
|
export declare const SHORTCODE_R: RegExp;
|
|
160
169
|
export type ListType = 1 | 2;
|