mmark
mmark copied to clipboard
Expose source position to scanners and extensions
Would it be possible to expose the source position for scanners and extension building functions? I have two use cases that would greatly benefit from this:
-
Many extensions can fail on bad markup. Currently, when this happens it can be really hard find out where it happened. For example, I would like to typecheck my code examples.
-
Wiki like editing would benefit from this as it would allow the generated html to point at the original source
I did notice that this was mentioned in the documentation. You can count this issue as a vote for adding the source locations + an offer to do some of the work.
This would require also adding a proper way for extensions to signal failure.
I think raising an exception would be sufficient.
Well I think it's not the best way to solve the problem, mostly because this
- Can be handled "purely", i.e. without exceptions.
- I'm not a big fan of throwing exceptions from pure code.
- This does not allow us combine and report multiple errors at once, which is something we could reasonably expect from a tool with already such a good story with respect to error reporting.
So for now throwing is an option because the code is written as it's written, but I think we should improve this in the future, or at least try to.
I agree on all of your points. However, I think that the error handling depends on the source position, so the latter would be best to implement first. If I'd submit a patch to add source position / span for code blocks and inline urls would that make for acceptable first step?
Well you could try, but my understanding is that it's not trivial to get quite right and it may make the parser slower. Be prepared that I may be picky about the solution.