Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record line numbers on tokens #144

Open
djmattyg007 opened this issue May 23, 2022 · 6 comments · Fixed by #188
Open

Record line numbers on tokens #144

djmattyg007 opened this issue May 23, 2022 · 6 comments · Fixed by #188
Labels

Comments

@djmattyg007
Copy link

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.

@pbodnar
Copy link
Collaborator

pbodnar commented May 28, 2022

@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. :)

@anderskaplan
Copy link
Contributor

anderskaplan commented Jan 1, 2023

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?

@djmattyg007
Copy link
Author

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

@anderskaplan
Copy link
Contributor

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.

@pbodnar
Copy link
Collaborator

pbodnar commented Jun 17, 2023

@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 pbodnar linked a pull request Jul 2, 2023 that will close this issue
pbodnar pushed a commit that referenced this issue Dec 2, 2023
* add tracking of line numbers to block_tokenizer.FileWrapper
* assign line numbers to all block tokens during parsing
* add line_number as a repr_attribute on all block tokens
* update the developer's guide
@pbodnar pbodnar added this to the 1.3.0 milestone Dec 2, 2023
@pbodnar
Copy link
Collaborator

pbodnar commented Dec 2, 2023

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 pbodnar reopened this Dec 2, 2023
@pbodnar pbodnar removed this from the 1.3.0 milestone Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants