跳到正文
Skillpedia
API 与服务器(后端)5.1k · #15051

migrate-goldmark-extension-v1-to-v2

它能做什么

它为让扩展在 goldmark v2 中正常运行所需的改动制定计划并执行,包括如何编写新式扩展。适合维护 goldmark 扩展的 Go 开发者。

适用场景

  • ✓当你维护一个 goldmark 扩展,并希望它能与 v2 配合使用时。
  • ✓当你需要学习如何为 v2 编写 goldmark 扩展时。
  • ✓当你想了解 goldmark v1 与 v2 之间针对扩展的不兼容变化时。

技能链接

https://github.com/yuin/goldmark/blob/v2/.agent-plugins/migrate-goldmark-v1-to-v2/skills/migrate-goldmark-extension-v1-to-v2/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/yuin/goldmark/blob/v2/.agent-plugins/migrate-goldmark-v1-to-v2/skills/migrate-goldmark-extension-v1-to-v2/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我把我的 goldmark 表格扩展从 v1 迁移到 v2,并告诉我怎么测试。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会先写出迁移计划供你批准,然后更新扩展代码,并用你选择的示例进行测试。它会参考关于创建扩展和不兼容变化的指南。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

migrate-goldmark-extension-v1-to-v2

Description

This skill helps you migrate a goldmark (https://github.com/yuin/goldmark) extension from version 1 to version 2. It provides guidance on the changes needed to update your project to be compatible with the new version of goldmark.

Knowledges

  • CommonMark key points : List of key points of CommonMark spec that you should be aware of when implementing a goldmark extension.
  • Breaking changes in v2 : List of breaking changes in goldmark v2 that you should be aware of when migrating your extension from v1 to v2.
  • How to create an extension : Guide on how to create a goldmark extension in v2, including the new extension pattern and how to implement parser and renderer extensions.

Migration steps

Overview of the migration process

  • Create a migration plan for the extension.
  • MUST ask human to confirm that the migration plan is acceptable before proceeding with the migration.
  • MUST ask human to how to test the extension after migration before proceeding with the migration.
    • e.g. : "How do you want to test the extension after migration? Do you have any test cases or examples that you want to use for testing?"
  • Execute the migration plan to update the extension code to be compatible with goldmark v2.
  • Update the test cases to ensure that the extension works as expected with goldmark v2.
  • Test the extension with goldmark v2 to ensure that it works as expected. If there are any issues, fix them and re-test until the extension works as expected.
  • Update the documentation to reflect any changes made during the migration process.

Create a migration plan

Task

  • Make sure you have read and understood the Breaking changes in v2 document.
  • Make sure you have read and understood the How to create an extension document.
  • You create a ./features/goldmark-migration-plan.md file that contains a migration plan for the extension.

Key points to consider when migrating your extension

Extension options
  • If the extension uses "unified" options for both parser and renderer, they should be split into separate options for each.
    • e.g. :
      • v1
        type Option interface {
            myOption()
        }
        
        type ParserOption interface {
            Option
            applyParserOption(*parserConfig)
        }
        
        type RendererOption interface {
            Option
            applyRendererOption(*rendererConfig)
        }
        
        func New(opts ...Option) goldmark.Extender { // takes unified options
            // ...
        }
        
      • v2
        type ParserOption interface {
            applyParserOption(*parserConfig)
        }
        
        type HTMLRendererOption interface { // explicitly named for **HTML**
            applyRendererOption(*htmlRendererConfig) // you can access the shared renderer config like `XHTML` or `Unsafe` in the renderer config
        }
        
        func NewParser(opts ...ParserOption) parser.Extension { // takes parser options
            // ...
        }
        
        func NewHTMLRenderer(opts ...HTMLRendererOption) html.Extension { // takes renderer options
            // ...
        }
        
AST nodes
  • use text.Value(single line), text.MultiLineValue(multi-line) instead of []byte for values that can be parsed from source text in inline AST nodes.
    • In your parser, you must choose text.Decoder implementation to decode the source value
      • text.IdentityDecoder : for raw contents like inline HTMLs, inline code, etc.
      • reader.Decoder : other contents like text, links, etc. This decoder decodes entity references, \ escapes, etc.
    • In most cases, you will choose text.Decoder. DO NOT use text.IdentityDecoder unless you have a clear intention to do so.
  • use text.Lines instead of []text.Segment for values in block AST nodes that have raw contents like HTML blocks, code blocks, etc.
  • Properties in AST Dump should be text.Value as possible.
    • e.g.
      • OK:
        // Dump implements Node.Dump.
        func (n *Text) Dump(_ []byte) *NodeDump {
            m := map[string]any{
                "Value": n.Value, // text.Value
            }
            fs := textFlagsString(n.flags)
            if len(fs) != 0 {
                m["Flags"] = fs
            }
            return NewNodeDump(n, m)
        
常见问题

智能体会用我自己的示例来测试吗?

它会询问你希望如何测试该扩展,并使用你提供的测试用例或示例。

改代码之前需要我批准吗?

需要。迁移计划必须先经你确认。

它也涵盖编写新扩展吗?

涵盖。它包含一份关于如何在 v2 中创建扩展的指南。

详情

作者的原始描述

Migrate goldmark extension from goldmark v1 to v2.

repo: yuin/goldmark

热度

GitHub 星标
5.1k
排名
#15051
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能