lark-docx2md 0.2.0 → 0.2.1-beta.1

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  将飞书文档转换为 Markdown 文件的命令行工具。
6
6
 
7
- > 支持的飞书文档链接格式:https://*.feishu.cn/wiki/*
7
+ > 支持的飞书文档链接格式:`https://*.feishu.cn/wiki/*`、`https://*.feishu.cn/sheets/*`
8
8
 
9
9
  ## 使用
10
10
 
@@ -14,6 +14,12 @@
14
14
  npx -y lark-docx2md@latest download https://xxx.feishu.cn/wiki/xxx --app-id cli_xxx --app-secret xxxx
15
15
  ```
16
16
 
17
+ > `download` 命令支持别名 `dl`,以下写法等效:
18
+ >
19
+ > ```bash
20
+ > npx -y lark-docx2md@latest dl https://xxx.feishu.cn/wiki/xxx --app-id cli_xxx --app-secret xxxx
21
+ > ```
22
+
17
23
  或先设置环境变量(命令行参数可省略):
18
24
 
19
25
  ```bash
@@ -22,26 +28,25 @@ export LARK_DOCX2MD_APP_SECRET=<APP_SECRET>
22
28
  npx -y lark-docx2md@latest download <url>
23
29
  ```
24
30
 
31
+ ## 参数
32
+
25
33
  | 参数 | 说明 | 环境变量 | 默认值 |
26
34
  |--------------------------|-------------------------------------------|------------------------------|-----------------------|
27
- | `<url>` | 飞书文档链接(`https://*.feishu.cn/wiki/*`) | — | — |
35
+ | `<url>` | 飞书文档链接(`https://*.feishu.cn/wiki/*` 或 `/sheets/*`) | — | — |
28
36
  | `--app-id <id>` | 飞书应用 App ID | `LARK_DOCX2MD_APP_ID` | — |
29
37
  | `--app-secret <secret>` | 飞书应用 App Secret | `LARK_DOCX2MD_APP_SECRET` | — |
30
38
  | `-o, --output <dir>` | 输出目录 | `LARK_DOCX2MD_OUTPUT` | `./larkDocx2mdOutput` |
31
- | `--agent` | Agent 模式:日志 ERRORMarkdown 输出到 stdout | `LARK_DOCX2MD_AGENT=true` | `false` |
39
+ | `--agent [mode]` | Agent 模式:日志 ERROR。不传值(或 `=true`)为在线模式,Markdown 输出到 stdout;传 `local` 则落盘后输出引导 AI 读取的提示词 | `LARK_DOCX2MD_AGENT=true\|local` | `false` |
32
40
  | `--image-mode <mode>` | 图片处理模式:`local`(下载到本地)或 `online`(24h 临时链接) | `LARK_DOCX2MD_IMAGE_MODE` | `local` |
33
- | `--wb-format <format>` | 画板输出格式:`base64`、`inline-svg`、`svg`、`yaml` | `LARK_DOCX2MD_WB_FORMAT` | `svg` |
41
+ | `--wb-format <format>` | 画板输出格式:`base64`、`inline-svg`、`svg`、`yaml` | `LARK_DOCX2MD_WB_FORMAT` | `svg`(agent 下默认 `yaml`) |
34
42
  | `--wb-bg <style>` | 画板 SVG 背景:`none`、`dot` 或颜色值如 `#fff` | `LARK_DOCX2MD_WB_BG` | `none` |
35
43
  | `--wb-image-mode <mode>` | 画板图片模式:`online`、`base64` 或 `local` | `LARK_DOCX2MD_WB_IMAGE_MODE` | `local` |
36
44
 
37
45
  > **参数联动规则**
38
46
  >
39
- > - `--agent` 开启时:`--image-mode` 强制为 `online`,`--wb-image-mode` 强制为 `online`,`--wb-format` 默认为 `yaml`(仅允许
40
- `inline-svg` / `yaml`)。
41
- > - `--wb-format yaml` 时:`--wb-image-mode` 强制为 `online`。
42
-
43
-
44
- **`--agent` 开启时,飞书文档转换后的内容会直接通过标准流输出**
47
+ > - `--agent`(在线):强制 `--image-mode=online`、`--wb-image-mode=online`;`--wb-format` 默认 `yaml`,仅允许 `inline-svg` / `yaml`;转换完成后 Markdown 直接通过 stdout 输出。
48
+ > - `--agent local`:强制 `--image-mode=local`、`--wb-image-mode=local`(Markdown、图片、画板中的图片均落盘);`--wb-format` 默认 `yaml`,仅允许 `inline-svg` / `yaml`;stdout 输出引导 AI 读取文件的提示词(包含绝对路径)。
49
+ > - 非 agent 模式下 `--wb-format yaml` 时:`--wb-image-mode` 强制为 `online`。
45
50
 
46
51
  ## 功能
47
52
 
@@ -50,6 +55,7 @@ npx -y lark-docx2md@latest download <url>
50
55
  - 输出标准 Markdown 文件
51
56
  - 支持飞书画板,输出格式:`base64`(data URI 内嵌)、`inline-svg`(SVG 标签内嵌)、`svg`(独立文件)、`yaml`(AI
52
57
  友好结构化数据)。详见 [画板支持说明](./WHITEBOARD.md)
58
+ - 支持飞书电子表格(独立 sheet URL 或 docx 内嵌 sheet 块),输出 GFM 表格,自动展开合并单元格。详见 [电子表格支持说明](./SHEET.md)
53
59
 
54
60
  ### 支持的内容块类型
55
61
 
@@ -70,6 +76,7 @@ npx -y lark-docx2md@latest download <url>
70
76
  | Table / TableCell | 表格 | `<table>` HTML(支持合并单元格) |
71
77
  | QuoteContainer | 引用容器 | `> 子块内容` |
72
78
  | Grid / GridColumn | 分栏布局 | 展平为子块内容 |
79
+ | Sheet | 电子表格 | GFM 表格(合并单元格自动展开) |
73
80
 
74
81
  ### 支持的行内样式
75
82
 
@@ -85,16 +92,16 @@ npx -y lark-docx2md@latest download <url>
85
92
  | @用户 | 用户 ID |
86
93
  | @文档 | `[标题](url)` |
87
94
 
88
- > 未支持的块类型(如文件附件、视频、内嵌表格等)会被静默忽略。
95
+ > 未支持的块类型(如文件附件、视频等)会被静默忽略。
89
96
 
90
97
  ## 开发
91
98
 
92
99
  ```bash
93
- # 直接运行(无需构建)
100
+ # 直接运行(无需构建),download 可使用别名 dl
94
101
  pnpm dev download --app-id <APP_ID> --app-secret <APP_SECRET> <url>
95
102
 
96
103
  # 或使用环境变量
97
- LARK_DOCX2MD_APP_ID=<APP_ID> LARK_DOCX2MD_APP_SECRET=<APP_SECRET> pnpm dev download <url>
104
+ LARK_DOCX2MD_APP_ID=<APP_ID> LARK_DOCX2MD_APP_SECRET=<APP_SECRET> pnpm dev dl <url>
98
105
 
99
106
  # 构建为 JS
100
107
  pnpm build
@@ -118,7 +125,9 @@ pnpm build
118
125
  "docx:document:readonly",
119
126
  "wiki:node:read",
120
127
  "wiki:wiki",
121
- "wiki:wiki:readonly"
128
+ "wiki:wiki:readonly",
129
+ "sheets:spreadsheet.meta:read",
130
+ "sheets:spreadsheet:readonly"
122
131
  ],
123
132
  "user": []
124
133
  }
@@ -132,3 +141,8 @@ ISC
132
141
  ## 🙏 致谢
133
142
 
134
143
  本项目开发过程中获得了 [LINUX DO](https://linux.do/latest) 社区佬友的帮助,本产品会在社区发布,感谢社区的支持。
144
+
145
+ ## TODO
146
+
147
+ - [ ] 富文本转换
148
+ - [x] 电子表格导出为 Markdown
package/dist/cli.js CHANGED
@@ -1,27 +1,38 @@
1
1
  #!/usr/bin/env node
2
- import { r as setLogLevel, t as convert } from "./converter-ByfbJV0N.js";
2
+ import { r as setLogLevel, t as convert } from "./converter-FwY1m1jm.js";
3
3
  import { Command } from "commander";
4
4
  import { LoggerLevel } from "@larksuiteoapi/node-sdk";
5
5
  //#region src/cli.ts
6
6
  const program = new Command();
7
7
  program.name("larkDocx2md").description("Download Lark/Feishu documents to markdown");
8
- program.command("download").description("Download a wiki document to markdown").option("--app-id <id>", "Feishu app ID (or read from LARK_DOCX2MD_APP_ID)").option("--app-secret <secret>", "Feishu app secret (or read from LARK_DOCX2MD_APP_SECRET)").option("-o, --output <dir>", "Output directory (or LARK_DOCX2MD_OUTPUT)").option("--agent", "Enable agent mode: ERROR log level, and AI prompt output (or LARK_DOCX2MD_AGENT=true)").option("--wb-format <format>", "Whiteboard output format: \"base64\", \"inline-svg\", \"svg\", or \"yaml\" (or LARK_DOCX2MD_WB_FORMAT)").option("--wb-bg <style>", "Whiteboard SVG background: \"none\", \"dot\", or a color like \"#fff\" (or LARK_DOCX2MD_WB_BG)").option("--wb-image-mode <mode>", "Whiteboard image mode: \"online\", \"base64\", or \"local\" (or LARK_DOCX2MD_WB_IMAGE_MODE)").option("--image-mode <mode>", "Image handling mode: \"local\" or \"online\" (or LARK_DOCX2MD_IMAGE_MODE)").argument("<url>", "Feishu wiki document URL: https://*.feishu.cn/wiki/*").action(async (url, opts) => {
8
+ program.command("download").alias("dl").description("Download a wiki document to markdown").option("--app-id <id>", "Feishu app ID (or read from LARK_DOCX2MD_APP_ID)").option("--app-secret <secret>", "Feishu app secret (or read from LARK_DOCX2MD_APP_SECRET)").option("-o, --output <dir>", "Output directory (or LARK_DOCX2MD_OUTPUT)").option("--agent [mode]", "Enable agent mode: ERROR log level, and AI-oriented stdout. Pass \"local\" to save markdown/images/whiteboards to disk and print a read-file prompt (or LARK_DOCX2MD_AGENT=true|local)").option("--wb-format <format>", "Whiteboard output format: \"base64\", \"inline-svg\", \"svg\", or \"yaml\" (or LARK_DOCX2MD_WB_FORMAT)").option("--wb-bg <style>", "Whiteboard SVG background: \"none\", \"dot\", or a color like \"#fff\" (or LARK_DOCX2MD_WB_BG)").option("--wb-image-mode <mode>", "Whiteboard image mode: \"online\", \"base64\", or \"local\" (or LARK_DOCX2MD_WB_IMAGE_MODE)").option("--image-mode <mode>", "Image handling mode: \"local\" or \"online\" (or LARK_DOCX2MD_IMAGE_MODE)").argument("<url>", "Feishu wiki document URL: https://*.feishu.cn/wiki/*").action(async (url, opts) => {
9
9
  opts.appId = opts.appId ?? process.env.LARK_DOCX2MD_APP_ID;
10
10
  opts.appSecret = opts.appSecret ?? process.env.LARK_DOCX2MD_APP_SECRET;
11
11
  opts.output = opts.output ?? process.env.LARK_DOCX2MD_OUTPUT ?? "./larkDocx2mdOutput";
12
- opts.agent = opts.agent ?? process.env.LARK_DOCX2MD_AGENT === "true";
12
+ if (opts.agent === void 0) {
13
+ const envAgent = process.env.LARK_DOCX2MD_AGENT;
14
+ if (envAgent === "true") opts.agent = true;
15
+ else if (envAgent === "local") opts.agent = "local";
16
+ else opts.agent = false;
17
+ } else if (typeof opts.agent === "string" && opts.agent !== "local") program.error(`Invalid --agent value "${opts.agent}", only "local" is supported (or omit the value)`);
18
+ const agentEnabled = opts.agent === true || opts.agent === "local";
19
+ const agentLocal = opts.agent === "local";
13
20
  opts.imageMode = opts.imageMode ?? process.env.LARK_DOCX2MD_IMAGE_MODE ?? "local";
14
21
  opts.wbFormat = opts.wbFormat ?? process.env.LARK_DOCX2MD_WB_FORMAT;
15
22
  opts.wbBg = opts.wbBg ?? process.env.LARK_DOCX2MD_WB_BG ?? "none";
16
23
  opts.wbImageMode = opts.wbImageMode ?? process.env.LARK_DOCX2MD_WB_IMAGE_MODE ?? "local";
17
- if (!opts.wbFormat) opts.wbFormat = opts.agent ? "yaml" : "svg";
18
- if (opts.agent) {
24
+ if (!opts.wbFormat) opts.wbFormat = agentEnabled ? "yaml" : "svg";
25
+ if (agentEnabled) {
19
26
  setLogLevel(LoggerLevel.error);
20
- opts.imageMode = "online";
21
- opts.wbImageMode = "online";
27
+ if (agentLocal) {
28
+ opts.imageMode = "local";
29
+ opts.wbImageMode = "local";
30
+ } else {
31
+ opts.imageMode = "online";
32
+ opts.wbImageMode = "online";
33
+ }
22
34
  if (!["inline-svg", "yaml"].includes(opts.wbFormat)) program.error(`Agent mode only supports "inline-svg" or "yaml" for --wb-format`);
23
- opts.wbImageMode = "online";
24
- }
35
+ } else if (opts.wbFormat === "yaml") opts.wbImageMode = "online";
25
36
  if (opts.imageMode && !["local", "online"].includes(opts.imageMode)) program.error(`Invalid --image-mode "${opts.imageMode}", must be "local" or "online"`);
26
37
  if (![
27
38
  "base64",
@@ -29,7 +40,6 @@ program.command("download").description("Download a wiki document to markdown").
29
40
  "svg",
30
41
  "yaml"
31
42
  ].includes(opts.wbFormat)) program.error(`Invalid --wb-format "${opts.wbFormat}", must be "base64", "inline-svg", "svg", or "yaml"`);
32
- if (opts.wbFormat === "yaml") opts.wbImageMode = "online";
33
43
  if (![
34
44
  "online",
35
45
  "base64",
@@ -47,9 +57,10 @@ program.command("download").description("Download a wiki document to markdown").
47
57
  wbImageMode: opts.wbImageMode,
48
58
  wbBg: opts.wbBg,
49
59
  wbFormat: opts.wbFormat,
50
- agent: opts.agent
60
+ agent: agentLocal ? "local" : opts.agent === true
51
61
  });
52
- if (opts.agent) process.stdout.write(result.markdown);
62
+ if (agentLocal) process.stdout.write(`The Feishu document has been downloaded to the following absolute path:\n${result.filePath}\n\nPlease read this file to access the full markdown content.\n`);
63
+ else if (opts.agent === true) process.stdout.write(result.markdown);
53
64
  });
54
65
  program.parse();
55
66
  //#endregion
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { LoggerLevel } from '@larksuiteoapi/node-sdk';\nimport { convert } from './converter.js';\nimport { setLogLevel } from './logger.js';\nimport type { SvgBackground, WbFormat, WbImageMode } from './types.js';\n\nconst program = new Command();\nprogram.name('larkDocx2md').description('Download Lark/Feishu documents to markdown');\n\nprogram\n .command('download')\n .description('Download a wiki document to markdown')\n .option('--app-id <id>', 'Feishu app ID (or read from LARK_DOCX2MD_APP_ID)')\n .option('--app-secret <secret>', 'Feishu app secret (or read from LARK_DOCX2MD_APP_SECRET)')\n .option('-o, --output <dir>', 'Output directory (or LARK_DOCX2MD_OUTPUT)')\n .option('--agent', 'Enable agent mode: ERROR log level, and AI prompt output (or LARK_DOCX2MD_AGENT=true)')\n .option('--wb-format <format>', 'Whiteboard output format: \"base64\", \"inline-svg\", \"svg\", or \"yaml\" (or LARK_DOCX2MD_WB_FORMAT)')\n .option('--wb-bg <style>', 'Whiteboard SVG background: \"none\", \"dot\", or a color like \"#fff\" (or LARK_DOCX2MD_WB_BG)')\n .option('--wb-image-mode <mode>', 'Whiteboard image mode: \"online\", \"base64\", or \"local\" (or LARK_DOCX2MD_WB_IMAGE_MODE)')\n .option('--image-mode <mode>', 'Image handling mode: \"local\" or \"online\" (or LARK_DOCX2MD_IMAGE_MODE)')\n .argument('<url>', 'Feishu wiki document URL: https://*.feishu.cn/wiki/*')\n .action(async (url: string, opts: { appId?: string; appSecret?: string; output?: string; agent?: boolean; imageMode?: string; wbImageMode?: string; wbBg?: SvgBackground; wbFormat?: string }) => {\n // ─── 环境变量默认值(直接指定 > 环境变量 > 内置默认值)────────────────\n opts.appId = opts.appId ?? process.env.LARK_DOCX2MD_APP_ID;\n opts.appSecret = opts.appSecret ?? process.env.LARK_DOCX2MD_APP_SECRET;\n opts.output = opts.output ?? process.env.LARK_DOCX2MD_OUTPUT ?? './larkDocx2mdOutput';\n opts.agent = opts.agent ?? (process.env.LARK_DOCX2MD_AGENT === 'true');\n opts.imageMode = opts.imageMode ?? process.env.LARK_DOCX2MD_IMAGE_MODE ?? 'local';\n opts.wbFormat = opts.wbFormat ?? process.env.LARK_DOCX2MD_WB_FORMAT;\n opts.wbBg = opts.wbBg ?? process.env.LARK_DOCX2MD_WB_BG ?? 'none';\n opts.wbImageMode = opts.wbImageMode ?? process.env.LARK_DOCX2MD_WB_IMAGE_MODE ?? 'local';\n\n // 设置 wb-format 默认值(依赖 agent 状态)\n if (!opts.wbFormat) {\n opts.wbFormat = opts.agent ? 'yaml' : 'svg';\n }\n\n if (opts.agent) {\n setLogLevel(LoggerLevel.error);\n opts.imageMode = 'online';\n opts.wbImageMode = 'online';\n // agent 模式下画板仅支持内嵌形式\n if (!['inline-svg', 'yaml'].includes(opts.wbFormat)) {\n program.error(`Agent mode only supports \"inline-svg\" or \"yaml\" for --wb-format`);\n }\n opts.wbImageMode = 'online';\n }\n\n if (opts.imageMode && !['local', 'online'].includes(opts.imageMode)) {\n program.error(`Invalid --image-mode \"${opts.imageMode}\", must be \"local\" or \"online\"`);\n }\n if (!['base64', 'inline-svg', 'svg', 'yaml'].includes(opts.wbFormat)) {\n program.error(`Invalid --wb-format \"${opts.wbFormat}\", must be \"base64\", \"inline-svg\", \"svg\", or \"yaml\"`);\n }\n // yaml 格式 图片仅支持 online\n if (opts.wbFormat === 'yaml') {\n opts.wbImageMode = 'online';\n }\n if (!['online', 'base64', 'local'].includes(opts.wbImageMode)) {\n program.error(`Invalid --wb-image-mode \"${opts.wbImageMode}\", must be \"online\", \"base64\", or \"local\"`);\n }\n\n const appId = opts.appId!;\n const appSecret = opts.appSecret!;\n if (!appId || !appSecret) {\n program.error('Missing credentials: pass --app-id/--app-secret or set LARK_DOCX2MD_APP_ID/LARK_DOCX2MD_APP_SECRET');\n }\n\n const result = await convert({\n appId,\n appSecret,\n url,\n output: opts.output,\n imageMode: opts.imageMode as 'local' | 'online',\n wbImageMode: opts.wbImageMode as WbImageMode,\n wbBg: opts.wbBg,\n wbFormat: opts.wbFormat as WbFormat,\n agent: opts.agent,\n });\n\n if (opts.agent) {\n process.stdout.write(result.markdown);\n }\n });\n\nprogram.parse();\n"],"mappings":";;;;;AAOA,MAAM,UAAU,IAAI,SAAS;AAC7B,QAAQ,KAAK,cAAc,CAAC,YAAY,6CAA6C;AAErF,QACG,QAAQ,WAAW,CACnB,YAAY,uCAAuC,CACnD,OAAO,iBAAiB,mDAAmD,CAC3E,OAAO,yBAAyB,2DAA2D,CAC3F,OAAO,sBAAsB,4CAA4C,CACzE,OAAO,WAAW,wFAAwF,CAC1G,OAAO,wBAAwB,yGAAiG,CAChI,OAAO,mBAAmB,iGAA2F,CACrH,OAAO,0BAA0B,8FAAwF,CACzH,OAAO,uBAAuB,4EAAwE,CACtG,SAAS,SAAS,uDAAuD,CACzE,OAAO,OAAO,KAAa,SAAsK;AAEhM,MAAK,QAAQ,KAAK,SAAS,QAAQ,IAAI;AACvC,MAAK,YAAY,KAAK,aAAa,QAAQ,IAAI;AAC/C,MAAK,SAAS,KAAK,UAAU,QAAQ,IAAI,uBAAuB;AAChE,MAAK,QAAQ,KAAK,SAAU,QAAQ,IAAI,uBAAuB;AAC/D,MAAK,YAAY,KAAK,aAAa,QAAQ,IAAI,2BAA2B;AAC1E,MAAK,WAAW,KAAK,YAAY,QAAQ,IAAI;AAC7C,MAAK,OAAO,KAAK,QAAQ,QAAQ,IAAI,sBAAsB;AAC3D,MAAK,cAAc,KAAK,eAAe,QAAQ,IAAI,8BAA8B;AAGjF,KAAI,CAAC,KAAK,SACR,MAAK,WAAW,KAAK,QAAQ,SAAS;AAGxC,KAAI,KAAK,OAAO;AACd,cAAY,YAAY,MAAM;AAC9B,OAAK,YAAY;AACjB,OAAK,cAAc;AAEnB,MAAI,CAAC,CAAC,cAAc,OAAO,CAAC,SAAS,KAAK,SAAS,CACjD,SAAQ,MAAM,kEAAkE;AAElF,OAAK,cAAc;;AAGrB,KAAI,KAAK,aAAa,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,KAAK,UAAU,CACjE,SAAQ,MAAM,yBAAyB,KAAK,UAAU,gCAAgC;AAExF,KAAI,CAAC;EAAC;EAAU;EAAc;EAAO;EAAO,CAAC,SAAS,KAAK,SAAS,CAClE,SAAQ,MAAM,wBAAwB,KAAK,SAAS,qDAAqD;AAG3G,KAAI,KAAK,aAAa,OACpB,MAAK,cAAc;AAErB,KAAI,CAAC;EAAC;EAAU;EAAU;EAAQ,CAAC,SAAS,KAAK,YAAY,CAC3D,SAAQ,MAAM,4BAA4B,KAAK,YAAY,2CAA2C;CAGxG,MAAM,QAAQ,KAAK;CACnB,MAAM,YAAY,KAAK;AACvB,KAAI,CAAC,SAAS,CAAC,UACb,SAAQ,MAAM,qGAAqG;CAGrH,MAAM,SAAS,MAAM,QAAQ;EAC3B;EACA;EACA;EACA,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,MAAM,KAAK;EACX,UAAU,KAAK;EACf,OAAO,KAAK;EACb,CAAC;AAEF,KAAI,KAAK,MACP,SAAQ,OAAO,MAAM,OAAO,SAAS;EAEvC;AAEJ,QAAQ,OAAO"}
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { LoggerLevel } from '@larksuiteoapi/node-sdk';\nimport { convert } from './converter.js';\nimport { setLogLevel } from './logger.js';\nimport type { SvgBackground, WbFormat, WbImageMode } from './types.js';\n\nconst program = new Command();\nprogram.name('larkDocx2md').description('Download Lark/Feishu documents to markdown');\n\nprogram\n .command('download')\n .alias('dl')\n .description('Download a wiki document to markdown')\n .option('--app-id <id>', 'Feishu app ID (or read from LARK_DOCX2MD_APP_ID)')\n .option('--app-secret <secret>', 'Feishu app secret (or read from LARK_DOCX2MD_APP_SECRET)')\n .option('-o, --output <dir>', 'Output directory (or LARK_DOCX2MD_OUTPUT)')\n .option('--agent [mode]', 'Enable agent mode: ERROR log level, and AI-oriented stdout. Pass \"local\" to save markdown/images/whiteboards to disk and print a read-file prompt (or LARK_DOCX2MD_AGENT=true|local)')\n .option('--wb-format <format>', 'Whiteboard output format: \"base64\", \"inline-svg\", \"svg\", or \"yaml\" (or LARK_DOCX2MD_WB_FORMAT)')\n .option('--wb-bg <style>', 'Whiteboard SVG background: \"none\", \"dot\", or a color like \"#fff\" (or LARK_DOCX2MD_WB_BG)')\n .option('--wb-image-mode <mode>', 'Whiteboard image mode: \"online\", \"base64\", or \"local\" (or LARK_DOCX2MD_WB_IMAGE_MODE)')\n .option('--image-mode <mode>', 'Image handling mode: \"local\" or \"online\" (or LARK_DOCX2MD_IMAGE_MODE)')\n .argument('<url>', 'Feishu wiki document URL: https://*.feishu.cn/wiki/*')\n .action(async (url: string, opts: { appId?: string; appSecret?: string; output?: string; agent?: boolean | string; imageMode?: string; wbImageMode?: string; wbBg?: SvgBackground; wbFormat?: string }) => {\n // ─── 环境变量默认值(直接指定 > 环境变量 > 内置默认值)────────────────\n opts.appId = opts.appId ?? process.env.LARK_DOCX2MD_APP_ID;\n opts.appSecret = opts.appSecret ?? process.env.LARK_DOCX2MD_APP_SECRET;\n opts.output = opts.output ?? process.env.LARK_DOCX2MD_OUTPUT ?? './larkDocx2mdOutput';\n // 解析 --agent:可能为 undefined | true | 'local' | 其他字符串\n if (opts.agent === undefined) {\n const envAgent = process.env.LARK_DOCX2MD_AGENT;\n if (envAgent === 'true') opts.agent = true;\n else if (envAgent === 'local') opts.agent = 'local';\n else opts.agent = false;\n } else if (typeof opts.agent === 'string' && opts.agent !== 'local') {\n program.error(`Invalid --agent value \"${opts.agent}\", only \"local\" is supported (or omit the value)`);\n }\n const agentEnabled = opts.agent === true || opts.agent === 'local';\n const agentLocal = opts.agent === 'local';\n\n opts.imageMode = opts.imageMode ?? process.env.LARK_DOCX2MD_IMAGE_MODE ?? 'local';\n opts.wbFormat = opts.wbFormat ?? process.env.LARK_DOCX2MD_WB_FORMAT;\n opts.wbBg = opts.wbBg ?? process.env.LARK_DOCX2MD_WB_BG ?? 'none';\n opts.wbImageMode = opts.wbImageMode ?? process.env.LARK_DOCX2MD_WB_IMAGE_MODE ?? 'local';\n\n // 设置 wb-format 默认值:--agent local 默认 inline-svg(兼容本地画板图片),--agent(在线)默认 yaml,其余 svg\n if (!opts.wbFormat) {\n opts.wbFormat = agentEnabled ? 'yaml' : 'svg';\n }\n\n if (agentEnabled) {\n setLogLevel(LoggerLevel.error);\n if (agentLocal) {\n // --agent local:图片/画板图片均落盘\n opts.imageMode = 'local';\n opts.wbImageMode = 'local';\n } else {\n // --agent(在线):一律在线,且画板仅支持内嵌形式\n opts.imageMode = 'online';\n opts.wbImageMode = 'online';\n }\n if (!['inline-svg', 'yaml'].includes(opts.wbFormat)) {\n program.error(`Agent mode only supports \"inline-svg\" or \"yaml\" for --wb-format`);\n }\n } else {\n // yaml 格式图片仅支持 online\n if (opts.wbFormat === 'yaml') {\n opts.wbImageMode = 'online';\n }\n }\n\n if (opts.imageMode && !['local', 'online'].includes(opts.imageMode)) {\n program.error(`Invalid --image-mode \"${opts.imageMode}\", must be \"local\" or \"online\"`);\n }\n if (!['base64', 'inline-svg', 'svg', 'yaml'].includes(opts.wbFormat)) {\n program.error(`Invalid --wb-format \"${opts.wbFormat}\", must be \"base64\", \"inline-svg\", \"svg\", or \"yaml\"`);\n }\n if (!['online', 'base64', 'local'].includes(opts.wbImageMode)) {\n program.error(`Invalid --wb-image-mode \"${opts.wbImageMode}\", must be \"online\", \"base64\", or \"local\"`);\n }\n\n const appId = opts.appId!;\n const appSecret = opts.appSecret!;\n if (!appId || !appSecret) {\n program.error('Missing credentials: pass --app-id/--app-secret or set LARK_DOCX2MD_APP_ID/LARK_DOCX2MD_APP_SECRET');\n }\n\n const result = await convert({\n appId,\n appSecret,\n url,\n output: opts.output,\n imageMode: opts.imageMode as 'local' | 'online',\n wbImageMode: opts.wbImageMode as WbImageMode,\n wbBg: opts.wbBg,\n wbFormat: opts.wbFormat as WbFormat,\n agent: agentLocal ? 'local' : (opts.agent === true),\n });\n\n if (agentLocal) {\n // 本地模式:输出引导 AI 读取文件的提示词(绝对路径)\n process.stdout.write(\n `The Feishu document has been downloaded to the following absolute path:\\n` +\n `${result.filePath}\\n\\n` +\n `Please read this file to access the full markdown content.\\n`,\n );\n } else if (opts.agent === true) {\n process.stdout.write(result.markdown);\n }\n });\n\nprogram.parse();\n"],"mappings":";;;;;AAOA,MAAM,UAAU,IAAI,SAAS;AAC7B,QAAQ,KAAK,cAAc,CAAC,YAAY,6CAA6C;AAErF,QACG,QAAQ,WAAW,CACnB,MAAM,KAAK,CACX,YAAY,uCAAuC,CACnD,OAAO,iBAAiB,mDAAmD,CAC3E,OAAO,yBAAyB,2DAA2D,CAC3F,OAAO,sBAAsB,4CAA4C,CACzE,OAAO,kBAAkB,yLAAuL,CAChN,OAAO,wBAAwB,yGAAiG,CAChI,OAAO,mBAAmB,iGAA2F,CACrH,OAAO,0BAA0B,8FAAwF,CACzH,OAAO,uBAAuB,4EAAwE,CACtG,SAAS,SAAS,uDAAuD,CACzE,OAAO,OAAO,KAAa,SAA+K;AAEzM,MAAK,QAAQ,KAAK,SAAS,QAAQ,IAAI;AACvC,MAAK,YAAY,KAAK,aAAa,QAAQ,IAAI;AAC/C,MAAK,SAAS,KAAK,UAAU,QAAQ,IAAI,uBAAuB;AAEhE,KAAI,KAAK,UAAU,KAAA,GAAW;EAC5B,MAAM,WAAW,QAAQ,IAAI;AAC7B,MAAI,aAAa,OAAQ,MAAK,QAAQ;WAC7B,aAAa,QAAS,MAAK,QAAQ;MACvC,MAAK,QAAQ;YACT,OAAO,KAAK,UAAU,YAAY,KAAK,UAAU,QAC1D,SAAQ,MAAM,0BAA0B,KAAK,MAAM,kDAAkD;CAEvG,MAAM,eAAe,KAAK,UAAU,QAAQ,KAAK,UAAU;CAC3D,MAAM,aAAa,KAAK,UAAU;AAElC,MAAK,YAAY,KAAK,aAAa,QAAQ,IAAI,2BAA2B;AAC1E,MAAK,WAAW,KAAK,YAAY,QAAQ,IAAI;AAC7C,MAAK,OAAO,KAAK,QAAQ,QAAQ,IAAI,sBAAsB;AAC3D,MAAK,cAAc,KAAK,eAAe,QAAQ,IAAI,8BAA8B;AAGjF,KAAI,CAAC,KAAK,SACR,MAAK,WAAW,eAAe,SAAS;AAG1C,KAAI,cAAc;AAChB,cAAY,YAAY,MAAM;AAC9B,MAAI,YAAY;AAEd,QAAK,YAAY;AACjB,QAAK,cAAc;SACd;AAEL,QAAK,YAAY;AACjB,QAAK,cAAc;;AAErB,MAAI,CAAC,CAAC,cAAc,OAAO,CAAC,SAAS,KAAK,SAAS,CACjD,SAAQ,MAAM,kEAAkE;YAI9E,KAAK,aAAa,OACpB,MAAK,cAAc;AAIvB,KAAI,KAAK,aAAa,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,KAAK,UAAU,CACjE,SAAQ,MAAM,yBAAyB,KAAK,UAAU,gCAAgC;AAExF,KAAI,CAAC;EAAC;EAAU;EAAc;EAAO;EAAO,CAAC,SAAS,KAAK,SAAS,CAClE,SAAQ,MAAM,wBAAwB,KAAK,SAAS,qDAAqD;AAE3G,KAAI,CAAC;EAAC;EAAU;EAAU;EAAQ,CAAC,SAAS,KAAK,YAAY,CAC3D,SAAQ,MAAM,4BAA4B,KAAK,YAAY,2CAA2C;CAGxG,MAAM,QAAQ,KAAK;CACnB,MAAM,YAAY,KAAK;AACvB,KAAI,CAAC,SAAS,CAAC,UACb,SAAQ,MAAM,qGAAqG;CAGrH,MAAM,SAAS,MAAM,QAAQ;EAC3B;EACA;EACA;EACA,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB,aAAa,KAAK;EAClB,MAAM,KAAK;EACX,UAAU,KAAK;EACf,OAAO,aAAa,UAAW,KAAK,UAAU;EAC/C,CAAC;AAEF,KAAI,WAEF,SAAQ,OAAO,MACb,4EACG,OAAO,SAAS,kEAEpB;UACQ,KAAK,UAAU,KACxB,SAAQ,OAAO,MAAM,OAAO,SAAS;EAEvC;AAEJ,QAAQ,OAAO"}
@@ -15,7 +15,7 @@ interface ConvertOptions {
15
15
  wbImageMode: WbImageMode;
16
16
  wbBg: SvgBackground;
17
17
  wbFormat: WbFormat;
18
- agent?: boolean;
18
+ agent?: boolean | 'local';
19
19
  }
20
20
  interface ConvertResult {
21
21
  markdown: string;
@@ -34,4 +34,4 @@ declare function convert(opts: ConvertOptions): Promise<ConvertResult>;
34
34
 
35
35
  //#endregion
36
36
  export { convert, parseWikiUrl };
37
- //# sourceMappingURL=converter-RbBjQFTa.d.ts.map
37
+ //# sourceMappingURL=converter-Bxdyw2k9.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter-Bxdyw2k9.d.ts","names":[],"sources":["../src/types.ts","../src/converter.ts"],"mappings":";;;;AAsCa,KAhBD,SAAA,GAgBC,OAAA,GAAA,QAAA;AACE,KAdH,WAAA,GAcG,QAAA,GAAA,QAAA,GAAA,OAAA;AACP,KAZI,QAAA,GAYJ,QAAA,GAAA,YAAA,GAAA,KAAA,GAAA,MAAA;AACI,KAVA,aAAA,GAUA,MAAA,GAAA,KAAA,GAAA,CAAA,MAAA,GAAA,CAAA,CAAA,CAAA;AAAQ,UARH,cAAA,CAQG;EASH,KAAA,EAAA,MAAA;;;;ECnCD,SAAA,EDuBH,SCvBe;EAQN,WAAO,EDgBd,WChBc;EAAA,IAAA,EDiBrB,aCjBqB;UAAQ,EDkBzB,QClByB;OAAyB,CAAA,EAAA,OAAA,GAAA,OAAA;;AAAD,UD2B5C,aAAA,CC3B4C;;;;;;;;iBAR7C,YAAA;;EDOJ,QAAA,EAAA,MAAS;AAGrB,CAAA;AAGY,iBCLU,OAAA,CDKF,IAAA,ECLiB,cDKjB,CAAA,ECLkC,ODKlC,CCL0C,aDK1C,CAAA;AAGpB"}