aboutsummaryrefslogtreecommitdiff
path: root/markdown/error.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 19:52:38 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 19:52:38 +0200
commit94dceb4f7c1740de9215b36ec183f93ca4337ee7 (patch)
tree5ad184efb0b74dd3aa4da7585f88a3e3f6cb4ecc /markdown/error.go
parent8b249c9ce8bd1c351daf80c6c9b095fb1bccafe2 (diff)
style(markdown): fix typo in package name
Diffstat (limited to 'markdown/error.go')
-rw-r--r--markdown/error.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/markdown/error.go b/markdown/error.go
new file mode 100644
index 0000000..6f88968
--- /dev/null
+++ b/markdown/error.go
@@ -0,0 +1,43 @@
+package markdown
+
+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 {
+ ch := "~"
+ if lxs.current == current {
+ ch = "^"
+ }
+ for range len(lxs.Current().Value) {
+ ind += ch
+ }
+ }
+ }
+ if lxs.current == current {
+ runes := []rune(ind)
+ runes[len(runes)-1] = '^'
+ ind = string(runes)
+ }
+ return fmt.Sprintf("%v\n\n%s\n%s", e, contxt, ind)
+}