mirror of https://github.com/vuejs/vitepress
commit
846498bc89
@ -1,29 +0,0 @@
|
|||||||
diff --git a/types/index.d.ts b/types/index.d.ts
|
|
||||||
index 7c94aae194faa66ca006ace98cdb0dee82a3e471..0377cace7c4a9653d4ecf963babffd4bd68494b0 100644
|
|
||||||
--- a/types/index.d.ts
|
|
||||||
+++ b/types/index.d.ts
|
|
||||||
@@ -1,10 +1,10 @@
|
|
||||||
-import MarkdownIt = require('markdown-it');
|
|
||||||
-import Token = require('markdown-it/lib/token');
|
|
||||||
-import State = require('markdown-it/lib/rules_core/state_core');
|
|
||||||
+import MarkdownIt from 'markdown-it';
|
|
||||||
+import Token from 'markdown-it/lib/token.mjs';
|
|
||||||
+import StateCore from 'markdown-it/lib/rules_core/state_core.mjs';
|
|
||||||
|
|
||||||
declare namespace anchor {
|
|
||||||
- export type RenderHref = (slug: string, state: State) => string;
|
|
||||||
- export type RenderAttrs = (slug: string, state: State) => Record<string, string | number>;
|
|
||||||
+ export type RenderHref = (slug: string, state: StateCore) => string;
|
|
||||||
+ export type RenderAttrs = (slug: string, state: StateCore) => Record<string, string | number>;
|
|
||||||
|
|
||||||
export interface PermalinkOptions {
|
|
||||||
class?: string,
|
|
||||||
@@ -37,7 +37,7 @@ declare namespace anchor {
|
|
||||||
placement?: 'before' | 'after'
|
|
||||||
}
|
|
||||||
|
|
||||||
- export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: State, index: number) => void;
|
|
||||||
+ export type PermalinkGenerator = (slug: string, opts: PermalinkOptions, state: StateCore, index: number) => void;
|
|
||||||
|
|
||||||
export interface AnchorInfo {
|
|
||||||
slug: string;
|
|
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,50 @@
|
|||||||
import type MarkdownIt from 'markdown-it'
|
import type MarkdownIt from 'markdown-it'
|
||||||
|
import type StateCore from 'markdown-it/lib/rules_core/state_core.mjs'
|
||||||
|
import type Token from 'markdown-it/lib/token.mjs'
|
||||||
|
import { escapeHtml } from '../../shared'
|
||||||
|
|
||||||
export function restoreEntities(md: MarkdownIt): void {
|
export function restoreEntities(md: MarkdownIt): void {
|
||||||
md.core.ruler.disable('text_join')
|
md.core.ruler.at('text_join', text_join)
|
||||||
md.renderer.rules.text_special = (tokens, idx) => {
|
md.renderer.rules.text = (tokens, idx) => escapeHtml(tokens[idx].content)
|
||||||
if (tokens[idx].info === 'entity') {
|
|
||||||
return tokens[idx].markup // leave as is so Vue can handle it
|
|
||||||
}
|
}
|
||||||
return md.utils.escapeHtml(tokens[idx].content)
|
|
||||||
|
function text_join(state: StateCore): void {
|
||||||
|
let curr, last
|
||||||
|
const blockTokens = state.tokens
|
||||||
|
const l = blockTokens.length
|
||||||
|
|
||||||
|
for (let j = 0; j < l; ++j) {
|
||||||
|
if (blockTokens[j].type !== 'inline') continue
|
||||||
|
|
||||||
|
const tokens = blockTokens[j].children || []
|
||||||
|
const max = tokens.length
|
||||||
|
|
||||||
|
for (curr = 0; curr < max; ++curr)
|
||||||
|
if (tokens[curr].type === 'text_special') tokens[curr].type = 'text'
|
||||||
|
|
||||||
|
for (curr = last = 0; curr < max; ++curr)
|
||||||
|
if (
|
||||||
|
tokens[curr].type === 'text' &&
|
||||||
|
curr + 1 < max &&
|
||||||
|
tokens[curr + 1].type === 'text'
|
||||||
|
) {
|
||||||
|
tokens[curr + 1].content =
|
||||||
|
getContent(tokens[curr]) + getContent(tokens[curr + 1])
|
||||||
|
tokens[curr + 1].info = ''
|
||||||
|
tokens[curr + 1].markup = ''
|
||||||
|
} else {
|
||||||
|
if (curr !== last) tokens[last] = tokens[curr]
|
||||||
|
++last
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curr !== last) tokens.length = last
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getContent(token: Token): string {
|
||||||
|
return token.info === 'entity'
|
||||||
|
? token.markup
|
||||||
|
: token.info === 'escape' && token.content === '&'
|
||||||
|
? '&'
|
||||||
|
: token.content
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue