mistletoe icon indicating copy to clipboard operation
mistletoe copied to clipboard

Record line numbers on tokens

Open djmattyg007 opened this issue 2 years ago • 6 comments

I'm writing a tool to parse markdown files and verify that links are valid. To be able to provide the most valuable, accurate feedback, I need to be able to display line numbers to the user, so that they know exactly where in a file the broken link is.

Right now this isn't possible, because line numbers aren't recorded on token objects.

djmattyg007 avatar May 23 '22 12:05 djmattyg007

@djmattyg007, I think that what you propose would be a pretty cool feature. In principal, it shouldn't be hard to implement, yet it would probably require some broader refactoring in order to track & store the context information (line, plus column would be also nice). I would also watch out for possible impact on performance, but I don't expect some human-noticeable difference...

I would like to look at this one day, but I don't have much time these days, so, as usually, PRs are welcome in the meantime. :)

pbodnar avatar May 28 '22 17:05 pbodnar

Hi, I have a somewhat similar use case, where I'd like to know the position of translatable content in the Markdown document.

I've started on an implementation. It turns out that block tokens are fairly straightforward, but span tokens are more difficult.

@djmattyg007: If you could get the starting line number of the paragraph containing the link, would that be of any use to you? Or do you need the line number of the link?

anderskaplan avatar Jan 01 '23 15:01 anderskaplan

I need the line number (and ideally the offset on the given line).

djmattyg007 avatar Jan 02 '23 04:01 djmattyg007

Ok, I have a PR in the works for line numbers on block tokens which may or may not be useful for you. But it depends on #172, so it will have to wait until that one is merged.

anderskaplan avatar Jan 02 '23 09:01 anderskaplan

@anderskaplan, while implementing the MarkdownRenderer recently, haven't you investigated this feature request more? I think it would be pretty cool and possibly another distinguishing trait of mistletoe? :)

pbodnar avatar Jun 17 '23 16:06 pbodnar

Thanks to @anderskaplan, we've got this implemented for block tokens in #188. It still doesn't fully cover the original request though (finding out line number for a any, notably span token), so I will leave this issue open for now.

pbodnar avatar Dec 02 '23 11:12 pbodnar