mirror of
https://github.com/marktext/marktext.git
synced 2025-05-04 03:01:44 +08:00
parent
c590977c09
commit
a2786b13d2
@ -45,7 +45,7 @@ div.ag-show-quick-insert-hint p.ag-paragraph.ag-active > span.ag-line:first-of-t
|
|||||||
|
|
||||||
.ag-reference-marker {
|
.ag-reference-marker {
|
||||||
font-size: .9em;
|
font-size: .9em;
|
||||||
color: var(--editorColor10);
|
color: var(--editorColor50);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ag-reference-title {
|
.ag-reference-title {
|
||||||
|
@ -93,7 +93,7 @@ const validateEmphasize = (src, offset, marker, pending) => {
|
|||||||
return lowerPriority(src, offset)
|
return lowerPriority(src, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top, labels) => {
|
||||||
const tokens = []
|
const tokens = []
|
||||||
let pending = ''
|
let pending = ''
|
||||||
let pendingStartPos = pos
|
let pendingStartPos = pos
|
||||||
@ -211,7 +211,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
range,
|
range,
|
||||||
marker,
|
marker,
|
||||||
parent: tokens,
|
parent: tokens,
|
||||||
children: tokenizerFac(to[2], undefined, inlineRules, pos + to[1].length, false),
|
children: tokenizerFac(to[2], undefined, inlineRules, pos + to[1].length, false, labels),
|
||||||
backlash: to[3]
|
backlash: to[3]
|
||||||
})
|
})
|
||||||
src = src.substring(to[0].length)
|
src = src.substring(to[0].length)
|
||||||
@ -252,7 +252,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
range,
|
range,
|
||||||
marker,
|
marker,
|
||||||
parent: tokens,
|
parent: tokens,
|
||||||
children: tokenizerFac(to[2], undefined, inlineRules, pos + to[1].length, false),
|
children: tokenizerFac(to[2], undefined, inlineRules, pos + to[1].length, false, labels),
|
||||||
backlash: to[3]
|
backlash: to[3]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
start: pos,
|
start: pos,
|
||||||
end: pos + linkTo[0].length
|
end: pos + linkTo[0].length
|
||||||
},
|
},
|
||||||
children: tokenizerFac(linkTo[2], undefined, inlineRules, pos + linkTo[1].length, false),
|
children: tokenizerFac(linkTo[2], undefined, inlineRules, pos + linkTo[1].length, false, labels),
|
||||||
backlash: {
|
backlash: {
|
||||||
first: linkTo[3],
|
first: linkTo[3],
|
||||||
second: linkTo[5]
|
second: linkTo[5]
|
||||||
@ -314,9 +314,8 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rLinkTo = inlineRules['reference_link'].exec(src)
|
const rLinkTo = inlineRules['reference_link'].exec(src)
|
||||||
if (rLinkTo && isLengthEven(rLinkTo[2]) && isLengthEven(rLinkTo[4])) {
|
if (rLinkTo && labels.has(rLinkTo[3] || rLinkTo[1]) && isLengthEven(rLinkTo[2]) && isLengthEven(rLinkTo[4])) {
|
||||||
pushPending()
|
pushPending()
|
||||||
|
|
||||||
tokens.push({
|
tokens.push({
|
||||||
type: 'reference_link',
|
type: 'reference_link',
|
||||||
raw: rLinkTo[0],
|
raw: rLinkTo[0],
|
||||||
@ -332,7 +331,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
start: pos,
|
start: pos,
|
||||||
end: pos + rLinkTo[0].length
|
end: pos + rLinkTo[0].length
|
||||||
},
|
},
|
||||||
children: tokenizerFac(rLinkTo[1], undefined, inlineRules, pos + 1, false)
|
children: tokenizerFac(rLinkTo[1], undefined, inlineRules, pos + 1, false, labels)
|
||||||
})
|
})
|
||||||
|
|
||||||
src = src.substring(rLinkTo[0].length)
|
src = src.substring(rLinkTo[0].length)
|
||||||
@ -424,7 +423,7 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
parent: tokens,
|
parent: tokens,
|
||||||
attrs,
|
attrs,
|
||||||
content: htmlTo[4],
|
content: htmlTo[4],
|
||||||
children: htmlTo[4] ? tokenizerFac(htmlTo[4], undefined, inlineRules, pos + htmlTo[2].length, false) : '',
|
children: htmlTo[4] ? tokenizerFac(htmlTo[4], undefined, inlineRules, pos + htmlTo[2].length, false, labels) : '',
|
||||||
range: {
|
range: {
|
||||||
start: pos,
|
start: pos,
|
||||||
end: pos + len
|
end: pos + len
|
||||||
@ -502,8 +501,8 @@ const tokenizerFac = (src, beginRules, inlineRules, pos = 0, top) => {
|
|||||||
return tokens
|
return tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
export const tokenizer = (src, highlights = [], hasBeginRules = true) => {
|
export const tokenizer = (src, highlights = [], hasBeginRules = true, labels = new Map()) => {
|
||||||
const tokens = tokenizerFac(src, hasBeginRules ? beginRules : null, inlineRules, 0, true)
|
const tokens = tokenizerFac(src, hasBeginRules ? beginRules : null, inlineRules, 0, true, labels)
|
||||||
const postTokenizer = tokens => {
|
const postTokenizer = tokens => {
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
for (const light of highlights) {
|
for (const light of highlights) {
|
||||||
|
@ -186,6 +186,7 @@ class StateRender {
|
|||||||
patch(oldCursorVnode, newCursorVnode)
|
patch(oldCursorVnode, newCursorVnode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderMermaid()
|
this.renderMermaid()
|
||||||
this.renderDiagram()
|
this.renderDiagram()
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ export default function renderLeafBlock (block, cursor, activeBlocks, matches, u
|
|||||||
functionType !== 'languageInput'
|
functionType !== 'languageInput'
|
||||||
) {
|
) {
|
||||||
const hasBeginRules = /^(h\d|span|hr)/.test(type)
|
const hasBeginRules = /^(h\d|span|hr)/.test(type)
|
||||||
tokens = tokenizer(text, highlights, hasBeginRules)
|
tokens = tokenizer(text, highlights, hasBeginRules, this.labels)
|
||||||
if (highlights.length === 0 && useCache && DEVICE_MEMORY >= 4) {
|
if (highlights.length === 0 && useCache && DEVICE_MEMORY >= 4) {
|
||||||
this.tokenCache.set(text, tokens)
|
this.tokenCache.set(text, tokens)
|
||||||
}
|
}
|
||||||
|
@ -15,23 +15,8 @@ export default function referenceLink (h, cursor, block, token, outerClass) {
|
|||||||
label
|
label
|
||||||
} = token
|
} = token
|
||||||
const MARKER = '['
|
const MARKER = '['
|
||||||
let href = ''
|
|
||||||
let title = ''
|
|
||||||
const key = (label + backlash.second).toLowerCase()
|
const key = (label + backlash.second).toLowerCase()
|
||||||
if (this.labels.has(key)) {
|
|
||||||
({ href, title } = this.labels.get(key))
|
|
||||||
} else {
|
|
||||||
// if the link's reference definition is not defined, just show as normal text.#432
|
|
||||||
return this.highlight(h, block, start, end, token)
|
|
||||||
}
|
|
||||||
const backlashStart = start + MARKER.length + anchor.length
|
const backlashStart = start + MARKER.length + anchor.length
|
||||||
const startMarker = this.highlight(
|
|
||||||
h,
|
|
||||||
block,
|
|
||||||
start,
|
|
||||||
start + MARKER.length,
|
|
||||||
token
|
|
||||||
)
|
|
||||||
const content = [
|
const content = [
|
||||||
...children.reduce((acc, to) => {
|
...children.reduce((acc, to) => {
|
||||||
const chunk = this[snakeToCamel(to.type)](h, cursor, block, to, className)
|
const chunk = this[snakeToCamel(to.type)](h, cursor, block, to, className)
|
||||||
@ -39,6 +24,14 @@ export default function referenceLink (h, cursor, block, token, outerClass) {
|
|||||||
}, []),
|
}, []),
|
||||||
...this.backlashInToken(h, backlash.first, className, backlashStart, token)
|
...this.backlashInToken(h, backlash.first, className, backlashStart, token)
|
||||||
]
|
]
|
||||||
|
const { href, title } = this.labels.get(key)
|
||||||
|
const startMarker = this.highlight(
|
||||||
|
h,
|
||||||
|
block,
|
||||||
|
start,
|
||||||
|
start + MARKER.length,
|
||||||
|
token
|
||||||
|
)
|
||||||
const endMarker = this.highlight(
|
const endMarker = this.highlight(
|
||||||
h,
|
h,
|
||||||
block,
|
block,
|
||||||
|
@ -118,7 +118,7 @@ kbd {
|
|||||||
border: 1px solid var(--floatBorderColor);
|
border: 1px solid var(--floatBorderColor);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
transform: scale(.8);
|
font-size: .8em;
|
||||||
padding: 0px 5px;
|
padding: 0px 5px;
|
||||||
box-shadow: inset 0 -1px 0 var(--floatBorderColor);
|
box-shadow: inset 0 -1px 0 var(--floatBorderColor);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user