diff --git a/temp/docx_parser.md b/skills/docx-reader/docx_parser.md similarity index 75% rename from temp/docx_parser.md rename to skills/docx-reader/docx_parser.md index 901d93e..dc1fa20 100644 --- a/temp/docx_parser.md +++ b/skills/docx-reader/docx_parser.md @@ -37,27 +37,27 @@ python3 docx_parser.py [options] ### 位置参数 -| 参数 | 说明 | -|------|------| +| 参数 | 说明 | +| ----------- | ------------------- | | `file_path` | DOCX 文件的绝对路径 | ### 选项参数 -| 参数 | 长参数 | 类型 | 默认值 | 说明 | -|------|--------|------|--------|------| -| `-n` | `--context` | 整数 | 2 | 与 `-s` 配合使用,指定每个检索结果包含的前后行数(不包含空行) | +| 参数 | 长参数 | 类型 | 默认值 | 说明 | +| ---- | ----------- | ---- | ------ | -------------------------------------------------------------- | +| `-n` | `--context` | 整数 | 2 | 与 `-s` 配合使用,指定每个检索结果包含的前后行数(不包含空行) | ### 互斥参数 以下参数只能使用其中一个: -| 参数 | 长参数 | 说明 | -|------|--------|------| -| `-c` | `--count` | 返回解析后的 markdown 文档的总字数 | -| `-l` | `--lines` | 返回解析后的 markdown 文档的总行数 | -| `-t` | `--titles` | 返回解析后的 markdown 文档的标题行(1-6级) | -| `-tc` | `--title-content` | 指定标题名称,输出该标题及其下级内容(不包含#号) | -| `-s` | `--search` | 使用正则表达式搜索文档,返回所有匹配结果(用---分隔) | +| 参数 | 长参数 | 说明 | +| ----- | ----------------- | ----------------------------------------------------- | +| `-c` | `--count` | 返回解析后的 markdown 文档的总字数 | +| `-l` | `--lines` | 返回解析后的 markdown 文档的总行数 | +| `-t` | `--titles` | 返回解析后的 markdown 文档的标题行(1-6级) | +| `-tc` | `--title-content` | 指定标题名称,输出该标题及其下级内容(不包含#号) | +| `-s` | `--search` | 使用正则表达式搜索文档,返回所有匹配结果(用---分隔) | ## 使用示例 @@ -92,6 +92,7 @@ python3 docx_parser.py -t /path/to/document.docx ``` 输出示例: + ``` # 主标题 ## 第一章 @@ -109,11 +110,13 @@ python3 docx_parser.py -tc "第一章" /path/to/document.docx 输出:包含所有上级标题的指定章节内容 **特点:** + - 支持多个同名标题 - 自动包含完整的上级标题链 - 包含所有下级内容 示例输出: + ``` # 主标题 ## 第一章 @@ -161,6 +164,7 @@ python3 docx_parser.py -s r"\d{4}-\d{2}-\d{2}" /path/to/document.docx ``` 输出示例: + ``` 这是前一行 包含匹配关键词 @@ -231,22 +235,10 @@ python3 docx_parser.py -s "关键词" /path/to/document.docx > search_results.md ## 常见问题 -### Q: 如何选择解析库? - -A: 建议优先安装 `markitdown`,它是微软官方库,解析效果最好。如果需要更多控制或兼容性,可以同时安装 `python-docx`。 - -### Q: 为什么某些文档解析不完整? - -A: 可能原因: -1. 文档使用特殊格式或样式 -2. 文档已损坏 -3. 未安装合适的解析库 - -尝试安装多个解析库,或检查文档是否损坏。 - ### Q: 如何处理大文档? A: 对于非常大的文档,建议: + 1. 使用 `-tc` 参数只提取需要的章节 2. 使用 `-s` 参数搜索特定内容 3. 将输出重定向到文件进行处理 @@ -284,11 +276,15 @@ A: `-tc` 参数会返回所有同名标题,每个标题都包含其完整的 ```markdown # 主标题 + ## 同名标题 1 + 内容1 # 主标题 + ## 同名标题 2 + 内容2 ``` @@ -296,36 +292,28 @@ A: `-tc` 参数会返回所有同名标题,每个标题都包含其完整的 ### 标题识别规则 -| 样式名称 | Markdown 标题级别 | -|---------|-------------------| -| Title | # | -| Heading 1 | # | -| Heading 2 | ## | -| Heading 3 | ### | -| Heading 4 | #### | -| Heading 5 | ##### | -| Heading 6 | ###### | +| 样式名称 | Markdown 标题级别 | +| --------- | ----------------- | +| Title | # | +| Heading 1 | # | +| Heading 2 | ## | +| Heading 3 | ### | +| Heading 4 | #### | +| Heading 5 | ##### | +| Heading 6 | ###### | ### 列表识别规则 -| 样式名称 | Markdown 列表格式 | -|---------|------------------| -| List Bullet / Bullet | - (无序列表) | -| List Number / Number | 1. (有序列表) | +| 样式名称 | Markdown 列表格式 | +| -------------------- | ----------------- | +| List Bullet / Bullet | - (无序列表) | +| List Number / Number | 1. (有序列表) | ### 文本格式支持 -| 格式 | 转换结果 | -|------|---------| -| 粗体 | `**文本**` | -| 斜体 | `*文本*` | -| 下划线 | `文本` | -| 表格 | Markdown 表格格式 | - -## 许可证 - -本脚本遵循相关开源许可证。 - -## 贡献 - -欢迎提交问题和改进建议。 +| 格式 | 转换结果 | +| ------ | ----------------- | +| 粗体 | `**文本**` | +| 斜体 | `*文本*` | +| 下划线 | `文本` | +| 表格 | Markdown 表格格式 | diff --git a/temp/docx_parser.py b/skills/docx-reader/scripts/docx_parser.py similarity index 100% rename from temp/docx_parser.py rename to skills/docx-reader/scripts/docx_parser.py