Skip to content

Commit

Permalink
fix: page alias parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sethyuan committed Dec 9, 2023
1 parent 9d8766c commit e689537
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-tocgen",
"version": "2.12.1",
"version": "2.12.2",
"main": "dist/index.html",
"logseq": {
"id": "_sethyuan-logseq-tocgen",
Expand Down
13 changes: 13 additions & 0 deletions src/libs/marked-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { marked } from "marked"

const footnoteRegex = /\[\^[^\]]*\]/g
const highlightRegex = /==([^=]*)==|\^\^([^\^]*)\^\^/g
const pageAliasRegex = /\[([^\]]*)\]\([^\)]*\)/g

function htmlDecode(str) {
if (str.length === 0) {
Expand Down Expand Up @@ -84,6 +85,18 @@ const tokenizer = {
}
return false
},
link(src) {
if (pageAliasRegex.test(src)) {
const text = src.replace(pageAliasRegex, "$1")
return {
type: "link",
raw: src,
text,
tokens: this.lexer.inlineTokens(text, []),
}
}
return false
},
}

marked.use({ renderer, tokenizer })
Expand Down

0 comments on commit e689537

Please sign in to comment.