Is lezer tree(markdown) to html or to mdast possible?

Hi,
I know that the README says that Note that this only parses the document, producing a data structure that represents its syntactic form, and doesn’t help with outputting HTML.
But I want to know if it is possible to convert a lezer tree into an ast and then into an html document. Personally, I think it’s doable, it just seems like the process is a bit of a pain, because lezer tree only have the position and before I dive into it, I’d like to know if it’s worth it (in terms of performance, not development difficulty) or if it’s more cost effective to just use some other tool (like remarkjs) to generate the HTML directly. Thanks.

If you are trying to highlight the code, see highlightTree. If you are trying generated some HTML that has the shape of the tree, you’ll need to write some custom logic using Tree.iterate.

Thanks for your reply, I am going to generate an HTML syntax tree.
I tried using the Tree.iterate method and it does do the job, below is a simple code which generates a simple tree structure.

In this process, I have a question, will lezer tree have nesting of the same nodes? For example, a “Paragraph” node contains a “Paragraph” node.

root.children = genHtmlTree(syntaxTree(state), doc);

function genHtmlTree(tree: Tree, doc: Text) {
  const newTree: any[] = [];
  tree.iterate({
    enter(node) {
      if (node.name === tree.topNode.name) return;
      const item: any = {};
      item.type = node.name;
      item.text = doc.sliceString(node.from, node.to);
      item.children = [];
      item.position = {
        from: node.from,
        to: node.to,
      };
      if (node.tree) {
        item.children = genHtmlTree(node.tree, doc.slice(node.from, node.to));
      }
      newTree.push(item);
      return false;
    },
  });
  return newTree;
}

With Markdown paragraphs, no, there’s no way to have a paragraph within a paragraph in Markdown. In general, yes, nodes of the same type can nest (you can have a list within a list, or an expression within an expression in a programming language).

Oh, I’m sorry, I’m having trouble expressing myself.

Actually, what I wanted to ask is whether there will be the same node in the adjacent level between parent and child, I know that for example “BulletList” can contain a node that is “BulletList”, but the containment is not neighboring, often there may be a layer in the middle, such as “ListItem”.

That is also possible—blockquotes could be direct children of blockquotes, for example.