summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-03-14 12:45:09 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-03-15 08:54:34 +0100
commitb0b1b76dc9c7edad15924785d01684e36f3e6cdb (patch)
tree85700dca0a8e7307ec168fcee4755c1a561a0f63 /common
parent0fbab7cbc5a0b57ec875858111b178160d18acb5 (diff)
markup/goldmark: Fail on invalid Markdown attributes
Diffstat (limited to 'common')
-rw-r--r--common/herrors/error_locator.go10
-rw-r--r--common/herrors/file_error.go14
2 files changed, 24 insertions, 0 deletions
diff --git a/common/herrors/error_locator.go b/common/herrors/error_locator.go
index c7e2d2f06..7624bab98 100644
--- a/common/herrors/error_locator.go
+++ b/common/herrors/error_locator.go
@@ -61,6 +61,16 @@ var OffsetMatcher = func(m LineMatcher) int {
return -1
}
+// ContainsMatcher is a line matcher that matches by line content.
+func ContainsMatcher(text string) func(m LineMatcher) int {
+ return func(m LineMatcher) int {
+ if idx := strings.Index(m.Line, text); idx != -1 {
+ return idx + 1
+ }
+ return -1
+ }
+}
+
// ErrorContext contains contextual information about an error. This will
// typically be the lines surrounding some problem in a file.
type ErrorContext struct {
diff --git a/common/herrors/file_error.go b/common/herrors/file_error.go
index e6baaf6e3..9273b2a80 100644
--- a/common/herrors/file_error.go
+++ b/common/herrors/file_error.go
@@ -392,3 +392,17 @@ func extractPosition(e error) (pos text.Position) {
}
return
}
+
+// TextSegmentError is an error with a text segment attached.
+type TextSegmentError struct {
+ Segment string
+ Err error
+}
+
+func (e TextSegmentError) Unwrap() error {
+ return e.Err
+}
+
+func (e TextSegmentError) Error() string {
+ return e.Err.Error()
+}