ansimax 1.3.7 → 1.4.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/CHANGELOG.md +112 -0
- package/README.es.md +34 -2
- package/README.md +34 -2
- package/dist/index.d.mts +165 -1
- package/dist/index.d.ts +165 -1
- package/dist/index.js +315 -28
- package/dist/index.mjs +311 -28
- package/examples/all-in-one.cjs +1 -1
- package/examples/all-in-one.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -127,6 +127,7 @@ __export(index_exports, {
|
|
|
127
127
|
listPresets: () => listPresets,
|
|
128
128
|
loader: () => loader,
|
|
129
129
|
mapTree: () => mapTree,
|
|
130
|
+
markdown: () => markdown,
|
|
130
131
|
measureBlock: () => measureBlock,
|
|
131
132
|
measureTree: () => measureTree,
|
|
132
133
|
memoize: () => memoize,
|
|
@@ -142,6 +143,8 @@ __export(index_exports, {
|
|
|
142
143
|
padStart: () => padStart,
|
|
143
144
|
panels: () => panels,
|
|
144
145
|
parseFiglet: () => parseFiglet,
|
|
146
|
+
parseMarkdownBlocks: () => parseBlocks,
|
|
147
|
+
parseMarkdownInline: () => parseInline,
|
|
145
148
|
pauseListeners: () => pauseListeners,
|
|
146
149
|
presetNames: () => presetNames,
|
|
147
150
|
presets: () => presets,
|
|
@@ -149,6 +152,7 @@ __export(index_exports, {
|
|
|
149
152
|
rainbow: () => rainbow,
|
|
150
153
|
registerFont: () => registerFont,
|
|
151
154
|
registerPreset: () => registerPreset,
|
|
155
|
+
renderMarkdown: () => render,
|
|
152
156
|
renderPixelArt: () => renderPixelArt,
|
|
153
157
|
renderTree: () => renderTree,
|
|
154
158
|
renderTreeStream: () => renderTreeStream,
|
|
@@ -3400,7 +3404,7 @@ var spin = (text = "Loading", opts = {}) => {
|
|
|
3400
3404
|
const animInterval = Math.max(FRAME_MS, safeInterval);
|
|
3401
3405
|
acquireCursor();
|
|
3402
3406
|
const startTime = Date.now();
|
|
3403
|
-
const
|
|
3407
|
+
const render2 = () => {
|
|
3404
3408
|
if (stopped) return;
|
|
3405
3409
|
const elapsed = Date.now() - startTime;
|
|
3406
3410
|
frame2 = Math.floor(elapsed / animInterval) % frames2.length;
|
|
@@ -3410,8 +3414,8 @@ var spin = (text = "Loading", opts = {}) => {
|
|
|
3410
3414
|
const buf = createOutputBuffer().push("\r").push(screen.clearLine()).push(line).toString();
|
|
3411
3415
|
write(buf);
|
|
3412
3416
|
};
|
|
3413
|
-
|
|
3414
|
-
timer = setInterval(
|
|
3417
|
+
render2();
|
|
3418
|
+
timer = setInterval(render2, animInterval);
|
|
3415
3419
|
let abortedBySignal = false;
|
|
3416
3420
|
const onAbort = () => {
|
|
3417
3421
|
abortedBySignal = true;
|
|
@@ -3582,15 +3586,15 @@ var dots = (text = "Processing", opts = {}) => {
|
|
|
3582
3586
|
let count = 0;
|
|
3583
3587
|
let stopped = false;
|
|
3584
3588
|
let timer = null;
|
|
3585
|
-
const
|
|
3589
|
+
const render2 = () => {
|
|
3586
3590
|
if (stopped) return;
|
|
3587
3591
|
const dotStr = ".".repeat(count);
|
|
3588
3592
|
const colored = applyColor(dotStr, hex);
|
|
3589
3593
|
write("\r" + screen.clearLine() + text + colored);
|
|
3590
3594
|
count = (count + 1) % (max + 1);
|
|
3591
3595
|
};
|
|
3592
|
-
|
|
3593
|
-
timer = setInterval(
|
|
3596
|
+
render2();
|
|
3597
|
+
timer = setInterval(render2, Math.max(FRAME_MS, interval));
|
|
3594
3598
|
const onAbort = () => stopFn();
|
|
3595
3599
|
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
3596
3600
|
const stopFn = () => {
|
|
@@ -3622,15 +3626,15 @@ var custom = (frames2, text = "", opts = {}) => {
|
|
|
3622
3626
|
let timer = null;
|
|
3623
3627
|
const safeInterval = Math.max(FRAME_MS, interval);
|
|
3624
3628
|
const startTime = Date.now();
|
|
3625
|
-
const
|
|
3629
|
+
const render2 = () => {
|
|
3626
3630
|
if (stopped) return;
|
|
3627
3631
|
const elapsed = Date.now() - startTime;
|
|
3628
3632
|
frame2 = Math.floor(elapsed / safeInterval) % frames2.length;
|
|
3629
3633
|
const f = frames2[frame2] ?? "";
|
|
3630
3634
|
write("\r" + screen.clearLine() + applyColor(f, hex) + " " + text);
|
|
3631
3635
|
};
|
|
3632
|
-
|
|
3633
|
-
timer = setInterval(
|
|
3636
|
+
render2();
|
|
3637
|
+
timer = setInterval(render2, safeInterval);
|
|
3634
3638
|
const onAbort = () => stopFn();
|
|
3635
3639
|
if (signal) signal.addEventListener("abort", onAbort, { once: true });
|
|
3636
3640
|
const stopFn = () => {
|
|
@@ -3737,7 +3741,7 @@ var multi = (opts = {}) => {
|
|
|
3737
3741
|
let frame2 = 0;
|
|
3738
3742
|
let timer = null;
|
|
3739
3743
|
let lastLineCount = 0;
|
|
3740
|
-
const
|
|
3744
|
+
const render2 = () => {
|
|
3741
3745
|
if (lastLineCount > 0) {
|
|
3742
3746
|
write("\r" + cursor.up(lastLineCount) + screen.clearDown());
|
|
3743
3747
|
}
|
|
@@ -3759,8 +3763,8 @@ var multi = (opts = {}) => {
|
|
|
3759
3763
|
const start = () => {
|
|
3760
3764
|
if (timer) return;
|
|
3761
3765
|
acquireCursor();
|
|
3762
|
-
|
|
3763
|
-
timer = setInterval(
|
|
3766
|
+
render2();
|
|
3767
|
+
timer = setInterval(render2, interval);
|
|
3764
3768
|
};
|
|
3765
3769
|
const tick = () => {
|
|
3766
3770
|
if (!timer) start();
|
|
@@ -3784,35 +3788,35 @@ var multi = (opts = {}) => {
|
|
|
3784
3788
|
},
|
|
3785
3789
|
set text(v) {
|
|
3786
3790
|
item.text = v;
|
|
3787
|
-
|
|
3791
|
+
render2();
|
|
3788
3792
|
},
|
|
3789
3793
|
update(newText) {
|
|
3790
3794
|
item.text = newText;
|
|
3791
|
-
|
|
3795
|
+
render2();
|
|
3792
3796
|
},
|
|
3793
3797
|
succeed(t) {
|
|
3794
3798
|
item.state = "success";
|
|
3795
3799
|
if (t !== void 0) item.finalText = t;
|
|
3796
|
-
|
|
3800
|
+
render2();
|
|
3797
3801
|
setTimeout(() => {
|
|
3798
3802
|
items.delete(id);
|
|
3799
|
-
|
|
3803
|
+
render2();
|
|
3800
3804
|
checkEmpty();
|
|
3801
3805
|
}, interval);
|
|
3802
3806
|
},
|
|
3803
3807
|
fail(t) {
|
|
3804
3808
|
item.state = "fail";
|
|
3805
3809
|
if (t !== void 0) item.finalText = t;
|
|
3806
|
-
|
|
3810
|
+
render2();
|
|
3807
3811
|
setTimeout(() => {
|
|
3808
3812
|
items.delete(id);
|
|
3809
|
-
|
|
3813
|
+
render2();
|
|
3810
3814
|
checkEmpty();
|
|
3811
3815
|
}, interval);
|
|
3812
3816
|
},
|
|
3813
3817
|
stop() {
|
|
3814
3818
|
items.delete(id);
|
|
3815
|
-
|
|
3819
|
+
render2();
|
|
3816
3820
|
checkEmpty();
|
|
3817
3821
|
}
|
|
3818
3822
|
};
|
|
@@ -4122,7 +4126,7 @@ var live = (opts = {}) => {
|
|
|
4122
4126
|
let running = false;
|
|
4123
4127
|
let timer = null;
|
|
4124
4128
|
let abortHandler = null;
|
|
4125
|
-
const
|
|
4129
|
+
const render2 = () => {
|
|
4126
4130
|
if (lastLines > 0) clearLines(lastLines);
|
|
4127
4131
|
const frame2 = isColorless2() ? stripAnsi(currentFrame) : currentFrame;
|
|
4128
4132
|
try {
|
|
@@ -4137,7 +4141,7 @@ var live = (opts = {}) => {
|
|
|
4137
4141
|
running = true;
|
|
4138
4142
|
registerCrashHandlers3();
|
|
4139
4143
|
hideCursorSafe2();
|
|
4140
|
-
timer = setInterval(
|
|
4144
|
+
timer = setInterval(render2, interval);
|
|
4141
4145
|
if (signal && !abortHandler) {
|
|
4142
4146
|
abortHandler = () => stop({ clear: false });
|
|
4143
4147
|
if (signal.aborted) abortHandler();
|
|
@@ -4166,7 +4170,7 @@ var live = (opts = {}) => {
|
|
|
4166
4170
|
};
|
|
4167
4171
|
const update = (newFrame) => {
|
|
4168
4172
|
currentFrame = ensureString4(newFrame);
|
|
4169
|
-
if (running)
|
|
4173
|
+
if (running) render2();
|
|
4170
4174
|
};
|
|
4171
4175
|
if (autoStart) start();
|
|
4172
4176
|
return { start, stop, update, isRunning: () => running };
|
|
@@ -4515,7 +4519,7 @@ var menu = (items, opts = {}) => {
|
|
|
4515
4519
|
} catch {
|
|
4516
4520
|
}
|
|
4517
4521
|
};
|
|
4518
|
-
const
|
|
4522
|
+
const render2 = () => {
|
|
4519
4523
|
let totalLines = 0;
|
|
4520
4524
|
const { cols: termCols } = termSize();
|
|
4521
4525
|
const safeTermCols = Math.max(1, termCols);
|
|
@@ -4589,7 +4593,7 @@ var menu = (items, opts = {}) => {
|
|
|
4589
4593
|
try {
|
|
4590
4594
|
emit(cursor.hide());
|
|
4591
4595
|
cursorHidden = true;
|
|
4592
|
-
lastRenderedLines =
|
|
4596
|
+
lastRenderedLines = render2();
|
|
4593
4597
|
} catch {
|
|
4594
4598
|
cleanup(null);
|
|
4595
4599
|
return Promise.resolve(MENU_CANCELLED);
|
|
@@ -4630,7 +4634,7 @@ var menu = (items, opts = {}) => {
|
|
|
4630
4634
|
return;
|
|
4631
4635
|
}
|
|
4632
4636
|
clearLinesLocal();
|
|
4633
|
-
lastRenderedLines =
|
|
4637
|
+
lastRenderedLines = render2();
|
|
4634
4638
|
} catch {
|
|
4635
4639
|
cleanup(onKey);
|
|
4636
4640
|
safeResolve(MENU_CANCELLED);
|
|
@@ -6342,8 +6346,8 @@ var _renderValue = (value, depth, config) => {
|
|
|
6342
6346
|
inlineItems.push(_c(`... (${remaining} more)`, COLORS.comment, useColor));
|
|
6343
6347
|
}
|
|
6344
6348
|
const candidate = _c("[", COLORS.bracket, useColor) + inlineItems.join(", ") + _c("]", COLORS.bracket, useColor);
|
|
6345
|
-
const
|
|
6346
|
-
if (
|
|
6349
|
+
const visibleLen3 = candidate.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
6350
|
+
if (visibleLen3 <= inlineArrayMaxLength) {
|
|
6347
6351
|
return candidate;
|
|
6348
6352
|
}
|
|
6349
6353
|
}
|
|
@@ -6422,6 +6426,269 @@ var json = {
|
|
|
6422
6426
|
pretty
|
|
6423
6427
|
};
|
|
6424
6428
|
|
|
6429
|
+
// src/markdown/index.ts
|
|
6430
|
+
var THEMES = {
|
|
6431
|
+
dark: {
|
|
6432
|
+
h1: ["#ff79c6", "#bd93f9", "#8be9fd"],
|
|
6433
|
+
h2: "#bd93f9",
|
|
6434
|
+
h3: "#8be9fd",
|
|
6435
|
+
h4: "#50fa7b",
|
|
6436
|
+
h5: "#f1fa8c",
|
|
6437
|
+
h6: "#ffb86c",
|
|
6438
|
+
code: "#ff79c6",
|
|
6439
|
+
codeBlockBorder: "#6272a4",
|
|
6440
|
+
link: "#8be9fd",
|
|
6441
|
+
blockquote: "#6272a4",
|
|
6442
|
+
hr: "#6272a4",
|
|
6443
|
+
tableHeader: "#bd93f9"
|
|
6444
|
+
},
|
|
6445
|
+
light: {
|
|
6446
|
+
h1: ["#d63384", "#6f42c1", "#0d6efd"],
|
|
6447
|
+
h2: "#6f42c1",
|
|
6448
|
+
h3: "#0d6efd",
|
|
6449
|
+
h4: "#198754",
|
|
6450
|
+
h5: "#664d03",
|
|
6451
|
+
h6: "#fd7e14",
|
|
6452
|
+
code: "#d63384",
|
|
6453
|
+
codeBlockBorder: "#adb5bd",
|
|
6454
|
+
link: "#0d6efd",
|
|
6455
|
+
blockquote: "#6c757d",
|
|
6456
|
+
hr: "#adb5bd",
|
|
6457
|
+
tableHeader: "#6f42c1"
|
|
6458
|
+
}
|
|
6459
|
+
};
|
|
6460
|
+
var _normalize = (text) => typeof text === "string" ? text.replace(/\r\n/g, "\n").replace(/\r/g, "\n") : "";
|
|
6461
|
+
var HEADING_RE = /^(#{1,6})\s+(.+?)\s*#*\s*$/;
|
|
6462
|
+
var ORDERED_LIST_RE = /^(\s*)(\d+)[.)]\s+(.+)$/;
|
|
6463
|
+
var UNORDERED_LIST_RE = /^(\s*)[-*+]\s+(.+)$/;
|
|
6464
|
+
var HR_RE = /^[ \t]*(?:-{3,}|\*{3,}|_{3,})[ \t]*$/;
|
|
6465
|
+
var CODEBLOCK_OPEN_RE = /^```[ \t]*(\S*)[ \t]*$/;
|
|
6466
|
+
var CODEBLOCK_CLOSE_RE = /^```\s*$/;
|
|
6467
|
+
var BLOCKQUOTE_RE = /^>\s?(.*)$/;
|
|
6468
|
+
var TABLE_SEPARATOR_RE = /^\|?[ \t]*:?-{2,}:?[ \t]*(\|[ \t]*:?-{2,}:?[ \t]*)+\|?[ \t]*$/;
|
|
6469
|
+
var TABLE_ROW_RE = /^\|.*\|[ \t]*$/;
|
|
6470
|
+
var parseBlocks = (source) => {
|
|
6471
|
+
if (typeof source !== "string" || source.length === 0) return [];
|
|
6472
|
+
const lines = _normalize(source).split("\n");
|
|
6473
|
+
const out = [];
|
|
6474
|
+
let i = 0;
|
|
6475
|
+
while (i < lines.length) {
|
|
6476
|
+
const line = lines[i];
|
|
6477
|
+
if (line.trim() === "") {
|
|
6478
|
+
out.push({ type: "blank" });
|
|
6479
|
+
i++;
|
|
6480
|
+
continue;
|
|
6481
|
+
}
|
|
6482
|
+
if (HR_RE.test(line)) {
|
|
6483
|
+
out.push({ type: "hr" });
|
|
6484
|
+
i++;
|
|
6485
|
+
continue;
|
|
6486
|
+
}
|
|
6487
|
+
const headingMatch = HEADING_RE.exec(line);
|
|
6488
|
+
if (headingMatch) {
|
|
6489
|
+
const level = headingMatch[1].length;
|
|
6490
|
+
const text = headingMatch[2].trim();
|
|
6491
|
+
out.push({ type: "heading", level, text });
|
|
6492
|
+
i++;
|
|
6493
|
+
continue;
|
|
6494
|
+
}
|
|
6495
|
+
const codeOpen = CODEBLOCK_OPEN_RE.exec(line);
|
|
6496
|
+
if (codeOpen) {
|
|
6497
|
+
const lang = codeOpen[1].trim();
|
|
6498
|
+
const codeLines = [];
|
|
6499
|
+
i++;
|
|
6500
|
+
while (i < lines.length && !CODEBLOCK_CLOSE_RE.test(lines[i])) {
|
|
6501
|
+
codeLines.push(lines[i]);
|
|
6502
|
+
i++;
|
|
6503
|
+
}
|
|
6504
|
+
if (i < lines.length) i++;
|
|
6505
|
+
out.push({ type: "codeblock", lang, code: codeLines.join("\n") });
|
|
6506
|
+
continue;
|
|
6507
|
+
}
|
|
6508
|
+
if (BLOCKQUOTE_RE.test(line)) {
|
|
6509
|
+
const qLines = [];
|
|
6510
|
+
while (i < lines.length && BLOCKQUOTE_RE.test(lines[i])) {
|
|
6511
|
+
const m = BLOCKQUOTE_RE.exec(lines[i]);
|
|
6512
|
+
qLines.push((m?.[1] ?? "").trim());
|
|
6513
|
+
i++;
|
|
6514
|
+
}
|
|
6515
|
+
out.push({ type: "blockquote", text: qLines.join("\n") });
|
|
6516
|
+
continue;
|
|
6517
|
+
}
|
|
6518
|
+
if (TABLE_ROW_RE.test(line) && i + 1 < lines.length && TABLE_SEPARATOR_RE.test(lines[i + 1])) {
|
|
6519
|
+
const headers = _splitTableRow(line);
|
|
6520
|
+
i += 2;
|
|
6521
|
+
const rows = [];
|
|
6522
|
+
while (i < lines.length && TABLE_ROW_RE.test(lines[i])) {
|
|
6523
|
+
rows.push(_splitTableRow(lines[i]));
|
|
6524
|
+
i++;
|
|
6525
|
+
}
|
|
6526
|
+
out.push({ type: "table", headers, rows });
|
|
6527
|
+
continue;
|
|
6528
|
+
}
|
|
6529
|
+
const ulMatch = UNORDERED_LIST_RE.exec(line);
|
|
6530
|
+
const olMatch = ORDERED_LIST_RE.exec(line);
|
|
6531
|
+
if (ulMatch || olMatch) {
|
|
6532
|
+
const ordered = olMatch != null;
|
|
6533
|
+
const items = [];
|
|
6534
|
+
while (i < lines.length) {
|
|
6535
|
+
const ln = lines[i];
|
|
6536
|
+
const u = UNORDERED_LIST_RE.exec(ln);
|
|
6537
|
+
const o = ORDERED_LIST_RE.exec(ln);
|
|
6538
|
+
if (ordered && o) {
|
|
6539
|
+
items.push(o[3].trim());
|
|
6540
|
+
i++;
|
|
6541
|
+
} else if (!ordered && u) {
|
|
6542
|
+
items.push(u[2].trim());
|
|
6543
|
+
i++;
|
|
6544
|
+
} else {
|
|
6545
|
+
break;
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
out.push({ type: "list", ordered, items });
|
|
6549
|
+
continue;
|
|
6550
|
+
}
|
|
6551
|
+
const paraLines = [line];
|
|
6552
|
+
i++;
|
|
6553
|
+
while (i < lines.length) {
|
|
6554
|
+
const next = lines[i];
|
|
6555
|
+
if (next.trim() === "" || HEADING_RE.test(next) || HR_RE.test(next) || CODEBLOCK_OPEN_RE.test(next) || BLOCKQUOTE_RE.test(next) || UNORDERED_LIST_RE.test(next) || ORDERED_LIST_RE.test(next) || TABLE_ROW_RE.test(next)) {
|
|
6556
|
+
break;
|
|
6557
|
+
}
|
|
6558
|
+
paraLines.push(next);
|
|
6559
|
+
i++;
|
|
6560
|
+
}
|
|
6561
|
+
out.push({ type: "paragraph", text: paraLines.join(" ").trim() });
|
|
6562
|
+
}
|
|
6563
|
+
return out;
|
|
6564
|
+
};
|
|
6565
|
+
var _splitTableRow = (row) => {
|
|
6566
|
+
const stripped = row.trim().replace(/^\|/, "").replace(/\|[ \t]*$/, "");
|
|
6567
|
+
return stripped.split("|").map((c) => c.trim());
|
|
6568
|
+
};
|
|
6569
|
+
var parseInline = (text, opts = {
|
|
6570
|
+
theme: "dark",
|
|
6571
|
+
inlineCodeBackground: true
|
|
6572
|
+
}) => {
|
|
6573
|
+
if (typeof text !== "string" || text.length === 0) return "";
|
|
6574
|
+
const t = THEMES[opts.theme];
|
|
6575
|
+
const codeSlots = [];
|
|
6576
|
+
let s = text.replace(/`([^`\n]+)`/g, (_m, code) => {
|
|
6577
|
+
const styled = opts.inlineCodeBackground ? color.dim(color.hex(t.code)("\xA0" + code + "\xA0")) : color.dim(color.hex(t.code)(code));
|
|
6578
|
+
codeSlots.push(styled);
|
|
6579
|
+
return `\0CODE${codeSlots.length - 1}\0`;
|
|
6580
|
+
});
|
|
6581
|
+
s = s.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, label, url) => {
|
|
6582
|
+
return hyperlink(url, color.hex(t.link)(color.underline(label)));
|
|
6583
|
+
});
|
|
6584
|
+
s = s.replace(/~~([^~\n]+)~~/g, (_m, inner) => color.strikethrough(inner));
|
|
6585
|
+
s = s.replace(/\*\*([^*\n]+)\*\*/g, (_m, inner) => color.bold(inner));
|
|
6586
|
+
s = s.replace(/__([^_\n]+)__/g, (_m, inner) => color.bold(inner));
|
|
6587
|
+
s = s.replace(/(^|[^*])\*([^*\n]+)\*(?!\*)/g, (_m, pre, inner) => pre + color.italic(inner));
|
|
6588
|
+
s = s.replace(/(^|[^_])_([^_\n]+)_(?!_)/g, (_m, pre, inner) => pre + color.italic(inner));
|
|
6589
|
+
s = s.replace(/\x00CODE(\d+)\x00/g, (_m, idx) => codeSlots[Number(idx)] ?? "");
|
|
6590
|
+
return s;
|
|
6591
|
+
};
|
|
6592
|
+
var _detectWidth = () => {
|
|
6593
|
+
const w = process.stdout?.columns;
|
|
6594
|
+
return isFiniteNumber2(w) && w > 10 ? w : 80;
|
|
6595
|
+
};
|
|
6596
|
+
var render = (source, opts = {}) => {
|
|
6597
|
+
if (typeof source !== "string" || source.length === 0) return "";
|
|
6598
|
+
const {
|
|
6599
|
+
width = _detectWidth(),
|
|
6600
|
+
theme = "dark",
|
|
6601
|
+
headingGradient,
|
|
6602
|
+
boxCodeBlocks = true,
|
|
6603
|
+
inlineCodeBackground = true
|
|
6604
|
+
} = opts;
|
|
6605
|
+
const safeWidth = isFiniteNumber2(width) && width > 4 ? Math.floor(width) : 80;
|
|
6606
|
+
const t = THEMES[theme] ?? THEMES.dark;
|
|
6607
|
+
const h1Colors = headingGradient && headingGradient.length >= 2 ? headingGradient : t.h1;
|
|
6608
|
+
const blocks = parseBlocks(source);
|
|
6609
|
+
const inlineOpts = { theme, inlineCodeBackground };
|
|
6610
|
+
const out = [];
|
|
6611
|
+
for (const block of blocks) {
|
|
6612
|
+
switch (block.type) {
|
|
6613
|
+
case "blank":
|
|
6614
|
+
out.push("");
|
|
6615
|
+
break;
|
|
6616
|
+
case "hr":
|
|
6617
|
+
out.push(color.hex(t.hr)(ascii.divider({ width: safeWidth, char: "\u2500" })));
|
|
6618
|
+
break;
|
|
6619
|
+
case "heading": {
|
|
6620
|
+
const inline = parseInline(block.text, inlineOpts);
|
|
6621
|
+
if (block.level === 1) {
|
|
6622
|
+
out.push(color.bold(gradient(inline, h1Colors)));
|
|
6623
|
+
} else if (block.level === 2) {
|
|
6624
|
+
out.push(color.bold(color.underline(color.hex(t.h2)(inline))));
|
|
6625
|
+
} else {
|
|
6626
|
+
const colorKey = `h${block.level}`;
|
|
6627
|
+
const hex = t[colorKey];
|
|
6628
|
+
out.push(color.bold(color.hex(hex)(inline)));
|
|
6629
|
+
}
|
|
6630
|
+
break;
|
|
6631
|
+
}
|
|
6632
|
+
case "paragraph": {
|
|
6633
|
+
out.push(parseInline(block.text, inlineOpts));
|
|
6634
|
+
break;
|
|
6635
|
+
}
|
|
6636
|
+
case "codeblock": {
|
|
6637
|
+
const codeText = block.code.length > 0 ? block.code : " ";
|
|
6638
|
+
if (boxCodeBlocks) {
|
|
6639
|
+
const labeled = block.lang ? ` ${block.lang} ` : null;
|
|
6640
|
+
const box3 = ascii.box(codeText, {
|
|
6641
|
+
borderStyle: "rounded",
|
|
6642
|
+
padding: 1,
|
|
6643
|
+
title: labeled
|
|
6644
|
+
});
|
|
6645
|
+
out.push(color.hex(t.codeBlockBorder)(box3));
|
|
6646
|
+
} else {
|
|
6647
|
+
const indented = codeText.split("\n").map((l) => " " + l).join("\n");
|
|
6648
|
+
out.push(color.dim(indented));
|
|
6649
|
+
}
|
|
6650
|
+
break;
|
|
6651
|
+
}
|
|
6652
|
+
case "list": {
|
|
6653
|
+
const lines = [];
|
|
6654
|
+
for (let idx = 0; idx < block.items.length; idx++) {
|
|
6655
|
+
const marker = block.ordered ? `${idx + 1}.` : "\u2022";
|
|
6656
|
+
const rendered = parseInline(block.items[idx], inlineOpts);
|
|
6657
|
+
lines.push(` ${color.hex(t.h3)(marker)} ${rendered}`);
|
|
6658
|
+
}
|
|
6659
|
+
out.push(lines.join("\n"));
|
|
6660
|
+
break;
|
|
6661
|
+
}
|
|
6662
|
+
case "blockquote": {
|
|
6663
|
+
const rendered = parseInline(block.text, inlineOpts);
|
|
6664
|
+
const quoted = rendered.split("\n").map((l) => color.hex(t.blockquote)("\u2502 ") + color.dim(l)).join("\n");
|
|
6665
|
+
out.push(quoted);
|
|
6666
|
+
break;
|
|
6667
|
+
}
|
|
6668
|
+
case "table": {
|
|
6669
|
+
const styledHeaders = block.headers.map(
|
|
6670
|
+
(h) => color.bold(color.hex(t.tableHeader)(parseInline(h, inlineOpts)))
|
|
6671
|
+
);
|
|
6672
|
+
const styledRows = block.rows.map(
|
|
6673
|
+
(row) => row.map((cell) => parseInline(cell, inlineOpts))
|
|
6674
|
+
);
|
|
6675
|
+
out.push(components.table([styledHeaders, ...styledRows], {
|
|
6676
|
+
borderStyle: "rounded",
|
|
6677
|
+
padding: 1
|
|
6678
|
+
}));
|
|
6679
|
+
break;
|
|
6680
|
+
}
|
|
6681
|
+
}
|
|
6682
|
+
}
|
|
6683
|
+
while (out.length > 0 && out[out.length - 1] === "") out.pop();
|
|
6684
|
+
return out.join("\n");
|
|
6685
|
+
};
|
|
6686
|
+
var markdown = {
|
|
6687
|
+
render,
|
|
6688
|
+
parseBlocks,
|
|
6689
|
+
parseInline
|
|
6690
|
+
};
|
|
6691
|
+
|
|
6425
6692
|
// src/configure.ts
|
|
6426
6693
|
var DEFAULTS = Object.freeze({
|
|
6427
6694
|
colorMode: "auto",
|
|
@@ -6729,7 +6996,23 @@ var resolveEasingByName = (e) => {
|
|
|
6729
6996
|
};
|
|
6730
6997
|
|
|
6731
6998
|
// src/index.ts
|
|
6732
|
-
var ansimax = {
|
|
6999
|
+
var ansimax = {
|
|
7000
|
+
color,
|
|
7001
|
+
animate,
|
|
7002
|
+
ascii,
|
|
7003
|
+
loader,
|
|
7004
|
+
frames,
|
|
7005
|
+
components,
|
|
7006
|
+
trees,
|
|
7007
|
+
themes,
|
|
7008
|
+
images,
|
|
7009
|
+
configure,
|
|
7010
|
+
// v1.3.0+
|
|
7011
|
+
panels,
|
|
7012
|
+
json,
|
|
7013
|
+
// v1.4.0
|
|
7014
|
+
markdown
|
|
7015
|
+
};
|
|
6733
7016
|
var index_default = ansimax;
|
|
6734
7017
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6735
7018
|
0 && (module.exports = {
|
|
@@ -6829,6 +7112,7 @@ var index_default = ansimax;
|
|
|
6829
7112
|
listPresets,
|
|
6830
7113
|
loader,
|
|
6831
7114
|
mapTree,
|
|
7115
|
+
markdown,
|
|
6832
7116
|
measureBlock,
|
|
6833
7117
|
measureTree,
|
|
6834
7118
|
memoize,
|
|
@@ -6844,6 +7128,8 @@ var index_default = ansimax;
|
|
|
6844
7128
|
padStart,
|
|
6845
7129
|
panels,
|
|
6846
7130
|
parseFiglet,
|
|
7131
|
+
parseMarkdownBlocks,
|
|
7132
|
+
parseMarkdownInline,
|
|
6847
7133
|
pauseListeners,
|
|
6848
7134
|
presetNames,
|
|
6849
7135
|
presets,
|
|
@@ -6851,6 +7137,7 @@ var index_default = ansimax;
|
|
|
6851
7137
|
rainbow,
|
|
6852
7138
|
registerFont,
|
|
6853
7139
|
registerPreset,
|
|
7140
|
+
renderMarkdown,
|
|
6854
7141
|
renderPixelArt,
|
|
6855
7142
|
renderTree,
|
|
6856
7143
|
renderTreeStream,
|