|
1 | 1 | import type { IndexTreeEvent } from "../../type/event.ts"; |
| 2 | +import { renderToText, replaceNodesMatching } from "../../plug-api/lib/tree.ts"; |
2 | 3 | import { extractHashtag } from "../../plug-api/lib/tags.ts"; |
3 | 4 | import { |
4 | 5 | collectNodesMatching, |
@@ -28,12 +29,21 @@ function cleanHeaderFieldName(str: string): string { |
28 | 29 | /** |
29 | 30 | * Concat text properties of all child nodes |
30 | 31 | * @param nodes |
31 | | - * @returns |
| 32 | + * @returns text of all child nodes |
32 | 33 | */ |
33 | 34 | function concatChildrenTexts(nodes: ParseTree[]): string { |
34 | 35 | return nodes.map((c) => c.text).join("").trim(); |
35 | 36 | } |
36 | 37 |
|
| 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 | + |
37 | 47 | export async function indexTables({ name: pageName, tree }: IndexTreeEvent) { |
38 | 48 | const result: ObjectValue<TableRowObject>[] = []; |
39 | 49 |
|
@@ -67,7 +77,12 @@ export async function indexTables({ name: pageName, tree }: IndexTreeEvent) { |
67 | 77 | pos: row.from!, |
68 | 78 | }; |
69 | 79 | 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!); |
71 | 86 | const label = headerLabels[i]; |
72 | 87 | tableRow[label!] = content; |
73 | 88 | }); |
|
0 commit comments