@markdy/core 0.7.8 → 0.7.10
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/dist/index.js +58 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -235,16 +235,17 @@ var ParseError = class extends Error {
|
|
|
235
235
|
};
|
|
236
236
|
function stripComment(line) {
|
|
237
237
|
let depth = 0;
|
|
238
|
-
let
|
|
238
|
+
let stringQuote = null;
|
|
239
239
|
let lastNonSpace = "";
|
|
240
240
|
for (let i = 0; i < line.length; i++) {
|
|
241
241
|
const ch = line[i];
|
|
242
|
-
if (ch === '"') {
|
|
243
|
-
|
|
242
|
+
if ((ch === '"' || ch === "'") && !isEscapedChar(line, i)) {
|
|
243
|
+
if (stringQuote === ch) stringQuote = null;
|
|
244
|
+
else if (stringQuote === null) stringQuote = ch;
|
|
244
245
|
lastNonSpace = ch;
|
|
245
246
|
continue;
|
|
246
247
|
}
|
|
247
|
-
if (
|
|
248
|
+
if (stringQuote !== null) continue;
|
|
248
249
|
if (ch === "(") {
|
|
249
250
|
depth++;
|
|
250
251
|
lastNonSpace = ch;
|
|
@@ -263,15 +264,16 @@ function stripComment(line) {
|
|
|
263
264
|
function splitByComma(s) {
|
|
264
265
|
const parts = [];
|
|
265
266
|
let depth = 0;
|
|
266
|
-
let
|
|
267
|
+
let stringQuote = null;
|
|
267
268
|
let start = 0;
|
|
268
269
|
for (let i = 0; i < s.length; i++) {
|
|
269
270
|
const ch = s[i];
|
|
270
|
-
if (ch === '"') {
|
|
271
|
-
|
|
271
|
+
if ((ch === '"' || ch === "'") && !isEscapedChar(s, i)) {
|
|
272
|
+
if (stringQuote === ch) stringQuote = null;
|
|
273
|
+
else if (stringQuote === null) stringQuote = ch;
|
|
272
274
|
continue;
|
|
273
275
|
}
|
|
274
|
-
if (
|
|
276
|
+
if (stringQuote !== null) continue;
|
|
275
277
|
if (ch === "(") depth++;
|
|
276
278
|
else if (ch === ")") depth--;
|
|
277
279
|
else if (ch === "," && depth === 0) {
|
|
@@ -284,8 +286,9 @@ function splitByComma(s) {
|
|
|
284
286
|
}
|
|
285
287
|
function parseValue(s) {
|
|
286
288
|
const t = s.trim();
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
const quoted = parseQuotedLiteral(t);
|
|
290
|
+
if (quoted !== null) {
|
|
291
|
+
return quoted;
|
|
289
292
|
}
|
|
290
293
|
if (t.startsWith("(") && t.endsWith(")")) {
|
|
291
294
|
const inner = t.slice(1, -1);
|
|
@@ -299,6 +302,47 @@ function parseValue(s) {
|
|
|
299
302
|
if (!Number.isNaN(n) && t !== "") return n;
|
|
300
303
|
return t;
|
|
301
304
|
}
|
|
305
|
+
function isEscapedChar(s, idx) {
|
|
306
|
+
let slashCount = 0;
|
|
307
|
+
for (let i = idx - 1; i >= 0 && s[i] === "\\"; i--) {
|
|
308
|
+
slashCount++;
|
|
309
|
+
}
|
|
310
|
+
return slashCount % 2 === 1;
|
|
311
|
+
}
|
|
312
|
+
function parseQuotedLiteral(token) {
|
|
313
|
+
if (token.length < 2) return null;
|
|
314
|
+
const quote2 = token[0];
|
|
315
|
+
if (quote2 !== '"' && quote2 !== "'" || token[token.length - 1] !== quote2) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
if (isEscapedChar(token, token.length - 1)) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
return unescapeQuotedContent(token.slice(1, -1), quote2);
|
|
322
|
+
}
|
|
323
|
+
function unescapeQuotedContent(content, quote2) {
|
|
324
|
+
let out = "";
|
|
325
|
+
for (let i = 0; i < content.length; i++) {
|
|
326
|
+
const ch = content[i];
|
|
327
|
+
if (ch !== "\\") {
|
|
328
|
+
out += ch;
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (i + 1 >= content.length) {
|
|
332
|
+
out += "\\";
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const next = content[++i];
|
|
336
|
+
if (next === "n") out += "\n";
|
|
337
|
+
else if (next === "r") out += "\r";
|
|
338
|
+
else if (next === "t") out += " ";
|
|
339
|
+
else if (next === "\\") out += "\\";
|
|
340
|
+
else if (next === quote2) out += quote2;
|
|
341
|
+
else if (next === '"' || next === "'") out += next;
|
|
342
|
+
else out += `\\${next}`;
|
|
343
|
+
}
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
302
346
|
var POSITIONAL_KEYS = {
|
|
303
347
|
say: ["text"],
|
|
304
348
|
throw: ["asset"]
|
|
@@ -729,7 +773,8 @@ function parseActorCallArgs(argsRaw) {
|
|
|
729
773
|
if (!argsRaw.trim()) return [];
|
|
730
774
|
return splitByComma(argsRaw).map((a) => {
|
|
731
775
|
const t = a.trim();
|
|
732
|
-
|
|
776
|
+
const q = parseQuotedLiteral(t);
|
|
777
|
+
return q ?? t;
|
|
733
778
|
});
|
|
734
779
|
}
|
|
735
780
|
function parseActorLine(raw, lineNum, ast) {
|
|
@@ -993,7 +1038,8 @@ function tryExpandSolePreset(source) {
|
|
|
993
1038
|
if (!fn) return null;
|
|
994
1039
|
const args = argsRaw ? splitByComma(argsRaw).map((a) => {
|
|
995
1040
|
const t = a.trim();
|
|
996
|
-
|
|
1041
|
+
const q = parseQuotedLiteral(t);
|
|
1042
|
+
return q ?? t;
|
|
997
1043
|
}) : [];
|
|
998
1044
|
return fn(args);
|
|
999
1045
|
}
|