mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-03 22:12:35 +00:00
feat: integrate goldmark Pos() for better error reporting
This commit is contained in:
19
renderer/util.go
Normal file
19
renderer/util.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package renderer
|
||||
|
||||
// GetLineCol returns the 1-based line and column for a given byte offset in the source.
|
||||
func GetLineCol(source []byte, offset int) (line, col int) {
|
||||
line = 1
|
||||
col = 1
|
||||
if offset > len(source) {
|
||||
offset = len(source)
|
||||
}
|
||||
for i := 0; i < offset; i++ {
|
||||
if source[i] == '\n' {
|
||||
line++
|
||||
col = 1
|
||||
} else {
|
||||
col++
|
||||
}
|
||||
}
|
||||
return line, col
|
||||
}
|
||||
Reference in New Issue
Block a user