chattercatcher 0.2.3 → 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 CHANGED
@@ -8,7 +8,7 @@ import fs15 from "fs/promises";
8
8
  // package.json
9
9
  var package_default = {
10
10
  name: "chattercatcher",
11
- version: "0.2.3",
11
+ version: "0.2.5",
12
12
  description: "\u672C\u5730\u4F18\u5148\u7684\u98DE\u4E66/Lark \u5BB6\u5EAD\u7FA4\u77E5\u8BC6\u5E93\u673A\u5668\u4EBA",
13
13
  type: "module",
14
14
  main: "dist/index.js",
@@ -4472,146 +4472,13 @@ function formatTextWithMentions(text, options) {
4472
4472
  const prefix = mentions.map((mention) => `<at user_id="${escapeAtText(mention.openId)}">${escapeAtText(mention.name)}</at>`).join(" ");
4473
4473
  return `${prefix} ${text}`.trim();
4474
4474
  }
4475
- function findMarkdownLinkEnd(text, start) {
4476
- let depth = 0;
4477
- for (let index2 = start; index2 < text.length; index2 += 1) {
4478
- const char = text[index2];
4479
- if (char === "(") {
4480
- depth += 1;
4481
- } else if (char === ")") {
4482
- if (depth === 0) return index2;
4483
- depth -= 1;
4484
- }
4485
- }
4486
- return -1;
4487
- }
4488
- function stripInlineMarkdown(text) {
4489
- let output = "";
4490
- let index2 = 0;
4491
- while (index2 < text.length) {
4492
- const linkStart = text.indexOf("[", index2);
4493
- const boldStarStart = text.indexOf("**", index2);
4494
- const boldUnderscoreStart = text.indexOf("__", index2);
4495
- const candidates = [linkStart, boldStarStart, boldUnderscoreStart].filter((value) => value >= 0);
4496
- const next = candidates.length ? Math.min(...candidates) : -1;
4497
- if (next < 0) {
4498
- output += text.slice(index2);
4499
- break;
4500
- }
4501
- output += text.slice(index2, next);
4502
- if (next === linkStart) {
4503
- const labelEnd = text.indexOf("](", next);
4504
- if (labelEnd > next) {
4505
- const hrefStart = labelEnd + 2;
4506
- const hrefEnd = findMarkdownLinkEnd(text, hrefStart);
4507
- const href = hrefEnd >= 0 ? text.slice(hrefStart, hrefEnd) : "";
4508
- if (hrefEnd >= 0 && /^https?:\/\/\S+$/.test(href)) {
4509
- output += `${text.slice(next + 1, labelEnd)} ${href}`;
4510
- index2 = hrefEnd + 1;
4511
- continue;
4512
- }
4513
- }
4514
- output += text[next];
4515
- index2 = next + 1;
4516
- continue;
4517
- }
4518
- const marker = next === boldStarStart ? "**" : "__";
4519
- const close = text.indexOf(marker, next + marker.length);
4520
- if (close > next + marker.length) {
4521
- output += text.slice(next + marker.length, close);
4522
- index2 = close + marker.length;
4523
- continue;
4524
- }
4525
- output += marker;
4526
- index2 = next + marker.length;
4527
- }
4528
- return output;
4529
- }
4530
- function parseInline(text) {
4531
- return [{ tag: "text", text: stripInlineMarkdown(text) || " " }];
4532
- }
4533
- function pushParagraph(content, lines) {
4534
- if (lines.length === 0) return;
4535
- content.push(parseInline(lines.join("\n")));
4536
- lines.length = 0;
4537
- }
4538
- function parseMarkdownBlocks(markdown) {
4539
- if (!markdown.trim()) {
4540
- return [[{ tag: "text", text: " " }]];
4541
- }
4542
- const content = [];
4543
- const paragraph = [];
4544
- const code = [];
4545
- let inCodeBlock = false;
4546
- for (const rawLine of markdown.replace(/\r\n/g, "\n").split("\n")) {
4547
- const line = rawLine.trimEnd();
4548
- if (line.startsWith("```")) {
4549
- if (inCodeBlock) {
4550
- content.push([{ tag: "text", text: `\`\`\`
4551
- ${code.join("\n")}
4552
- \`\`\`` }]);
4553
- code.length = 0;
4554
- inCodeBlock = false;
4555
- } else {
4556
- pushParagraph(content, paragraph);
4557
- inCodeBlock = true;
4558
- }
4559
- continue;
4560
- }
4561
- if (inCodeBlock) {
4562
- code.push(rawLine);
4563
- continue;
4564
- }
4565
- if (!line.trim()) {
4566
- pushParagraph(content, paragraph);
4567
- continue;
4568
- }
4569
- const heading = line.match(/^#{1,6}\s+(.+)$/);
4570
- if (heading) {
4571
- pushParagraph(content, paragraph);
4572
- content.push([{ tag: "text", text: stripInlineMarkdown(heading[1]) || " " }]);
4573
- continue;
4574
- }
4575
- const unordered = line.match(/^[-*]\s+(.+)$/);
4576
- if (unordered) {
4577
- pushParagraph(content, paragraph);
4578
- content.push(parseInline(`\u2022 ${unordered[1]}`));
4579
- continue;
4580
- }
4581
- const ordered = line.match(/^(\d+)\.\s+(.+)$/);
4582
- if (ordered) {
4583
- pushParagraph(content, paragraph);
4584
- content.push(parseInline(`${ordered[1]}. ${ordered[2]}`));
4585
- continue;
4586
- }
4587
- paragraph.push(line);
4588
- }
4589
- if (inCodeBlock) {
4590
- content.push([{ tag: "text", text: `\`\`\`
4591
- ${code.join("\n")}` }]);
4592
- }
4593
- pushParagraph(content, paragraph);
4594
- return content.length ? content : [[{ tag: "text", text: markdown }]];
4475
+ function buildMarkdownText(markdown, options) {
4476
+ return formatTextWithMentions(markdown.trim() || " ", options);
4595
4477
  }
4596
4478
  function buildFeishuPostContent(markdown, options) {
4597
- const content = parseMarkdownBlocks(markdown);
4598
- const mentions = options?.mentions ?? [];
4599
- if (mentions.length) {
4600
- const firstLine = content[0] ?? [];
4601
- const firstText = firstLine[0];
4602
- const prefix = mentions.map((mention) => `@${mention.name}`).join(" ");
4603
- if (firstText?.tag === "text") {
4604
- content[0] = [{ tag: "text", text: `${prefix} ${firstText.text}` }, ...firstLine.slice(1)];
4605
- } else {
4606
- content[0] = [{ tag: "text", text: `${prefix} ` }, ...firstLine];
4607
- }
4608
- }
4609
4479
  return {
4610
- post: {
4611
- zh_cn: {
4612
- title: "",
4613
- content
4614
- }
4480
+ zh_cn: {
4481
+ content: [[{ tag: "md", text: buildMarkdownText(markdown, options) }]]
4615
4482
  }
4616
4483
  };
4617
4484
  }
@@ -4633,12 +4500,33 @@ function extractImageKey(response) {
4633
4500
  throw new Error("\u98DE\u4E66\u56FE\u7247\u4E0A\u4F20\u54CD\u5E94\u7F3A\u5C11 image_key\u3002");
4634
4501
  }
4635
4502
  function collectErrorFields(error) {
4636
- const fields = [error];
4637
- const value = error && typeof error === "object" ? error : {};
4638
- fields.push(value.code, value.errorCode, value.msg, value.message);
4639
- const response = value.response && typeof value.response === "object" ? value.response : {};
4640
- const data2 = response.data && typeof response.data === "object" ? response.data : {};
4641
- fields.push(data2.code, data2.errorCode, data2.msg, data2.message);
4503
+ const fields = [];
4504
+ const seen = /* @__PURE__ */ new Set();
4505
+ function visit(value) {
4506
+ if (value === void 0 || value === null || seen.has(value)) {
4507
+ return;
4508
+ }
4509
+ fields.push(value);
4510
+ if (typeof value !== "object") {
4511
+ return;
4512
+ }
4513
+ seen.add(value);
4514
+ if (Array.isArray(value)) {
4515
+ for (const item of value) {
4516
+ visit(item);
4517
+ }
4518
+ return;
4519
+ }
4520
+ const record = value;
4521
+ visit(record.code);
4522
+ visit(record.errorCode);
4523
+ visit(record.msg);
4524
+ visit(record.message);
4525
+ visit(record.error);
4526
+ visit(record.response);
4527
+ visit(record.data);
4528
+ }
4529
+ visit(error);
4642
4530
  return fields;
4643
4531
  }
4644
4532
  function isRichTextCompatibilityError(error) {