import { parser as htmlParser } from "@lezer/html"
import { parser as commonMarkParser } from "@lezer/markdown"
import { parse, postprocess, preprocess } from "micromark"
import { frontmatter } from "micromark-extension-frontmatter"
import { gfmTable } from "micromark-extension-gfm-table"
import { normalizeIdentifier } from "micromark-util-normalize-identifier"
import { markdownSyntaxExtension } from "./markdown-syntax.ts"
interface MarkdownAnalysis {
readonly lines: string[]
readonly structuralLines: string[]
readonly dictionaryLines: string[]
readonly wordingLines: string[]
readonly wordingStructuralLines: string[]
readonly wordingDictionaryLines: string[]
readonly structuralBlanks: boolean[]
readonly wordingStructuralBlanks: boolean[]
readonly sentenceBoundaryLines: boolean[]
readonly blocks: BlockStructure
}
// Per line: the id of the leaf block that owns it, or -1 when no block does, and
// the column where the block content starts after any quote or list prefix.
export interface BlockStructure {
readonly ids: readonly number[]
readonly contentStarts: readonly number[]
}
interface AnalysisState {
readonly source: string
readonly parseLines: readonly string[]
readonly sourceLineStarts: readonly number[]
readonly lineAtOffset: Int32Array
readonly proseMask: Uint8Array
readonly structuralMask: Uint8Array
readonly dictionaryMask: Uint8Array
readonly containerMask: Uint8Array
readonly blockQuoteMask: Uint8Array | undefined
readonly blockQuoteLines: Uint8Array | undefined
readonly structuralBlanks: boolean[]
readonly sentenceBoundaryLines: boolean[]
readonly blockIds: number[]
readonly blockContentStarts: number[]
}
interface SourceRange {
readonly start: number
readonly end: number
}
const parserInput = (source: string): { readonly source: string; readonly offset: number } => ({
source,
offset: source.charCodeAt(0) === 0xfeff ? 1 : 0,
})
const translateParserOffsets = >(
events: Events,
offset: number,
): Events => {
if (offset === 0) return events
const points = new Set