Repository navigation
Support for including source spans on block nodes - #185
Merged
Merged
Conversation
The previous attempt required every block parser to implement source positions, which is not ideal. This one is for trying to see if we can get it done inside DocumentParser. Note that SourceSpan initially used 1-based indexes and beginIndex/endIndex, but it was changed to 0-based and a length because: 0-based fits better with the existing API and other Java APIs. And instead of having an endIndex, having a length would allow us to easily extend the SourceSpan to include a character offset in addition to line/column offset.
The block parsers will still need to be extended so that they can communicate where the source started, in case they return positions after marker characters. I think we can put that into BlockStart and BlockContinue though.
This means that e.g. this:
```
paragraph starting with a space
```
Will include the starting space in the source positions. I was initially
thinking it should not be included, but that makes a lot of things
harder, for not much gain IMO.
E.g. for a code block with 5 spaces:
```
code
```
Where should the source position start, at index 0, 4, or 5? This
implements 0. 4 is kind of hard to implement due to tabs being treated
as 4-space tabstops.
Just better to not accidentally modify it.
|
@robinst Hi! Just a note. Knowing the position in source is also very helpful when you need to report warnings/errors. E.g. I'm using HTMLRenderer and I'm trying to verify that links lead to "somewhere", and when the linked resource is missing, I would like to report a warning. But currently I've no chance to get source location from e.g. Link node. Looking forward for the new release! :-). Do you have any plans already? Or is there any other workaround how to get position in source markdown? (I'm using lastest release 0.15.2). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
or start editing on the block that was selected.
includeSourceSpansonParser.Builderto enable, read data withNode.getSourceSpansFixes #1 for block nodes. Will look into inline nodes too after #180, which might require more API changes.