|
|
|
|
@ -12,7 +12,7 @@ import type {
@@ -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 {
@@ -66,6 +66,8 @@ export default class Pharos {
|
|
|
|
|
|
|
|
|
|
private asciidoctor: Asciidoctor; |
|
|
|
|
|
|
|
|
|
private pharosExtensions: Extensions.Registry; |
|
|
|
|
|
|
|
|
|
private ndk: NDK; |
|
|
|
|
|
|
|
|
|
private contextCounters: Map<string, number> = new Map<string, number>(); |
|
|
|
|
@ -130,25 +132,26 @@ export default class Pharos {
@@ -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 () { |
|
|
|
|
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.'); |
|
|
|
|
|