Skip to content

Commit

Permalink
fix: rehype2remark list item inline bug
Browse files Browse the repository at this point in the history
fix: #1207
  • Loading branch information
windingwind committed Nov 30, 2024
1 parent cd7edb0 commit d17d5dc
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,24 +417,34 @@ async function rehype2remark(rehype: HRoot) {
* ```
*/
li: (h, node) => {
const mnode = defaultHandlers.li(h, node) as ListContent;
const mNode = defaultHandlers.li(h, node) as ListContent;
// If no more than 1 children, skip
if (!mnode || mnode.children.length < 2) {
return mnode;
if (!mNode || mNode.children.length < 2) {
return mNode;
}
const children: any[] = [];
// Merge none-list nodes inside li into the previous paragraph node to avoid line break
while (mnode.children.length > 0) {
const current = mnode.children.shift();
while (mNode.children.length > 0) {
const current = mNode.children.shift();
const cached = children[children.length - 1];
if (cached?.type === "paragraph" && current?.type !== "list") {
cached.children.push(current);
if (current?.type !== "list") {
if (cached?.type === "paragraph") {
cached.children.push(current);
} else {
// https://github.com/windingwind/zotero-better-notes/issues/1207
// Create a new paragraph node
const paragraph = {
type: "paragraph",
children: [current],
};
children.push(paragraph);
}
} else {
children.push(current);
}
}
mnode.children.push(...children);
return mnode;
mNode.children.push(...children);
return mNode;
},
wrapper: (h, node) => {
return h(node, "wrapper", toText(node));
Expand Down Expand Up @@ -803,12 +813,12 @@ function processN2MRehypeHighlightNodes(
const libraryType = uriParts[3];
const key = uriParts[uriParts.length - 1];
if (libraryType === "users") {
openURI = "zotero://open-pdf/library/items/" + key;
openURI = "zotero://open/library/items/" + key;
}
// groups
else {
const groupID = uriParts[4];
openURI = "zotero://open-pdf/groups/" + groupID + "/items/" + key;
openURI = "zotero://open/groups/" + groupID + "/items/" + key;
}

openURI +=
Expand Down

0 comments on commit d17d5dc

Please sign in to comment.