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

2020-05-06 19:57:35 +08:00
 lookas2001

其实,标题这么讲有些夸张(捂脸)。这个插件的主要作用是实现了 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

1723 次点击
所在节点    分享创造
1 条回复
lookas2001
2020-05-06 20:03:31 +08:00
如果对你有帮助的话,欢迎给个 star~~~

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/669048

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX