Skip to content

Commit f5aef74

Browse files
authored
support links in table queryable objects (#1523)
1 parent 045d6d0 commit f5aef74

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

plugs/index/table.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { IndexTreeEvent } from "../../type/event.ts";
2+
import { renderToText, replaceNodesMatching } from "../../plug-api/lib/tree.ts";
23
import { extractHashtag } from "../../plug-api/lib/tags.ts";
34
import {
45
collectNodesMatching,
@@ -28,12 +29,21 @@ function cleanHeaderFieldName(str: string): string {
2829
/**
2930
* Concat text properties of all child nodes
3031
* @param nodes
31-
* @returns
32+
* @returns text of all child nodes
3233
*/
3334
function concatChildrenTexts(nodes: ParseTree[]): string {
3435
return nodes.map((c) => c.text).join("").trim();
3536
}
3637

38+
/**
39+
* Concat text properties of all child nodes, preserving links
40+
* @param nodes
41+
* @returns text, preserving links, of all child nodes
42+
*/
43+
function concatChildrenTextsPreserveLinks(nodes: ParseTree[]): string {
44+
return nodes.map((c) => renderToText(c)).join("").trim();
45+
}
46+
3747
export async function indexTables({ name: pageName, tree }: IndexTreeEvent) {
3848
const result: ObjectValue<TableRowObject>[] = [];
3949

@@ -67,7 +77,12 @@ export async function indexTables({ name: pageName, tree }: IndexTreeEvent) {
6777
pos: row.from!,
6878
};
6979
cells.forEach((c, i) => {
70-
const content = concatChildrenTexts(c.children!);
80+
replaceNodesMatching(c, (tree) => {
81+
if (tree.type === "Hashtag") {
82+
return null;
83+
}
84+
});
85+
const content = concatChildrenTextsPreserveLinks(c.children!);
7186
const label = headerLabels[i];
7287
tableRow[label!] = content;
7388
});

0 commit comments

Comments
 (0)