Fix: addParentPointers re-attaches parents even if a sub-tree already
has some + some cleanup Properly addresses #1776
This commit is contained in:
@@ -43,10 +43,15 @@ function cleanTags(values: (Tag | null)[], cleanWhitespace = false): Tag[] {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up a markdown tree. Side effect: adds parent pointers
|
||||
*/
|
||||
function preprocess(t: ParseTree) {
|
||||
addParentPointers(t);
|
||||
traverseTree(t, (node) => {
|
||||
// If this node i
|
||||
if (!node.type) {
|
||||
// Remove redundant newlines in table
|
||||
if (node.text?.startsWith("\n")) {
|
||||
const prevNodeIdx = node.parent!.children!.indexOf(node) - 1;
|
||||
const prevNodeType = node.parent!.children![prevNodeIdx]?.type;
|
||||
|
||||
@@ -15,10 +15,6 @@ export function addParentPointers(tree: ParseTree) {
|
||||
return;
|
||||
}
|
||||
for (const child of tree.children) {
|
||||
if (child.parent) {
|
||||
// Already added parent pointers before
|
||||
return;
|
||||
}
|
||||
child.parent = tree;
|
||||
addParentPointers(child);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ export async function renamePageLinkCommand() {
|
||||
console.error("No link found at cursor position...");
|
||||
return;
|
||||
}
|
||||
console.log("Link node", mdTree);
|
||||
addParentPointers(mdTree);
|
||||
let node: ParseTree | null = link;
|
||||
if (node.type !== "WikiLink") {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { FrontMatter } from "./frontmatter.ts";
|
||||
import { queryLuaObjects } from "./api.ts";
|
||||
import {
|
||||
addParentPointers,
|
||||
collectNodesOfType,
|
||||
findParentMatching,
|
||||
type ParseTree,
|
||||
@@ -31,7 +30,6 @@ export function indexTags(
|
||||
tree: ParseTree,
|
||||
) {
|
||||
const tags = new Set<string>(); // name:parent
|
||||
addParentPointers(tree);
|
||||
const pageTags: string[] = frontmatter.tags || [];
|
||||
for (const pageTag of pageTags) {
|
||||
tags.add(`${pageTag}:page`);
|
||||
|
||||
Reference in New Issue
Block a user