fix: link may not have attribute and children

This commit is contained in:
linonetwo
2025-02-19 19:55:40 +08:00
parent 87dc05be9d
commit 2765e995dd
2 changed files with 5 additions and 5 deletions
@@ -51,11 +51,11 @@ exports.parse = function() {
};
exports.serialize = function(tree,serialize) {
// Check if the link is suppressed
var isSuppressed = tree.children[0].text.substr(0,1) === "~";
// Check if the link is suppressed. Tree may only have text, no children and attributes
var isSuppressed = tree.children && tree.children[0].text.substr(0,1) === "~";
var serialized = isSuppressed ? "~" : "";
// Append the link text
serialized += tree.attributes.to.value;
serialized += tree.attributes ? tree.attributes.to.value : tree.text;
return serialized;
};
@@ -66,10 +66,10 @@ exports.parse = function() {
};
exports.serialize = function(tree,serialize) {
var isSuppressed = tree.children[0].text.substr(0,1) === $tw.config.textPrimitives.unWikiLink;
var isSuppressed = tree.children && tree.children[0].text.substr(0,1) === $tw.config.textPrimitives.unWikiLink;
var serialized = isSuppressed ? $tw.config.textPrimitives.unWikiLink : "";
serialized += tree.attributes.to.value;
serialized += tree.attributes ? tree.attributes.to.value : tree.text;
return serialized;
};