-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const {marked} = require("marked"); | ||
const {loadComponent} = require("../../component-loader"); | ||
|
||
// [链接文本](链接URL) // 基本语法 | ||
// [链接文本](链接URL "链接标题") // 带标题 | ||
// [链接文本](链接URL "链接标题" "_blank") // 指定打开方式 | ||
const PageForgeLinkExtension = { | ||
name: 'pageforgeLink', | ||
level: 'inline', | ||
start(src) { | ||
return src.match(/^\[/)?.index; | ||
}, | ||
tokenizer(src, tokens) { | ||
const rule = /^\[(.*?)\]\((.*?)(?:\s+"(.*?)")?(?:\s+"(.*?)")?\)/; | ||
const match = rule.exec(src); | ||
if (match) { | ||
return { | ||
type: 'pageforgeLink', | ||
raw: match[0], | ||
text: match[1], | ||
href: match[2], | ||
title: match[3] || null, | ||
target: match[4] || null, | ||
tokens: [] | ||
}; | ||
} | ||
return false; | ||
}, | ||
renderer(item) { | ||
return loadComponent('a', { | ||
...item | ||
}); | ||
} | ||
}; | ||
|
||
marked.use({ | ||
extensions: [ | ||
PageForgeLinkExtension | ||
] | ||
}); | ||
|
||
module.exports = PageForgeLinkExtension; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
module.exports = function template(value) { | ||
const item = value.linkItem; | ||
const matches = item.raw.match(/\[(.*?)\]\((.*?)(?:\s+"(.*?)")?\s*(?:"(.*?)")?\)/); | ||
const target = matches?.[4]; | ||
|
||
module.exports = function template(item) { | ||
return ` | ||
<a class="text-blue-600 hover:text-blue-800 hover:underline transition-colors duration-200 cursor-pointer" | ||
href="${target ? matches[2] : item.href}" | ||
target="${target || '_self'}" | ||
title="${target ? matches[3] : item.title || ''}"> | ||
${target ? matches[1] : item.text} | ||
href="${item.href}" | ||
target="${item.target || '_self'}" | ||
title="item.title || ''}"> | ||
${item.text} | ||
</a> | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters