Fixes #845
parent
25720c63e0
commit
6d8149d747
|
@ -14,8 +14,9 @@ import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
||||||
|
|
||||||
export type ItemObject = ObjectValue<
|
export type ItemObject = ObjectValue<
|
||||||
{
|
{
|
||||||
name: string;
|
|
||||||
page: string;
|
page: string;
|
||||||
|
name: string;
|
||||||
|
text: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
} & Record<string, any>
|
} & Record<string, any>
|
||||||
>;
|
>;
|
||||||
|
@ -27,7 +28,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||||
|
|
||||||
const coll = collectNodesOfType(tree, "ListItem");
|
const coll = collectNodesOfType(tree, "ListItem");
|
||||||
|
|
||||||
for (let n of coll) {
|
for (const n of coll) {
|
||||||
if (!n.children) {
|
if (!n.children) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -40,13 +41,16 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||||
const item: ItemObject = {
|
const item: ItemObject = {
|
||||||
ref: `${name}@${n.from}`,
|
ref: `${name}@${n.from}`,
|
||||||
tag: "item",
|
tag: "item",
|
||||||
name: "", // to be replaced
|
name: "",
|
||||||
|
text: "",
|
||||||
page: name,
|
page: name,
|
||||||
pos: n.from!,
|
pos: n.from!,
|
||||||
};
|
};
|
||||||
|
|
||||||
const textNodes: ParseTree[] = [];
|
const textNodes: ParseTree[] = [];
|
||||||
|
|
||||||
|
const fullText = renderToText(n);
|
||||||
|
|
||||||
collectNodesOfType(n, "Hashtag").forEach((h) => {
|
collectNodesOfType(n, "Hashtag").forEach((h) => {
|
||||||
// Push tag to the list, removing the initial #
|
// Push tag to the list, removing the initial #
|
||||||
tags.add(h.children![0].text!.substring(1));
|
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.name = textNodes.map(renderToText).join("").trim();
|
||||||
|
item.text = fullText;
|
||||||
|
|
||||||
if (tags.size > 0) {
|
if (tags.size > 0) {
|
||||||
item.tags = [...tags];
|
item.tags = [...tags];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
||||||
/** ParagraphObject An index object for the top level text nodes */
|
/** ParagraphObject An index object for the top level text nodes */
|
||||||
export type ParagraphObject = ObjectValue<
|
export type ParagraphObject = ObjectValue<
|
||||||
{
|
{
|
||||||
text: string;
|
|
||||||
page: string;
|
page: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
|
text: string;
|
||||||
} & Record<string, any>
|
} & Record<string, any>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
@ -35,7 +35,9 @@ export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) {
|
||||||
return false;
|
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>();
|
const tags = new Set<string>();
|
||||||
collectNodesOfType(p, "Hashtag").forEach((tagNode) => {
|
collectNodesOfType(p, "Hashtag").forEach((tagNode) => {
|
||||||
tags.add(tagNode.children![0].text!.substring(1));
|
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 pos = p.from!;
|
||||||
const paragraph: ParagraphObject = {
|
const paragraph: ParagraphObject = {
|
||||||
ref: `${page}@${pos}`,
|
|
||||||
text,
|
|
||||||
tag: "paragraph",
|
tag: "paragraph",
|
||||||
|
ref: `${page}@${pos}`,
|
||||||
|
text: fullText,
|
||||||
page,
|
page,
|
||||||
pos,
|
pos,
|
||||||
...attrs,
|
...attrs,
|
||||||
|
|
|
@ -28,6 +28,7 @@ export type TaskObject = ObjectValue<
|
||||||
page: string;
|
page: string;
|
||||||
pos: number;
|
pos: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
text: string;
|
||||||
done: boolean;
|
done: boolean;
|
||||||
state: string;
|
state: string;
|
||||||
deadline?: string;
|
deadline?: string;
|
||||||
|
@ -70,6 +71,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||||
ref: `${name}@${n.from}`,
|
ref: `${name}@${n.from}`,
|
||||||
tag: "task",
|
tag: "task",
|
||||||
name: "",
|
name: "",
|
||||||
|
text: "",
|
||||||
done: complete,
|
done: complete,
|
||||||
page: name,
|
page: name,
|
||||||
pos: n.from!,
|
pos: n.from!,
|
||||||
|
@ -78,6 +80,10 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||||
|
|
||||||
rewritePageRefs(n, name);
|
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) => {
|
replaceNodesMatching(n, (tree) => {
|
||||||
if (tree.type === "DeadlineDate") {
|
if (tree.type === "DeadlineDate") {
|
||||||
task.deadline = getDeadline(tree);
|
task.deadline = getDeadline(tree);
|
||||||
|
@ -96,7 +102,6 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Extract attributes and remove from tree
|
// Extract attributes and remove from tree
|
||||||
task.name = n.children!.slice(1).map(renderToText).join("").trim();
|
|
||||||
const extractedAttributes = await extractAttributes(
|
const extractedAttributes = await extractAttributes(
|
||||||
["task", ...task.tags || []],
|
["task", ...task.tags || []],
|
||||||
n,
|
n,
|
||||||
|
|
|
@ -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))
|
* Hide `\` escapes in [[Live Preview]] (by [MrMugame](https://github.com/silverbulletmd/silverbullet/pull/901))
|
||||||
* Added Erlang [[Markdown/Syntax Highlighting]]
|
* 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)
|
* 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)
|
* Numerous other bug fixes (thanks MrMugame and onespaceman)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue