commonmark / commonmark-java

Java library for parsing and rendering CommonMark (Markdown)
BSD 2-Clause "Simplified" License
2.31k stars 288 forks source link

Also include "input index" in SourceSpan #348

Closed robinst closed 1 month ago

robinst commented 1 month ago

The existing line/column indexes in SourceSpan are useful for some cases, e.g. editors that are line based. But for other cases, it's useful to be able to get the index within the original input string.

An example: If the input string is "foo\n\nbar", the "bar" paragraph has the following SourceSpan:

With this change, now it also includes the input index: 5 ("b" is the character at index 5 in the string). That means it's possible to use e.g. substring instead of having to split the input text into lines first.