Skip to content

Allow directive source extraction without defining a docutils directive #1232

Open

Description

@adamtheturtle

Source-analysis tools need to split MyST directive options from the body and use body_offset, without rendering a directive or validating against an installed extension.

Currently parse_directive_text() requires type[Directive]. Accepting arbitrary string options therefore requires a placeholder directive subclass and custom truthy option_spec mapping, even though no directive instance is ever needed. The placeholder also inherits docutils' abstract run() contract. Separately, DirectiveParsingResult.options is annotated as a bare dict, exposing unknown key/value types to strict downstream checkers.

Proposed fix: allow directive_class=None to parse arbitrary options as strings using the normal option tokenizer and offset handling. Preserve syntax warnings, colon/YAML option blocks, empty flags and additional_options precedence. Existing calls with a directive class should retain their current behavior, including option conversion. Make the result generic so schema-free parsing exposes dict[str, str] to type checkers while directive converters and full-YAML mode can still return arbitrary values.

This removes the placeholder classes and lint/type suppressions from the proposed downstream integration in adamtheturtle/sybil-extras#1369 and adamtheturtle/sybil-extras#1370.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions