Is it possible to retrieve the attributes of a line inside a syntaxTree?

Hi!

I am iterating through the syntaxTree and set for every codeblock an attribute codeblockId. But I also want to retrieve it? Is that even possible? I know that EditorView.dom returns the DOM but how do I find the current “line” in it?

syntaxTree(view.state).iterate({ from: codeblock.from, to: codeblock.to,
  enter(node) {
    const line = view.state.doc.lineAt(node.from);
    const lineText = view.state.sliceDoc(line.from, line.to);
    const lang = searchString(lineText, "```");
    
    // chek if line has attribute codeblockId??
    
    if (node.type.name === "HyperMD-codeblock_HyperMD-codeblock-bg" ) {
      decorations.push(Decoration.line({attributes: {class: lineClass, "codeblockId": randomString}}).range(node.from));
      lineNumber++;
    }
  },
});

Thanks!

What do you mean by “line”? You appear to have the Line object in your line variable already.

Sorry, I wasn’t clear enough. So, I process the syntaxTree and identify codeblocks. I want to check if a specific attribute is set. If not, I generate a unique id, and add it with a line decoration. This way every codeblock would have a unique attribute, which I could query and do some calculations, which is basically my end goal. I need to calculate something but it must be specific for some codeblocks, which depends on user input. I hope it is understandable now.

Sounds like those ids are state created by your extension? You could keep them in a RangeSet in a StateField, I suppose.