Skip to content

Commit

Permalink
fix(view:codeblock:markmap): Use ListIndex builder instead of headings
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed May 5, 2024
1 parent 63eb4ee commit ebd1756
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
7 changes: 4 additions & 3 deletions src/components/codeblocks/CodeblockMarkmap.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type { ICodeblock } from "src/codeblocks/schema";
import { ListIndex } from "src/commands/list_index";
import { Traverse, type EdgeTree } from "src/graph/traverse";
import {
get_edge_sorter,
Expand All @@ -9,7 +10,6 @@
import type { BreadcrumbsError } from "src/interfaces/graph";
import type BreadcrumbsPlugin from "src/main";
import { active_file_store } from "src/stores/active_file";
import { Markmap } from "src/utils/markmap";
import { onMount } from "svelte";
import MarkmapDiagram from "../Markmap/MarkmapDiagram.svelte";
import CopyToClipboardButton from "../button/CopyToClipboardButton.svelte";
Expand Down Expand Up @@ -79,9 +79,10 @@
}
};
$: markmap = Markmap.from_tree(tree, {
$: markmap = ListIndex.edge_tree_to_list_index(tree, {
...plugin.settings.commands.list_index.default_options,
show_node_options,
show_attributes: options?.["show-attributes"],
show_attributes: options["show-attributes"] ?? [],
});
onMount(update);
Expand Down
43 changes: 1 addition & 42 deletions src/utils/markmap.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1 @@
import type { EdgeAttribute } from "src/graph/MyMultiGraph";
import type { EdgeTree } from "src/graph/traverse";
import type { ShowNodeOptions } from "src/interfaces/settings";
import { Links } from "./links";
import { untyped_pick } from "./objects";
import { Paths } from "./paths";
import { url_search_params } from "./url";

type Options = {
show_attributes?: EdgeAttribute[];
show_node_options?: ShowNodeOptions;
};

const from_tree = (tree: EdgeTree[], options?: Options) => {
let markmap = "";

tree.forEach((item) => {
const hashes = "#".repeat(item.depth + 1);

const link = Links.ify(
item.edge.target_id,
Paths.show(item.edge.target_id, options?.show_node_options),
{ link_kind: "wiki" },
);

const attr = options?.show_attributes
? ` (${url_search_params(untyped_pick(item.edge.attr, options.show_attributes), { trim_lone_param: true })})`
: "";

markmap += `${hashes} ${link}${attr}\n\n`;

if (item.children.length) {
markmap += from_tree(item.children, options);
}
});

return markmap;
};

export const Markmap = {
from_tree,
};
export const Markmap = {};

0 comments on commit ebd1756

Please sign in to comment.