lark-docx2md 0.5.0 → 0.5.1-beta.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/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { r as setLogLevel, t as convert } from "./converter-_quZveHl.js";
2
+ import { r as setLogLevel, t as convert } from "./converter-Bqb4bqxh.js";
3
3
  import { Command } from "commander";
4
4
  import { LoggerLevel } from "@larksuiteoapi/node-sdk";
5
5
  //#region src/cli.ts
@@ -3005,6 +3005,7 @@ function createTitleFilter(options) {
3005
3005
  let state = "scanning";
3006
3006
  let matchedLevel = 0;
3007
3007
  const collected = [];
3008
+ const seenHeadings = [];
3008
3009
  function pageHandler(blocks) {
3009
3010
  for (const block of blocks) {
3010
3011
  if (block.block_type === 1) {
@@ -3015,7 +3016,12 @@ function createTitleFilter(options) {
3015
3016
  case "scanning": {
3016
3017
  const level = getHeadingLevel(block);
3017
3018
  if (level !== null) {
3018
- if (extractHeadingText(block) === targetTitle) {
3019
+ const text = extractHeadingText(block) ?? "";
3020
+ seenHeadings.push({
3021
+ level,
3022
+ text
3023
+ });
3024
+ if (text === targetTitle) {
3019
3025
  state = "collecting";
3020
3026
  matchedLevel = level;
3021
3027
  collected.push(block);
@@ -3040,7 +3046,8 @@ function createTitleFilter(options) {
3040
3046
  function getResult() {
3041
3047
  return {
3042
3048
  blocks: [...collected],
3043
- matched: state === "collecting" || state === "done"
3049
+ matched: state === "collecting" || state === "done",
3050
+ availableHeadings: [...seenHeadings]
3044
3051
  };
3045
3052
  }
3046
3053
  return {
@@ -3096,7 +3103,14 @@ async function convert(opts) {
3096
3103
  const filter = createTitleFilter({ title: opts.filterTitle });
3097
3104
  await client.getDocxBlocks(docToken, filter.pageHandler);
3098
3105
  const result = filter.getResult();
3099
- if (!result.matched) throw new Error(`未找到匹配的标题「${opts.filterTitle}」,请检查标题文本是否正确`);
3106
+ if (!result.matched) {
3107
+ let msg = `No heading matched "${opts.filterTitle}". Please verify the heading text.`;
3108
+ if (result.availableHeadings.length > 0) {
3109
+ const list = result.availableHeadings.map((h) => `${"#".repeat(h.level)} ${h.text}`).join("\n");
3110
+ msg += `\n\nAvailable headings in the document:\n\n${list}`;
3111
+ }
3112
+ throw new Error(msg);
3113
+ }
3100
3114
  blocks = result.blocks;
3101
3115
  } else blocks = await client.getDocxBlocks(docToken);
3102
3116
  logger.info(`Fetched ${blocks.length} blocks`);
@@ -3124,4 +3138,4 @@ async function convert(opts) {
3124
3138
  //#endregion
3125
3139
  export { parseWikiUrl as n, setLogLevel as r, convert as t };
3126
3140
 
3127
- //# sourceMappingURL=converter-_quZveHl.js.map
3141
+ //# sourceMappingURL=converter-Bqb4bqxh.js.map