V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
lookas2001
V2EX  ›  分享创造

写了一个 markdown-it 拓展,让你的 Markdown 变的更加强大!(markdown-it-directive)

  •  
  •   lookas2001 · 2020-05-06 19:57:35 +08:00 · 1721 次点击
    这是一个创建于 1452 天前的主题,其中的信息可能已经有所发展或是发生改变。

    其实,标题这么讲有些夸张(捂脸)。这个插件的主要作用是实现了 Generic directives/plugins syntax spec 标准,配合另外一个插件 markdown-it-directive-webcomponents 可以将 WebComponents 嵌入到 Markdown 文档中。这样可以很大程度上减轻为 Markdown 拓展功能所需要的写代码负担。

    具体来讲,可以将:

    text before :directive-name[content](/link "destination" /another "one"){.class #id name=value name="string!"} text after
    
    :: directive-name [inline content] (/link "destination" /another "one") {.class #id name=value name="string!"} content title ::
    
    ::: directive-name [inline content] (/link "destination" /another "one") {.class #id name=value name="string!"} content title ::
    content
    :::
    

    配合 markdown-it 解析成:

    <p>text before <tag-name class="class" id="id" name="value" src="/link" title="destination">content</tag-name> text after</p>
    
    <tag-name class="class" id="id" name="value" src="/link" title="destination">inline content</tag-name>
    
    <tag-name class="class" id="id" name="value" src="/link" title="destination">
    <p>content</p>
    </tag-name>
    

    接下来就可以用 Vue 这种框架来渲染结果啦~~~

    希望能为需要的人带来帮助!

    项目地址:

    markdown-it-directive: https://github.com/hilookas/markdown-it-directive
    markdown-it-directive-webcomponents: https://github.com/hilookas/markdown-it-directive-webcomponents

    1 条回复    2020-05-06 20:03:31 +08:00
    lookas2001
        1
    lookas2001  
    OP
       2020-05-06 20:03:31 +08:00
    如果对你有帮助的话,欢迎给个 star~~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1153 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:01 · PVG 02:01 · LAX 11:01 · JFK 14:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.