Missing source position of Links #550
Replies: 1 comment 1 reply
-
|
goldmark is designed with the goal of balancing a relatively easy-to-work-with AST and performance. At least in v1, I do not think it will be changed to preserve the positions of all elements, because that would likely have a small performance impact. It could be possible in the future when building v2. By the way, I have also created another CommonMark parser called rushdown (written in Rust). Rushdown uses Rust’s flexible conditional compilation to meet your requirements. If you compile it with the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
<>, Table, etc) are not part of CommonMark spec. You should confirm your output is different from other official renderers correspond with an extension.Please answer the following before submitting your issue:
When parsing links, the AST loses information on the source location of the entire link.
The Link node has descendants from which we can infer a portion of the link, but the rest of it is lost during parsing.
At first I considered that this might be out-of-scope, but then I noticed that README.md mentions one of the core motivations behind goldmark is to preserves source position of nodes. This is exactly what I'm missing in this case.
Because links themselves don't have any position information, the best we can do is extract the "visible" portion from their text descendants:
In my particular use case, I'm using goldmark for zk's LSP. User trigger "go to definition" to follow a link on their editor. But the entire source position of the Link is not available from the AST, so I have to extract it with some hack scanning:
This is ugly, hacky and inefficient. It would be immensely useful if the Link AST node could include the entire
Segmentfor its source, or at least aStartandEndfields.A previous related issue exits, but it "expired": #138
Beta Was this translation helpful? Give feedback.
All reactions