Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Inconsistent precedence in Markdown parser #42

Description

@danieldongit

There seems to be a conflict between my custom inline parser and image tags.
This is my code:

const copyOpen = '[copy]';
const copyClose = '[/copy]';
export const CopyExtension: MarkdownConfig = {
    defineNodes: [NodeTypes.copy, NodeTypes.copyTag],
    parseInline: [{
        name: NodeTypes.copy,
        parse(cx: InlineContext, next: number, pos: number) {
            const isOpenTag = cx.slice(pos, pos + copyOpen.length) === copyOpen;
            const isCloseTag = cx.slice(pos, pos + copyClose.length) === copyClose;

            if (isOpenTag) {
                return cx.addDelimiter(CopyDelim, pos, pos + copyOpen.length, true, false);
            } else if (isCloseTag) {
                return cx.addDelimiter(CopyDelim, pos, pos + copyClose.length, false, true);
            }
            return -1;
        },
        after: NodeTypes.italic,
    }],
    props: [
        styleTags({
            [NodeTypes.copyTag]: tags.special(CustomTags.CopyTag),
            [NodeTypes.copy]: tags.special(CustomTags.Copy),
        }),
    ],
};

This issue is that my copy tag gets mistaken for on image when placing a ! character before the closing tag.

Since it is parsed after Italic it should be parsed before images. If I set it to be before image it gets interpreted as a link.
I don't see what else can be done on my end to fix this.

Here are some screenshots of the behaviour:
image
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions