Skip to content

Parser.parse extension to be able to change tokens as a whole #2639

@kapouer

Description

@kapouer

Describe the feature
Ability to get the "root" tokens list before rendering - either through a Parser.parse extension, or another mecanism.

Why is this feature necessary?
I need my extension to be able to prepend a default (depth 1) heading token when one is missing.

Describe alternatives you've considered

const defaultParse = Parser.parse;
Parser.parse = (tokens, options) => {
	const [{ type, depth }] = tokens;
	if (type != "heading" || depth != 1) {
		tokens.unshift({
			type: 'heading',
			depth: 1,
			tokens: []
		});
	}
	return defaultParse.call(Parser, tokens, options);
};

but i hate monkey-patching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions