Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion commonV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ func getLinkContents(in []rune, tgSpecial bool) (bool, []rune, string, int) {
return true, text, content, urlEndIdx + 1
}

func isCodeBlockNewlineEnd(in []rune, offset int, item string) bool {
if item != "```" {
return false
}
return offset == 0 || in[offset-1] == '\n'
}

func getValidEnd(in []rune, s string) int {
offset := 0
for offset < len(in) {
Expand All @@ -106,7 +113,7 @@ func getValidEnd(in []rune, s string) int {

end := offset + idx
// validEnd check has double logic to account for multi char strings
if validEnd(end, in) && validEnd(end+len(s)-1, in) && !IsEscaped(in, end) {
if (validEnd(end, in) || isCodeBlockNewlineEnd(in, end, s)) && validEnd(end+len(s)-1, in) && !IsEscaped(in, end) {
idx = stringIndex(in[end+1:], s)
for idx == 0 {
end++
Expand Down
3 changes: 3 additions & 0 deletions md2htmlV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var basicMDv2 = []struct {
}, {
in: "```code\ncontent```",
out: "<pre><code class=\"language-code\">content</code></pre>",
}, {
in: "```code\ncontent\n```",
out: "<pre><code class=\"language-code\">content\n</code></pre>",
}, {
in: "```spaced words\ncontent```",
out: "<pre><code class=\"language-spaced words\">content</code></pre>",
Expand Down
Loading