Skip to content

Allow a custom auto-close function in the Markdown parser #391

Description

@jinghaihan

Description

Allow ParserOptions.autoClose to accept a synchronous function. It should receive the unstable Markdown tail after incremental reuse and run before plugin preprocessing and tokenization.

Motivation

While optimizing vue-stream-markdown, I found Comark's compact document model and incremental parser architecture excellent. Our benchmarks show several-fold parsing performance improvements over the current mdast-based implementation, so I would like to adopt Comark as the parser while retaining custom completion rules for more controlled handling of incomplete Markdown.

Proposed solution

Allow autoClose to accept a boolean or a synchronous function:

autoClose?: boolean | ((markdown: string, options: AutoCloseOptions) => string)

true would keep the current behavior, false would disable auto-close, and a function would replace the built-in implementation at the same stage.

Alternatives considered

Preprocessing before parsing handles the full source and may disrupt incremental reuse. A pre plugin can work, but it is a general transform hook whose execution order may not match the built-in auto-close stage.

Additional context

PR #385 makes a pre plugin less reliable as an auto-close replacement because default hooks run first. A function would provide a stable extension point, and I would be happy to submit a PR if this approach is accepted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions