X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/fc51ee2f545233df3cc1fa2fd4f28a4484c6bc00..84fc815feb485b35eec53a8c7863c6770fc65e02:/markdown.go diff --git a/markdown.go b/markdown.go index 48e9ace..1a2f4fe 100644 --- a/markdown.go +++ b/markdown.go @@ -169,8 +169,7 @@ func closingFence(lines []string, index int, fence string) int { } for end := index + 1; end < len(lines); end++ { - trimmed := strings.TrimSpace(lines[end]) - if strings.HasPrefix(trimmed, fence) && strings.Trim(trimmed, "`") == "" { + if closesFence(lines[end], fence) { return end } } @@ -178,6 +177,12 @@ func closingFence(lines []string, index int, fence string) int { return -1 } +// closesFence tells if line closes the code block of fence. +func closesFence(line, fence string) bool { + trimmed := strings.TrimSpace(line) + return strings.HasPrefix(trimmed, fence) && strings.Trim(trimmed, "`") == "" +} + // headingText returns the text of an ATX heading line without its marks, or "" // when line is not a heading or has no text. func headingText(line string) string {