chattercatcher 0.2.1 → 0.2.2

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.1",
11
+ version: "0.2.2",
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",
@@ -4463,8 +4463,8 @@ function findMarkdownLinkEnd(text, start) {
4463
4463
  }
4464
4464
  return -1;
4465
4465
  }
4466
- function parseInline(text) {
4467
- const elements = [];
4466
+ function stripInlineMarkdown(text) {
4467
+ let output = "";
4468
4468
  let index2 = 0;
4469
4469
  while (index2 < text.length) {
4470
4470
  const linkStart = text.indexOf("[", index2);
@@ -4473,12 +4473,10 @@ function parseInline(text) {
4473
4473
  const candidates = [linkStart, boldStarStart, boldUnderscoreStart].filter((value) => value >= 0);
4474
4474
  const next = candidates.length ? Math.min(...candidates) : -1;
4475
4475
  if (next < 0) {
4476
- elements.push({ tag: "text", text: text.slice(index2) });
4476
+ output += text.slice(index2);
4477
4477
  break;
4478
4478
  }
4479
- if (next > index2) {
4480
- elements.push({ tag: "text", text: text.slice(index2, next) });
4481
- }
4479
+ output += text.slice(index2, next);
4482
4480
  if (next === linkStart) {
4483
4481
  const labelEnd = text.indexOf("](", next);
4484
4482
  if (labelEnd > next) {
@@ -4486,27 +4484,29 @@ function parseInline(text) {
4486
4484
  const hrefEnd = findMarkdownLinkEnd(text, hrefStart);
4487
4485
  const href = hrefEnd >= 0 ? text.slice(hrefStart, hrefEnd) : "";
4488
4486
  if (hrefEnd >= 0 && /^https?:\/\/\S+$/.test(href)) {
4489
- elements.push({ tag: "a", text: text.slice(next + 1, labelEnd), href });
4487
+ output += `${text.slice(next + 1, labelEnd)} ${href}`;
4490
4488
  index2 = hrefEnd + 1;
4491
4489
  continue;
4492
4490
  }
4493
4491
  }
4494
- elements.push({ tag: "text", text: text[next] });
4492
+ output += text[next];
4495
4493
  index2 = next + 1;
4496
4494
  continue;
4497
4495
  }
4498
4496
  const marker = next === boldStarStart ? "**" : "__";
4499
4497
  const close = text.indexOf(marker, next + marker.length);
4500
4498
  if (close > next + marker.length) {
4501
- elements.push({ tag: "text", text: text.slice(next + marker.length, close), style: ["bold"] });
4499
+ output += text.slice(next + marker.length, close);
4502
4500
  index2 = close + marker.length;
4503
4501
  continue;
4504
4502
  }
4505
- elements.push({ tag: "text", text: marker });
4503
+ output += marker;
4506
4504
  index2 = next + marker.length;
4507
4505
  }
4508
- const compacted = elements.filter((element) => element.tag !== "text" || element.text.length > 0);
4509
- return compacted.length ? compacted : [{ tag: "text", text: " " }];
4506
+ return output;
4507
+ }
4508
+ function parseInline(text) {
4509
+ return [{ tag: "text", text: stripInlineMarkdown(text) || " " }];
4510
4510
  }
4511
4511
  function pushParagraph(content, lines) {
4512
4512
  if (lines.length === 0) return;
@@ -4547,7 +4547,7 @@ ${code.join("\n")}
4547
4547
  const heading = line.match(/^#{1,6}\s+(.+)$/);
4548
4548
  if (heading) {
4549
4549
  pushParagraph(content, paragraph);
4550
- content.push([{ tag: "text", text: heading[1], style: ["bold"] }]);
4550
+ content.push([{ tag: "text", text: stripInlineMarkdown(heading[1]) || " " }]);
4551
4551
  continue;
4552
4552
  }
4553
4553
  const unordered = line.match(/^[-*]\s+(.+)$/);
@@ -4575,17 +4575,13 @@ function buildFeishuPostContent(markdown, options) {
4575
4575
  const content = parseMarkdownBlocks(markdown);
4576
4576
  const mentions = options?.mentions ?? [];
4577
4577
  if (mentions.length) {
4578
- const mentionElements = mentions.map((mention) => ({
4579
- tag: "at",
4580
- user_id: mention.openId,
4581
- user_name: mention.name
4582
- }));
4583
4578
  const firstLine = content[0] ?? [];
4584
4579
  const firstText = firstLine[0];
4580
+ const prefix = mentions.map((mention) => `@${mention.name}`).join(" ");
4585
4581
  if (firstText?.tag === "text") {
4586
- content[0] = [...mentionElements, { ...firstText, text: ` ${firstText.text}` }, ...firstLine.slice(1)];
4582
+ content[0] = [{ tag: "text", text: `${prefix} ${firstText.text}` }, ...firstLine.slice(1)];
4587
4583
  } else {
4588
- content[0] = [...mentionElements, { tag: "text", text: " " }, ...firstLine];
4584
+ content[0] = [{ tag: "text", text: `${prefix} ` }, ...firstLine];
4589
4585
  }
4590
4586
  }
4591
4587
  return {