X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/fc51ee2f545233df3cc1fa2fd4f28a4484c6bc00..97729fc59a2fbd73e3f8a424cae4c825f5ba885b:/markdown.go?ds=sidebyside 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 {