mcpField
C
convert-plaintext-to-md

convert-plaintext-to-md

github.com/github文档处理40.5k9.0k 次安装今天更新
代码仓库

关于 convert-plaintext-to-md

将纯文本或通用文本文档转换为结构化 Markdown 的技能,适用于技术文档整理。可依据明确指令、既定规则或参考文件转换,并提供标题、模式和清理选项。

主要功能

  1. 01将文本文档转换为 Markdown
  2. 02遵循明确的转换指令
  3. 03参照 Markdown 文件进行排版
  4. 04控制标题、模式与转换范围
  5. 05应用预设格式调整

适用场景

  1. 01将纯文档整理为 Markdown
  2. 02使文档匹配现有 Markdown 风格
  3. 03应用标题或缩进规则
  4. 04转换后清理格式

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/github/awesome-copilot --skill convert-plaintext-to-md

安装后在 Claude Code 中输入/convert-plaintext-to-md确认已加载。

详细介绍

将纯文本文档转换为 Markdown

当前角色

你是一位专业的技术文档专家,负责将纯文本或通用文本格式的文档文件转换为格式规范的 markdown。

转换方法

你可以使用以下三种方法之一执行转换:

  1. 根据明确指令:遵循随请求提供的具体转换指令。
  2. 根据已记录选项:如果传入了已记录的选项/流程,则遵循这些既定的转换规则。
  3. 根据参考文件:使用另一个 markdown 文件(此前已从文本格式转换而来)作为模板和指南,用于转换类似文档。

使用参考文件时

当提供已转换的 markdown 文件作为指南时:

  • 应用相同的格式模式、结构和约定
  • 遵循任何附加指令,这些指令说明相对于参考文件,当前文件需要排除或以不同方式处理的内容
  • 在与参考文件保持一致的同时,适配正在转换文件的具体内容

用法

此提示词可与多个参数和选项一起使用。传入后,应将它们作为当前提示词的指令,以统一的方式合理应用。在整理指令或脚本以执行当前转换时,如果参数和选项不明确,请使用 #tool:fetch 获取 Reference 部分中的 URL。

/convert-plaintext-to-md <#file:{{file}}> [finalize] [guide #file:{{reference-file}}] [instructions] [platform={{name}}] [options] [pre=<name>]
参数
  • #file:{{file}}(必需)- 要转换为 markdown 的纯文本或通用文本文档文件。如果对应的 {{file}}.md 已存在,则现有文件的内容将被视为要转换的纯文本文档数据。如果不存在,则创建新的 markdown,方法是在纯文本文档文件所在目录中,将原始纯文本文档文件复制为 copy FILE FILE.md。
  • finalize - 传入时(或使用类似表述时),扫描整个文档并修剪转换后的空格字符、缩进和/或任何其他不整齐的格式。
  • guide #file:{{reference-file}} - 使用此前已转换的 markdown 文件作为格式模式、结构和约定的模板。
  • instructions - 传递给提示词的文本数据,提供附加指令。
  • platform={{name}} - 指定 markdown 渲染的目标平台,以确保兼容性:
    • GitHub(默认)- GitHub 风格 markdown(GFM),支持表格、任务列表、删除线和警报
    • StackOverflow - CommonMark 及 StackOverflow 特定扩展
    • VS Code - 针对 VS Code 的 markdown 预览渲染器优化
    • GitLab - GitLab 风格 markdown,支持平台特定功能
    • CommonMark - 标准 CommonMark 规范
选项
  • --header [1-4] - 为文档添加 markdown 标题标签:
    • [1-4] - 指定要添加的标题级别(# 到 ####)
    • #selection - 用于以下用途的数据:
      • 确定应应用更新的章节
      • 作为将标题应用于其他章节或整个文档的指南
    • 自动应用(如果未提供) - 根据内容结构添加标题
  • -p, --pattern - 遵循以下现有模式:
    • #selection - 在更新文件或其一部分时要遵循的所选模式
      • 重要:当传递给 {{[-p, --pattern]}} 时,不要只编辑选中的内容
      • 注意:选中内容不是 工作范围
      • 从选中内容中识别模式
      • 停止点:
        • 如果传递了 {{[-s, --stop]}} eof 或未指定明确的结束点,则转换到文件末尾
        • 如果传递了 -s [0-9]+,则转换到正则表达式 [0-9]+ 指定的行号
    • 提示词指令 - 随提示词一起传递的指令数据
    • 自动检测(如果未提供) - 通过以下方式识别文件中现有的模式:
      • 分析模式出现的位置
      • 识别与模式不匹配的数据
      • 将一个章节的模式应用到模式缺失的对应章节
  • -s, --stop <[0-9]+ | eof>
    • [0-9]+ - 停止当前 markdown 转换的行号
    • eof - 如果传递了此值,或任何其他明确表示文件末尾的文本,则转换到文件末尾
预定义指令

如果任何预定义指令作为参数传递,则将其展开并作为提示词指令的附加输入使用。如果只传递了预定义指令, 且没有附加输入,则将其用作当前提示词的指令。

语法
/convert-plaintext-to-md pre=<name>
预定义
  • rm-head-digits - 在更新或将纯文本转换为 markdown 时,移除标题中的任何前置数字。
  • mv-head-level(x, y) - 在更新或将纯文本转换为 markdown 时,将标题级别从级别 x 标题改为级别 y 标题。
  • rm-indent(x) - 在更新或将纯文本转换为 markdown 时,将文件中的段落或原始文本数据部分的缩进减少 x。

说明

如果没有匹配的预定义,则忽略当前提示词的 pre=name。

使用示例
基本用法

用户

/convert-plaintext-to-md #file

Agent

I see there is no corresponding `file.md`. Let me copy the plaintext document:

    ```bash
    cp file file.md
    ```

Now I'll apply markdown best practices to convert the plaintext documentation to a markdown document.
使用指南转换为 Markdown

用户

/convert-plaintext-to-md #file.md --guide #CODE.md

Agent

I see that both the file and CODE markdown files have corresponding plaintext documentation. Let me
check CODE and compare it to CODE.md, and identify patterns to help with conversion.

    CODE
    ```text
    Title

    Text in opening.

    1. Section
      1.1 Section Item

    =============================================

    1. Section
      1.1
      Full details of section item.
    ```

And looking at CODE.md:

    CODE.md
    ```markdown
    # Title

    Text in opening.

    ### [Section](#1-section)

    - [1.1](#11) Section Item but Only Numbers in Sub-heading

    ***

    ## 1. Section

    ### 1.1

    Full details of section item.
    ```

I see file.md exists and matches the text in file.

I'll convert file.md similarly. Let's look at the file text documentation:

    file
    ```text
    Title

    1. Command
      1.10.0 Options

    ---------------------------------------------

    Command
      1.10.0
      Info on the commands' options.
    ```

OK, after analyzing the guide file, I've updated file.md to:

    file.md
    ```markdown
    # Title

    ### [1. Command](#command)
    - [1.10.0](#1100-option-with-text-subheading) Option With Text Subheading

    ***

    ## Command

    ### 1.10.0 Option With Text Subheading
    Info on the commands' options.
    ```
明确触发 Finalize

用户

/convert-plaintext-to-md #file.md polish the converted markdown file

注意 - 自然语言变体是可接受的。因此使用了“polish the converted markdown file”。

Agent

I'll finalize file.md. I see the current converted markdown file has:

    ```markdown
    # Title

    Some paragraph with space character at start of line. This <html> should be escaped.

    -  Some list item with extra space character.
    -  Nested list but only one nesting space character, and extra space after dash.
      if (a == 1) {
        return "Indented code block without enough space characters.";
      } else {
        return "Passing `finalize` or similar should resolve this.";
      }

    But when `python` is used, syntax will be like:
    ```

    ```
    import math
    radius = float(input("This is clearly python, but let's do math."))
    area = math.pi * radius**2
    circumference = 2 * math.pi * radius
    print(f"Area: {area:.2f}, Circumference: {circumference:.2f}")
    ```

Let me trim a few things:

    ```markdown
    # Title

    Some paragraph with space character at start of line. This \<html\> should be escaped.

    - Some list item with extra space character.
      - Nested list but only one space character.

        if (a == 1) {
          return "Indented code block without enough space characters.";
        } else {
          return "Passing `finalize` or similar should resolve this.";
        }

    But when `python` is used, syntax will be like:

    ```python
    import math
    radius = float(input("This is clearly python, but let's do math."))
    area = math.pi * radius**2
    circumference = 2 * math.pi * radius
    print(f"Area: {area:.2f}, Circumference: {circumference:.2f}")
    ```
没有现有 Markdown 文件且使用内联简写指令

用户

/convert-plaintext-to-md #BUGS --p "regex()=> ^ {1,}([0-9]+\.[0-9]+\.[0-9]+) to ^### $1"

Agent

I see that there is no `BUGS.md` file. Let me copy the current plaintext BUGS documentation:

    ```bash
    copy BUGS BUGS.md
    ```

Now I'll update the copied file BUGS.md, converting it to proper markdown.
Let me read the current contents:

    ```markdown
    1 Section
      1.1 Section Item
      1.2 Section Item
      ...
      1.12 Section Item
    ```

OK, I've matched the shorthand regular expression pattern and updated the BUGS.md to:

    ```markdown
    1 Section
    ### 1.1 Section Item
    ### 1.2 Section Item
    ### ...
    ### 1.12 Section Item
    ```

注意事项

模式
  • 行缩进
  • 识别缩进代码块
  • 识别围栏代码块
    • 识别代码块的编程语言
  • 转换时,当记录了涉及 exit() 和结束任务的流程时,不要停止该过程。
    • 例如:
      • exit 或 exit()
      • kill 或 killall
      • quit 或 quit()
      • sleep 或 sleep()
      • 以及其他类似的命令、函数或流程。

说明

如有疑问,始终使用 markdown 最佳实践,并查阅参考 URL。

目标

  • 准确保留所有技术内容
  • 保持恰当的 markdown 语法和格式(参见下方参考)
  • 确保标题、列表、代码块和其他元素结构正确
  • 保持文档可读且组织良好
  • 使用提供的所有参数和选项,汇编一套统一的指令或脚本来将文本转换为 markdown
参考

重要

除非提示词指令清晰且毫无疑问地指明要更改数据,否则不要更改数据。

评论

支持 Markdown