简介
@gerhobbelt/markdown-it-abbr 是一款用于 markdown 渲染的 npm 包,它可以快速创建缩写词,并在文本中自动解析和渲染这些缩写。
安装
在你的项目中输入以下命令,即可安装 @gerhobbelt/markdown-it-abbr:
npm install @gerhobbelt/markdown-it-abbr --save
使用
安装好包之后,你需要引入该包并在 markdown-it 的配置中启用它。
const md = require('markdown-it')(); const abbr = require('@gerhobbelt/markdown-it-abbr'); md.use(abbr);
之后你就可以在 markdown 中添加以下的缩写标记:
*[HTML]: Hyper Text Markup Language *[CSS]: Cascading Style Sheets *[API]: Application Programming Interface
它们以星号和中括号的组合形式出现,其中星号后面是缩写词的解释,中括号里面是缩写词本身。
当你在 markdown 中使用该缩写词时,它会自动解析并渲染缩写词的含义:
HTML is a markup language. CSS is used for styling. We interact with APIs for building applications.
上述 markdown 输入将被渲染成如下 HTML 输出:
<p><abbr title="Hyper Text Markup Language">HTML</abbr> is a markup language. <abbr title="Cascading Style Sheets">CSS</abbr> is used for styling. We interact with <abbr title="Application Programming Interface">API</abbr>s for building applications.</p>
其中 <abbr>
标签包裹了缩写词,并使用 title 属性显示缩写词的解释。
结论
@gerhobbelt/markdown-it-abbr 是一个方便快捷的 npm 包,可以帮助我们创建缩写词并自动解析和渲染这些缩写。它的使用方法简单明了,适用于各种前端项目中 markdown 渲染的场景。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/5f02c870403f2923b035bd71