From bdef04422954a480a1f28f55e6c87377905ddce1 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Sat, 21 Sep 2024 00:15:45 -0500 Subject: [PATCH] Add getters to Pharos public API --- src/lib/parser.ts | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/lib/parser.ts b/src/lib/parser.ts index 7b1d9bc..bcabac0 100644 --- a/src/lib/parser.ts +++ b/src/lib/parser.ts @@ -67,6 +67,9 @@ export default class Pharos extends Asciidoctor { */ private rootIndexId?: string; + /** + * Metadata to be used to populate the tags on the root index event. + */ private rootIndexMetadata: IndexMetadata = {}; /** @@ -89,6 +92,8 @@ export default class Pharos extends Asciidoctor { */ private eventIds: Map = new Map(); + // #region Public API + constructor(ndk: NDK) { super(); @@ -116,10 +121,56 @@ export default class Pharos extends Asciidoctor { return this.generateEvents(stack, pubkey); } + /** + * Gets the entire HTML content of the AsciiDoc document. + * @returns The HTML content of the converted document. + */ getHtml(): string { return this.html?.toString() || ''; } + /** + * @returns The ID of the root index of the converted document. + * @remarks The root index ID may be used to retrieve metadata or children from the root index. + */ + getRootIndexId(): string { + return this.rootIndexId!; + } + + /** + * @returns The title, if available, from the metadata of the index with the given ID. + */ + getIndexTitle(id: string): string | undefined { + const section = this.nodes.get(id) as Section; + return section.getTitle(); + } + + /** + * @returns The IDs of any child indices of the index with the given ID. + */ + getChildIndexIds(id: string): string[] { + return Array.from(this.indexToChildEventsMap.get(id)!) + .filter(id => this.eventToKindMap.get(id) === 30040); + } + + /** + * @returns The IDs of any child zettels of the index with the given ID. + */ + getChildZettelIds(id: string): string[] { + return Array.from(this.indexToChildEventsMap.get(id)!) + .filter(id => this.eventToKindMap.get(id) !== 30040); + } + + /** + * @returns The converted content of the zettel with the given ID. + */ + getZettelHtml(id: string): string { + const block = this.nodes.get(id) as Block; + return block.convert(); + } + + // #endregion + // #region Tree Processor Extensions /** @@ -402,5 +453,7 @@ export default class Pharos extends Asciidoctor { return wikilinks; } + // TODO: Add search-based wikilink resolution. + // #endregion } \ No newline at end of file