mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-09 08:50:26 +00:00
fix: correct anchor start end
This commit is contained in:
parent
7e9cadf6b0
commit
92ca17a08b
@ -18,8 +18,8 @@ Instantiate parse rule
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match the anchor.
|
||||
// 1. located on the end of the line, with a space before it, means it's the id of the current block.
|
||||
// 2. located at start of the line, no space, means it's the id of the previous block. Because some block can't have id suffix, otherwise id break the block mode parser like codeblock.
|
||||
// 1. inlineId: located on the end of the line, with a space before it, means it's the id of the current block.
|
||||
// 2. blockId: located at start of the line, no space, means it's the id of the previous block. Because some block can't have id suffix, otherwise id break the block mode parser like codeblock.
|
||||
this.matchRegExp = /[ ]\^(\S+)$|^\^(\S+)$/mg;
|
||||
};
|
||||
|
||||
@ -30,16 +30,19 @@ exports.parse = function() {
|
||||
// Move past the match
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// will be one of following case, another will be undefined
|
||||
var anchorId = this.match[1];
|
||||
var anchorBeforeId = this.match[2];
|
||||
var inlineId = this.match[1];
|
||||
var blockId = this.match[2];
|
||||
var id = inlineId || blockId || '';
|
||||
var anchorStart = this.parser.pos;
|
||||
var anchorEnd = anchorStart + id.length;
|
||||
// Parse tree nodes to return
|
||||
return [{
|
||||
type: "anchor",
|
||||
attributes: {
|
||||
id: {type: "string", value: anchorId || anchorBeforeId},
|
||||
id: {type: "string", value: id, start: anchorStart, end: anchorEnd},
|
||||
// `yes` means the block that this anchor pointing to, is before this node, both anchor and the block, is in a same parent node's children list.
|
||||
// empty means the block is this node's direct parent node.
|
||||
previousSibling: {type: "string", value: Boolean(anchorBeforeId) ? "yes" : ""},
|
||||
previousSibling: {type: "string", value: Boolean(blockId) ? "yes" : ""},
|
||||
},
|
||||
children: []
|
||||
}];
|
||||
|
@ -42,7 +42,7 @@ exports.parse = function() {
|
||||
var linkStart = this.match[2] ? (start + this.match[1].length + 1) : start;
|
||||
var linkEnd = linkStart + link.length;
|
||||
if($tw.utils.isLinkExternal(link)) {
|
||||
// add back the part after `^` to the ext link, if it happen to has one.
|
||||
// add back the part after `^` to the ext link, if it happen to has one. Here is is not an anchor, but a part of the external URL.
|
||||
if(anchor) {
|
||||
link = link + "^" + anchor;
|
||||
}
|
||||
@ -60,11 +60,13 @@ exports.parse = function() {
|
||||
}]
|
||||
}];
|
||||
} else {
|
||||
var anchorStart = anchor ? (linkEnd + 1) : linkEnd;
|
||||
var anchorEnd = anchorStart + anchor.length;
|
||||
return [{
|
||||
type: "link",
|
||||
attributes: {
|
||||
to: {type: "string", value: link, start: linkStart, end: linkEnd},
|
||||
toAnchor: {type: "string", value: anchor},
|
||||
toAnchor: {type: "string", value: anchor, start: anchorStart, end: anchorEnd},
|
||||
},
|
||||
children: [{
|
||||
type: "text", text: text, start: start, end: textEndPos
|
||||
|
Loading…
Reference in New Issue
Block a user