pull/921/head
Zef Hemel 2024-07-06 20:52:27 +02:00
parent 25720c63e0
commit 6d8149d747
4 changed files with 22 additions and 8 deletions

View File

@ -14,8 +14,9 @@ import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
export type ItemObject = ObjectValue<
{
name: string;
page: string;
name: string;
text: string;
pos: number;
} & Record<string, any>
>;
@ -27,7 +28,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
const coll = collectNodesOfType(tree, "ListItem");
for (let n of coll) {
for (const n of coll) {
if (!n.children) {
continue;
}
@ -40,13 +41,16 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
const item: ItemObject = {
ref: `${name}@${n.from}`,
tag: "item",
name: "", // to be replaced
name: "",
text: "",
page: name,
pos: n.from!,
};
const textNodes: ParseTree[] = [];
const fullText = renderToText(n);
collectNodesOfType(n, "Hashtag").forEach((h) => {
// Push tag to the list, removing the initial #
tags.add(h.children![0].text!.substring(1));
@ -69,6 +73,8 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
}
item.name = textNodes.map(renderToText).join("").trim();
item.text = fullText;
if (tags.size > 0) {
item.tags = [...tags];
}

View File

@ -14,9 +14,9 @@ import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
/** ParagraphObject An index object for the top level text nodes */
export type ParagraphObject = ObjectValue<
{
text: string;
page: string;
pos: number;
text: string;
} & Record<string, any>
>;
@ -35,7 +35,9 @@ export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) {
return false;
}
// So we're looking at indexable a paragraph now
const fullText = renderToText(p);
// Collect tags and remove from the tree
const tags = new Set<string>();
collectNodesOfType(p, "Hashtag").forEach((tagNode) => {
tags.add(tagNode.children![0].text!.substring(1));
@ -54,9 +56,9 @@ export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) {
const pos = p.from!;
const paragraph: ParagraphObject = {
ref: `${page}@${pos}`,
text,
tag: "paragraph",
ref: `${page}@${pos}`,
text: fullText,
page,
pos,
...attrs,

View File

@ -28,6 +28,7 @@ export type TaskObject = ObjectValue<
page: string;
pos: number;
name: string;
text: string;
done: boolean;
state: string;
deadline?: string;
@ -70,6 +71,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
ref: `${name}@${n.from}`,
tag: "task",
name: "",
text: "",
done: complete,
page: name,
pos: n.from!,
@ -78,6 +80,10 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
rewritePageRefs(n, name);
// The task text is everything after the task marker
task.text = n.children!.slice(1).map(renderToText).join("").trim();
// This finds the deadline and tags, and removes them from the tree
replaceNodesMatching(n, (tree) => {
if (tree.type === "DeadlineDate") {
task.deadline = getDeadline(tree);
@ -96,7 +102,6 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
});
// Extract attributes and remove from tree
task.name = n.children!.slice(1).map(renderToText).join("").trim();
const extractedAttributes = await extractAttributes(
["task", ...task.tags || []],
n,

View File

@ -16,6 +16,7 @@ _These features are not yet properly released, you need to use [the edge builds]
* Hide `\` escapes in [[Live Preview]] (by [MrMugame](https://github.com/silverbulletmd/silverbullet/pull/901))
* Added Erlang [[Markdown/Syntax Highlighting]]
* Dates (formatted as e.g. `2023-07-01` or `2023-07-01 23:33`) in [[Frontmatter]] are now converted into strings (rather than empty objects)
* `task` and `item` objects now have an additional `text` attribute that contains the full text of the item and/or task, with any [[Attributes]] and [[Tags]] intact (whereas they are removed from `name`)
* Numerous other bug fixes (thanks MrMugame and onespaceman)
---