mirror of https://github.com/vuejs/vitepress
commit
9ba446ce46
@ -0,0 +1,23 @@
|
||||
diff --git a/index.d.ts b/index.d.ts
|
||||
index 41d4a858c6ece5a61a2088733cf8b333b45603d8..2cb19bcd8fc76ae82ebe87af742916e17f49334b 100644
|
||||
--- a/index.d.ts
|
||||
+++ b/index.d.ts
|
||||
@@ -1,3 +1,15 @@
|
||||
-import MarkdownIt = require("markdown-it");
|
||||
-declare function attrs(md: MarkdownIt): void;
|
||||
-export = attrs;
|
||||
+import type MarkdownIt from 'markdown-it'
|
||||
+
|
||||
+export interface MarkdownItAttrsOptions {
|
||||
+ /** left delimiter, default is `{`(left curly bracket) */
|
||||
+ leftDelimiter?: string
|
||||
+ /** right delimiter, default is `}`(right curly bracket) */
|
||||
+ rightDelimiter?: string
|
||||
+ /** rule of allowed attribute, empty means no limit */
|
||||
+ allowedAttributes?: (string | RegExp)[]
|
||||
+}
|
||||
+
|
||||
+export default function attrsPlugin(
|
||||
+ md: MarkdownIt,
|
||||
+ options?: MarkdownItAttrsOptions
|
||||
+): void
|
||||
@ -0,0 +1,14 @@
|
||||
diff --git a/patterns.js b/patterns.js
|
||||
index e56a3b785df29e726194f2b30e86bb19a78ef902..e1f6211b92cbb2bbbe2a3c317dd9e5f1f41ab8d1 100644
|
||||
--- a/patterns.js
|
||||
+++ b/patterns.js
|
||||
@@ -28,7 +28,8 @@ module.exports = options => {
|
||||
{
|
||||
shift: 0,
|
||||
block: true,
|
||||
- info: utils.hasDelimiters('end', options)
|
||||
+ info: utils.hasDelimiters('end', options),
|
||||
+ markup: (str) => !/^[`~]{3,}$/.test(str)
|
||||
}
|
||||
],
|
||||
transform: (tokens, i) => {
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,48 +0,0 @@
|
||||
// Modified from https://github.com/egoist/markdown-it-highlight-lines
|
||||
// Now this plugin is only used to normalize line attrs.
|
||||
// The else part of line highlights logic is in './highlight.ts'.
|
||||
|
||||
import type { MarkdownItAsync } from 'markdown-it-async'
|
||||
|
||||
const RE = /{([\d,-]+)}/
|
||||
|
||||
export const highlightLinePlugin = (md: MarkdownItAsync) => {
|
||||
const fence = md.renderer.rules.fence!
|
||||
md.renderer.rules.fence = (...args) => {
|
||||
const [tokens, idx] = args
|
||||
const token = tokens[idx]
|
||||
|
||||
// due to use of markdown-it-attrs, the {0} syntax would have been
|
||||
// converted to attrs on the token
|
||||
const attr = token.attrs && token.attrs[0]
|
||||
|
||||
let lines = null
|
||||
|
||||
if (!attr) {
|
||||
// markdown-it-attrs maybe disabled
|
||||
const rawInfo = token.info
|
||||
|
||||
if (!rawInfo || !RE.test(rawInfo)) {
|
||||
return fence(...args)
|
||||
}
|
||||
|
||||
const langName = rawInfo.replace(RE, '').trim()
|
||||
|
||||
// ensure the next plugin get the correct lang
|
||||
token.info = langName
|
||||
|
||||
lines = RE.exec(rawInfo)![1]
|
||||
}
|
||||
|
||||
if (!lines) {
|
||||
lines = attr![0]
|
||||
|
||||
if (!lines || !/[\d,-]+/.test(lines)) {
|
||||
return fence(...args)
|
||||
}
|
||||
}
|
||||
|
||||
token.info += ' ' + lines
|
||||
return fence(...args)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue