From b0b1b76dc9c7edad15924785d01684e36f3e6cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 14 Mar 2023 12:45:09 +0100 Subject: markup/goldmark: Fail on invalid Markdown attributes --- common/herrors/error_locator.go | 10 ++++++++++ common/herrors/file_error.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'common') 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() +} -- cgit v1.2.3