diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 15:06:42 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 15:06:42 +0200 |
| commit | 21dd71949b05d84ef6ee2f05610ec7254f1086f0 (patch) | |
| tree | 72f94b52067774eed8264c5468b3b8a32b8553ef /mardown/error.go | |
| parent | be4cea404c15979112653cd4d75784aab527f22c (diff) | |
feat(markdown): custom error display
Diffstat (limited to 'mardown/error.go')
| -rw-r--r-- | mardown/error.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mardown/error.go b/mardown/error.go new file mode 100644 index 0000000..f85dfbb --- /dev/null +++ b/mardown/error.go @@ -0,0 +1,38 @@ +package mardown + +import "fmt" + +type ParseError struct { + internal error + lxs lexers +} + +func (e *ParseError) Error() string { + return e.internal.Error() +} + +func (e *ParseError) Pretty() string { + lxs := e.lxs + if lxs.lexers == nil { + return e.internal.Error() + } + current := lxs.current - 1 + for lxs.Before() && lxs.Current().Type != lexerBreak { + } + current -= lxs.current + contxt := "" + ind := "" + for lxs.Next() && lxs.Current().Type != lexerBreak { + contxt += lxs.Current().Value + if lxs.current < current { + if lxs.current == current-2 { + ind += "^" + } else { + for range len(lxs.Current().Value) { + ind += "~" + } + } + } + } + return fmt.Sprintf("%v\n\n%s\n%s", e, contxt, ind) +} |
