1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-08 23:03:50 +00:00

feat: allow wiki pretty link to have id

This commit is contained in:
linonetwo 2023-09-16 02:49:58 +08:00
parent 18236b547f
commit d5e9d2a71b

View File

@ -23,8 +23,8 @@ exports.types = {inline: true};
exports.init = function(parser) { exports.init = function(parser) {
this.parser = parser; this.parser = parser;
// Regexp to match // Regexp to match `[[Title^blockId|Alias]]`, the `^blockId` and `|Alias` are optional.
this.matchRegExp = /\[\[(.*?)(?:\|(.*?))?\]\]/mg; this.matchRegExp = /\[\[(.*?)(?:\^([^|\s^]+))?(?:\|(.*?))?\]\]/mg;
}; };
exports.parse = function() { exports.parse = function() {
@ -32,8 +32,13 @@ exports.parse = function() {
this.parser.pos = this.matchRegExp.lastIndex; this.parser.pos = this.matchRegExp.lastIndex;
// Process the link // Process the link
var text = this.match[1], var text = this.match[1],
link = this.match[2] || text; blockId = this.match[2] || "",
link = this.match[3] || text;
if($tw.utils.isLinkExternal(link)) { if($tw.utils.isLinkExternal(link)) {
// add back the part after `^` to the ext link, if it happen to has one.
if(blockId) {
link = link + "^" + blockId;
}
return [{ return [{
type: "element", type: "element",
tag: "a", tag: "a",
@ -51,7 +56,8 @@ exports.parse = function() {
return [{ return [{
type: "link", type: "link",
attributes: { attributes: {
to: {type: "string", value: link} to: {type: "string", value: link},
id: {type: "string", value: blockId},
}, },
children: [{ children: [{
type: "text", text: text type: "text", text: text