chattercatcher 0.2.4 → 0.2.5
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/cli.js +5 -138
- package/dist/cli.js.map +1 -1
- package/dist/index.js +4 -137
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4327,146 +4327,13 @@ function formatTextWithMentions(text, options) {
|
|
|
4327
4327
|
const prefix = mentions.map((mention) => `<at user_id="${escapeAtText(mention.openId)}">${escapeAtText(mention.name)}</at>`).join(" ");
|
|
4328
4328
|
return `${prefix} ${text}`.trim();
|
|
4329
4329
|
}
|
|
4330
|
-
function
|
|
4331
|
-
|
|
4332
|
-
for (let index = start; index < text.length; index += 1) {
|
|
4333
|
-
const char = text[index];
|
|
4334
|
-
if (char === "(") {
|
|
4335
|
-
depth += 1;
|
|
4336
|
-
} else if (char === ")") {
|
|
4337
|
-
if (depth === 0) return index;
|
|
4338
|
-
depth -= 1;
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
return -1;
|
|
4342
|
-
}
|
|
4343
|
-
function stripInlineMarkdown(text) {
|
|
4344
|
-
let output = "";
|
|
4345
|
-
let index = 0;
|
|
4346
|
-
while (index < text.length) {
|
|
4347
|
-
const linkStart = text.indexOf("[", index);
|
|
4348
|
-
const boldStarStart = text.indexOf("**", index);
|
|
4349
|
-
const boldUnderscoreStart = text.indexOf("__", index);
|
|
4350
|
-
const candidates = [linkStart, boldStarStart, boldUnderscoreStart].filter((value) => value >= 0);
|
|
4351
|
-
const next = candidates.length ? Math.min(...candidates) : -1;
|
|
4352
|
-
if (next < 0) {
|
|
4353
|
-
output += text.slice(index);
|
|
4354
|
-
break;
|
|
4355
|
-
}
|
|
4356
|
-
output += text.slice(index, next);
|
|
4357
|
-
if (next === linkStart) {
|
|
4358
|
-
const labelEnd = text.indexOf("](", next);
|
|
4359
|
-
if (labelEnd > next) {
|
|
4360
|
-
const hrefStart = labelEnd + 2;
|
|
4361
|
-
const hrefEnd = findMarkdownLinkEnd(text, hrefStart);
|
|
4362
|
-
const href = hrefEnd >= 0 ? text.slice(hrefStart, hrefEnd) : "";
|
|
4363
|
-
if (hrefEnd >= 0 && /^https?:\/\/\S+$/.test(href)) {
|
|
4364
|
-
output += `${text.slice(next + 1, labelEnd)} ${href}`;
|
|
4365
|
-
index = hrefEnd + 1;
|
|
4366
|
-
continue;
|
|
4367
|
-
}
|
|
4368
|
-
}
|
|
4369
|
-
output += text[next];
|
|
4370
|
-
index = next + 1;
|
|
4371
|
-
continue;
|
|
4372
|
-
}
|
|
4373
|
-
const marker = next === boldStarStart ? "**" : "__";
|
|
4374
|
-
const close = text.indexOf(marker, next + marker.length);
|
|
4375
|
-
if (close > next + marker.length) {
|
|
4376
|
-
output += text.slice(next + marker.length, close);
|
|
4377
|
-
index = close + marker.length;
|
|
4378
|
-
continue;
|
|
4379
|
-
}
|
|
4380
|
-
output += marker;
|
|
4381
|
-
index = next + marker.length;
|
|
4382
|
-
}
|
|
4383
|
-
return output;
|
|
4384
|
-
}
|
|
4385
|
-
function parseInline(text) {
|
|
4386
|
-
return [{ tag: "text", text: stripInlineMarkdown(text) || " " }];
|
|
4387
|
-
}
|
|
4388
|
-
function pushParagraph(content, lines) {
|
|
4389
|
-
if (lines.length === 0) return;
|
|
4390
|
-
content.push(parseInline(lines.join("\n")));
|
|
4391
|
-
lines.length = 0;
|
|
4392
|
-
}
|
|
4393
|
-
function parseMarkdownBlocks(markdown) {
|
|
4394
|
-
if (!markdown.trim()) {
|
|
4395
|
-
return [[{ tag: "text", text: " " }]];
|
|
4396
|
-
}
|
|
4397
|
-
const content = [];
|
|
4398
|
-
const paragraph = [];
|
|
4399
|
-
const code = [];
|
|
4400
|
-
let inCodeBlock = false;
|
|
4401
|
-
for (const rawLine of markdown.replace(/\r\n/g, "\n").split("\n")) {
|
|
4402
|
-
const line = rawLine.trimEnd();
|
|
4403
|
-
if (line.startsWith("```")) {
|
|
4404
|
-
if (inCodeBlock) {
|
|
4405
|
-
content.push([{ tag: "text", text: `\`\`\`
|
|
4406
|
-
${code.join("\n")}
|
|
4407
|
-
\`\`\`` }]);
|
|
4408
|
-
code.length = 0;
|
|
4409
|
-
inCodeBlock = false;
|
|
4410
|
-
} else {
|
|
4411
|
-
pushParagraph(content, paragraph);
|
|
4412
|
-
inCodeBlock = true;
|
|
4413
|
-
}
|
|
4414
|
-
continue;
|
|
4415
|
-
}
|
|
4416
|
-
if (inCodeBlock) {
|
|
4417
|
-
code.push(rawLine);
|
|
4418
|
-
continue;
|
|
4419
|
-
}
|
|
4420
|
-
if (!line.trim()) {
|
|
4421
|
-
pushParagraph(content, paragraph);
|
|
4422
|
-
continue;
|
|
4423
|
-
}
|
|
4424
|
-
const heading = line.match(/^#{1,6}\s+(.+)$/);
|
|
4425
|
-
if (heading) {
|
|
4426
|
-
pushParagraph(content, paragraph);
|
|
4427
|
-
content.push([{ tag: "text", text: stripInlineMarkdown(heading[1]) || " " }]);
|
|
4428
|
-
continue;
|
|
4429
|
-
}
|
|
4430
|
-
const unordered = line.match(/^[-*]\s+(.+)$/);
|
|
4431
|
-
if (unordered) {
|
|
4432
|
-
pushParagraph(content, paragraph);
|
|
4433
|
-
content.push(parseInline(`\u2022 ${unordered[1]}`));
|
|
4434
|
-
continue;
|
|
4435
|
-
}
|
|
4436
|
-
const ordered = line.match(/^(\d+)\.\s+(.+)$/);
|
|
4437
|
-
if (ordered) {
|
|
4438
|
-
pushParagraph(content, paragraph);
|
|
4439
|
-
content.push(parseInline(`${ordered[1]}. ${ordered[2]}`));
|
|
4440
|
-
continue;
|
|
4441
|
-
}
|
|
4442
|
-
paragraph.push(line);
|
|
4443
|
-
}
|
|
4444
|
-
if (inCodeBlock) {
|
|
4445
|
-
content.push([{ tag: "text", text: `\`\`\`
|
|
4446
|
-
${code.join("\n")}` }]);
|
|
4447
|
-
}
|
|
4448
|
-
pushParagraph(content, paragraph);
|
|
4449
|
-
return content.length ? content : [[{ tag: "text", text: markdown }]];
|
|
4330
|
+
function buildMarkdownText(markdown, options) {
|
|
4331
|
+
return formatTextWithMentions(markdown.trim() || " ", options);
|
|
4450
4332
|
}
|
|
4451
4333
|
function buildFeishuPostContent(markdown, options) {
|
|
4452
|
-
const content = parseMarkdownBlocks(markdown);
|
|
4453
|
-
const mentions = options?.mentions ?? [];
|
|
4454
|
-
if (mentions.length) {
|
|
4455
|
-
const firstLine = content[0] ?? [];
|
|
4456
|
-
const firstText = firstLine[0];
|
|
4457
|
-
const prefix = mentions.map((mention) => `@${mention.name}`).join(" ");
|
|
4458
|
-
if (firstText?.tag === "text") {
|
|
4459
|
-
content[0] = [{ tag: "text", text: `${prefix} ${firstText.text}` }, ...firstLine.slice(1)];
|
|
4460
|
-
} else {
|
|
4461
|
-
content[0] = [{ tag: "text", text: `${prefix} ` }, ...firstLine];
|
|
4462
|
-
}
|
|
4463
|
-
}
|
|
4464
4334
|
return {
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
title: "",
|
|
4468
|
-
content
|
|
4469
|
-
}
|
|
4335
|
+
zh_cn: {
|
|
4336
|
+
content: [[{ tag: "md", text: buildMarkdownText(markdown, options) }]]
|
|
4470
4337
|
}
|
|
4471
4338
|
};
|
|
4472
4339
|
}
|