miyuchina/mistletoe

Record line numbers on tokens

Opened this issue · 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, 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. :)

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?

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

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, 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? :)

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.