@kaciras-blog/markdown
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -6,5 +6,7 @@ import AnchorRaw from "markdown-it-anchor"; | ||
export { default as Media } from "./media.js"; | ||
/** | ||
* 给标题加上锚点,是对 markdown-it-anchor 的简单封装。 | ||
*/ | ||
export function Anchor(markdownIt) { | ||
markdownIt.use(Anchor, { | ||
// 参考 MSDN 网站的做法,有 aria-labelledby 情况下不再需要内容 | ||
markdownIt.use(AnchorRaw, { | ||
permalink: AnchorRaw.permalink.linkInsideHeader({ | ||
@@ -18,2 +20,14 @@ placement: "after", | ||
} | ||
/** | ||
* 给行内代码加个 inline-code 类以便跟代码块区别开。 | ||
*/ | ||
export function Classify(markdownIt) { | ||
const { rules } = markdownIt.renderer; | ||
const raw = rules.code_inline; | ||
rules.code_inline = (tokens, idx, options, env, self) => { | ||
const token = tokens[idx]; | ||
token.attrPush(["class", "inline-code"]); | ||
return raw(tokens, idx, options, env, self); | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -11,6 +11,7 @@ import MarkdownIt from "markdown-it"; | ||
/** | ||
* 给标题加上锚点,是对 markdown-it-anchor 的简单封装。 | ||
*/ | ||
export function Anchor(markdownIt: MarkdownIt) { | ||
markdownIt.use<AnchorRaw.AnchorOptions>(Anchor, { | ||
// 参考 MSDN 网站的做法,有 aria-labelledby 情况下不再需要内容 | ||
markdownIt.use<AnchorRaw.AnchorOptions>(AnchorRaw, { | ||
permalink: AnchorRaw.permalink.linkInsideHeader({ | ||
@@ -21,5 +22,18 @@ placement: "after", | ||
}), | ||
slugify: title => title.trim().toLowerCase().replace(/\s+/g, "-"), | ||
}); | ||
} | ||
/** | ||
* 给行内代码加个 inline-code 类以便跟代码块区别开。 | ||
*/ | ||
export function Classify(markdownIt: MarkdownIt) { | ||
const { rules } = markdownIt.renderer; | ||
const raw = rules.code_inline!; | ||
rules.code_inline = (tokens, idx, options, env, self) => { | ||
const token = tokens[idx]; | ||
token.attrPush(["class", "inline-code"]); | ||
return raw(tokens, idx, options, env, self); | ||
}; | ||
} |
@@ -25,3 +25,3 @@ /* | ||
* - 无法解决用视频来模拟GIF图片的需求 | ||
* - URL必须要有扩展名,但并不是所有系统都是这样(比如Twitter) | ||
* - URL 必须要有扩展名,但并不是所有系统都是这样(比如 Twitter) | ||
* | ||
@@ -31,4 +31,4 @@ * https://gitlab.com/help/user/markdown#videos | ||
* 【为何不直接写HTML】 | ||
* Markdown本身是跟渲染结果无关的,不应该和HTML绑死,而且写HTML不利于修改。 | ||
* 而且直接写HTML安全性太差,要转义也很麻烦,难以开放给用户。 | ||
* Markdown 本身是跟渲染结果无关的,不应该和 HTML 绑死,而且写HTML不利于修改。 | ||
* 而且直接写 HTML 安全性太差,要转义也很麻烦,难以开放给用户。 | ||
*/ | ||
@@ -35,0 +35,0 @@ import MarkdownIt from "markdown-it"; |
{ | ||
"name": "@kaciras-blog/markdown", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Markdown-it plugins for Kaciras Blog", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
21545
416