mirror of
https://github.com/glassflame/glassflame.github.io.git
synced 2024-11-22 08:04:27 +00:00
Fix lheading behaving strangely
This commit is contained in:
parent
2073029d99
commit
bcd51d2eb5
1 changed files with 39 additions and 22 deletions
|
@ -10,11 +10,27 @@ export class MarkdownElement extends CustomElement {
|
||||||
return document.getElementById("template-markdown")
|
return document.getElementById("template-markdown")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// noinspection JSUnusedGlobalSymbols
|
||||||
/**
|
/**
|
||||||
* {@link Marked} Markdown renderer.
|
* {@link Marked} Markdown renderer.
|
||||||
* @type {Marked}
|
* @type {Marked}
|
||||||
*/
|
*/
|
||||||
static MARKED = new Marked({
|
static MARKED = new Marked({
|
||||||
|
tokenizer: {
|
||||||
|
// Fix single, double, and triple equals on a single line being interpreted as headings
|
||||||
|
lheading(src) {
|
||||||
|
const cap = /^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(={4,}|-{4,}) *(?:\n+|$)/.exec(src);
|
||||||
|
if (cap) {
|
||||||
|
return {
|
||||||
|
type: 'heading',
|
||||||
|
raw: cap[0],
|
||||||
|
depth: cap[2].charAt(0) === '=' ? 1 : 2,
|
||||||
|
text: cap[1],
|
||||||
|
tokens: this.lexer.inline(cap[1])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
extensions: [
|
extensions: [
|
||||||
{
|
{
|
||||||
name: "frontmatter",
|
name: "frontmatter",
|
||||||
|
@ -38,6 +54,27 @@ export class MarkdownElement extends CustomElement {
|
||||||
return `<x-frontmatter lang="${token.lang}" data="${token.data.replaceAll('"', '"')}"></x-frontmatter>`;
|
return `<x-frontmatter lang="${token.lang}" data="${token.data.replaceAll('"', '"')}"></x-frontmatter>`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "mathBlock",
|
||||||
|
level: "block",
|
||||||
|
start(src) {
|
||||||
|
const match = src.match(/[$][$]/)
|
||||||
|
return match?.index
|
||||||
|
},
|
||||||
|
tokenizer(src, _) {
|
||||||
|
const match = src.match(/^[$][$](.*?)[$][$]/s)
|
||||||
|
if(match) {
|
||||||
|
return {
|
||||||
|
type: "mathBlock",
|
||||||
|
raw: match[0],
|
||||||
|
document: match[1],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
renderer(token) {
|
||||||
|
return `<x-math document="${token.document}" block></x-math>`
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "wikilink",
|
name: "wikilink",
|
||||||
level: "inline",
|
level: "inline",
|
||||||
|
@ -45,7 +82,7 @@ export class MarkdownElement extends CustomElement {
|
||||||
return src.match(/\[\[/)?.index
|
return src.match(/\[\[/)?.index
|
||||||
},
|
},
|
||||||
tokenizer(src, _) {
|
tokenizer(src, _) {
|
||||||
const match = src.match(/^\[\[([^|\]]+)(?:\|([^\]]+))?]]/)
|
const match = src.match(/^\[\[([^|\]]*)(?:\|([^\]]*))?]]/)
|
||||||
if(match) {
|
if(match) {
|
||||||
return {
|
return {
|
||||||
type: "wikilink",
|
type: "wikilink",
|
||||||
|
@ -79,26 +116,6 @@ export class MarkdownElement extends CustomElement {
|
||||||
return `<x-hashtag tag="${token.tag}"></x-hashtag>`
|
return `<x-hashtag tag="${token.tag}"></x-hashtag>`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "mathBlock",
|
|
||||||
level: "block",
|
|
||||||
start(src) {
|
|
||||||
return src.match(/[$][$]/)?.index
|
|
||||||
},
|
|
||||||
tokenizer(src, _) {
|
|
||||||
const match = src.match(/^[$][$](.+?)[$][$]/s)
|
|
||||||
if(match) {
|
|
||||||
return {
|
|
||||||
type: "mathBlock",
|
|
||||||
raw: match[0],
|
|
||||||
document: match[1],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
renderer(token) {
|
|
||||||
return `<x-math document="${token.document}" block></x-math>`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "mathInline",
|
name: "mathInline",
|
||||||
level: "inline",
|
level: "inline",
|
||||||
|
@ -126,7 +143,7 @@ export class MarkdownElement extends CustomElement {
|
||||||
return src.match(/==/)?.index
|
return src.match(/==/)?.index
|
||||||
},
|
},
|
||||||
tokenizer(src, _) {
|
tokenizer(src, _) {
|
||||||
const match = src.match(/^==(.+?)==/)
|
const match = src.match(/^==(.*?)==/)
|
||||||
if(match) {
|
if(match) {
|
||||||
return {
|
return {
|
||||||
type: "highlight",
|
type: "highlight",
|
||||||
|
|
Loading…
Reference in a new issue