diff --git a/src/lib/parser.ts b/src/lib/parser.ts index b9f9545..0454a10 100644 --- a/src/lib/parser.ts +++ b/src/lib/parser.ts @@ -12,7 +12,7 @@ import type { } from 'asciidoctor'; import he from 'he'; import { writable, type Writable } from 'svelte/store'; -import { zettelKinds } from './consts'; +import { zettelKinds } from './consts.ts'; interface IndexMetadata { authors?: string[]; @@ -66,6 +66,8 @@ export default class Pharos { private asciidoctor: Asciidoctor; + private pharosExtensions: Extensions.Registry; + private ndk: NDK; private contextCounters: Map = new Map(); @@ -130,25 +132,26 @@ export default class Pharos { constructor(ndk: NDK) { this.asciidoctor = asciidoctor(); + this.pharosExtensions = this.asciidoctor.Extensions.create(); this.ndk = ndk; const pharos = this; - this.asciidoctor.Extensions.register(function () { - const registry = this; - registry.treeProcessor(function () { - const dsl = this; - dsl.process(function (document) { - const treeProcessor = this; - pharos.treeProcessor(treeProcessor, document); - }); - }) + this.pharosExtensions.treeProcessor(function () { + const dsl = this; + dsl.process(function (document) { + const treeProcessor = this; + pharos.treeProcessor(treeProcessor, document); + }); }); } parse(content: string, options?: ProcessorOptions | undefined): void { try { - this.html = this.asciidoctor.convert(content, options) as string | Document | undefined; + this.html = this.asciidoctor.convert(content, { + 'extension_registry': this.pharosExtensions, + ...options, + }) as string | Document | undefined; } catch (error) { console.error(error); throw new Error('Failed to parse AsciiDoc document.');