Is there a way to impose node on other nodes?

I use markdown() extension for code mirror.

I use syntaxTree().iterate() to iterate over nodes, and I find Paragraph, HTMLTag, Link, LinkMark, etc.

I would like there to appear another custom node, let’s call it CustomNode, over HTMLTag. I know, I can define my own MarkdownConfig, and use defineNodes and parseInline, but that would require me to copy/reuse already existing HTMLTag parser. I would like to avoid that.

Is there some way, to just call .resolve(-1) and check if type is HTMLTag, and if so, just add a node there?

No. The syntax tree is produced by the parser, and cannot be mutated.

I don’t mean to mutate it.

I was thinking about adding a parser extension that could work like this?

export const CustomNode: MarkdownConfig = {
  defineNodes: ['CustomNode'],
  parseInline: [{
    name: 'CustomNode',
    parse(context: InlineContext, char: number, pos: number) {
      if (context.PreviousNodeEquals(Type.HTMLTag)) {
      return context.addElement(context.elt('CustomNode', pos, end))
      }    
    }
  }]
};

Obviously PreviousNodeEquals doesn’t exist, but maybe there’s some other way to check for previously parsed nodes, and impose new elements on top of them somehow?

Let me describe what I really want.

I’m using markdown extension, to render markdown. My users also use HTML tags with certain attributes embeded in them. Based on the attributed and names, the html tags “act” differently. And by that I mean I want to add different decoration, highlights, autocompletes, keymaps to them. Basically I need something to make certain HTMLTags behave as if they were another Markdown entity, even though I perfectly know that they aren’t. They’re just regular HTML tags as markdown is concerned. But I would like the parser to differentiate them somehow. Actually, it doesn’t have to be a parser. I would like to simply add some “user data” to it,. so that when I write deccorations, autocomplete, keymaps, highlights I can just do node.type === 'SPECIAL_TYPE' and just check it , without having to duplicate the “html-checking” logic in autocomplete, keymaps, decorations etc. Maybe assigning different tags to them would also be helpful.

What would be the best way to achive this?

I would simply like to add to the code mirror “something” that would allow me to mark or specify certain nodes, and then simply read that info in further places of the lib.

For example, I might have markdown like this

#heading
 
some kontent with inline kbd tag: somebody wants to use <kbd>Ctrl</kbd> key.

Someone below, might want to add block tag

<iframe src="href">

I know that from the markdown perspective, these tags are similar, there’s no real distingishment between them as far as parsing is concerned.

But I would like to somehow iterate them and mark them, so that the fruther parts of the library can use that distinction, instead of recomputing it again.

And the tags, must follow certain conditions (length, attributes, allowed keys inside). I would like a single place where I can distinguish/predicate them, and maybe assign a tag to the nodes or something; and then, in further parts of the app (autocomplete, decorations, keymaps) simply read those values from a boolean or something.