mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-05 21:33:52 +00:00
fix: empty list item
This commit is contained in:
parent
8056d8c11e
commit
0f385675c2
@ -66,6 +66,12 @@ var listTypes = {
|
|||||||
var listTags = Object.values(listTypes).map(function(type) {
|
var listTags = Object.values(listTypes).map(function(type) {
|
||||||
return type.listTag;
|
return type.listTag;
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
Check if the child is a nested list or a simple line of list item
|
||||||
|
*/
|
||||||
|
function isListNode(node) {
|
||||||
|
return node && node.type === "element" && listTags.includes(node.tag);
|
||||||
|
}
|
||||||
var itemTags = Object.values(listTypes).map(function(type) {
|
var itemTags = Object.values(listTypes).map(function(type) {
|
||||||
return type.itemTag;
|
return type.itemTag;
|
||||||
});
|
});
|
||||||
@ -174,7 +180,7 @@ exports.serialize = function (tree,serialize) {
|
|||||||
// Recursive function to serialize list nodes, handling nested lists and formatting output
|
// Recursive function to serialize list nodes, handling nested lists and formatting output
|
||||||
function serializeList(node, markerPrefix) {
|
function serializeList(node, markerPrefix) {
|
||||||
var result = [];
|
var result = [];
|
||||||
if(node.type === "element" && listTags.includes(node.tag)) {
|
if(node.type === "element" && isListNode(node)) {
|
||||||
node.children.forEach(function (child) {
|
node.children.forEach(function (child) {
|
||||||
if(itemTags.includes(child.tag)) {
|
if(itemTags.includes(child.tag)) {
|
||||||
var currentMarker = findMarker(node.tag, child.tag);
|
var currentMarker = findMarker(node.tag, child.tag);
|
||||||
@ -183,8 +189,7 @@ exports.serialize = function (tree,serialize) {
|
|||||||
// same level text nodes may be split into multiple children, and separated by deeper list sub-tree. We collect same level text nodes into this list, and concat then submit them before enter deeper list.
|
// same level text nodes may be split into multiple children, and separated by deeper list sub-tree. We collect same level text nodes into this list, and concat then submit them before enter deeper list.
|
||||||
var content = [];
|
var content = [];
|
||||||
$tw.utils.each(child.children,function (subNode) {
|
$tw.utils.each(child.children,function (subNode) {
|
||||||
// Check if the child is a nested list or a simple line of list item
|
if(isListNode(subNode)) {
|
||||||
if(listTags.includes(subNode.tag)) {
|
|
||||||
// Recursive call for nested lists
|
// Recursive call for nested lists
|
||||||
if(content.length > 0) {
|
if(content.length > 0) {
|
||||||
result.push(markerPrefix + currentMarker + classAttr + " " + content.join("").trim());
|
result.push(markerPrefix + currentMarker + classAttr + " " + content.join("").trim());
|
||||||
@ -196,7 +201,8 @@ exports.serialize = function (tree,serialize) {
|
|||||||
}
|
}
|
||||||
return ""; // Default return for unhandled node types
|
return ""; // Default return for unhandled node types
|
||||||
});
|
});
|
||||||
if(content.length > 0) {
|
// prepend `#` mark to a new line, if it has content (and has or hasn't nested list), or if it has no content and also no nested list
|
||||||
|
if(content.length > 0 || child.children.length === 0) {
|
||||||
result.push(markerPrefix + currentMarker + classAttr + " " + content.join("").trim());
|
result.push(markerPrefix + currentMarker + classAttr + " " + content.join("").trim());
|
||||||
content = []
|
content = []
|
||||||
}
|
}
|
||||||
|
@ -25,3 +25,16 @@ type: text/vnd.tiddlywiki
|
|||||||
* List item one
|
* List item one
|
||||||
*.active List item two has the class `active`
|
*.active List item two has the class `active`
|
||||||
* List item three
|
* List item three
|
||||||
|
|
||||||
|
# AAA
|
||||||
|
## [[BBB]]
|
||||||
|
### CCC
|
||||||
|
# AAA
|
||||||
|
## CCC
|
||||||
|
## DDD
|
||||||
|
## EEE
|
||||||
|
# BBB
|
||||||
|
## FF `/` FFF
|
||||||
|
## FFF
|
||||||
|
## GGG
|
||||||
|
##
|
||||||
|
Loading…
x
Reference in New Issue
Block a user