Skip to content

Commit

Permalink
Fix newline prefixes for 'pre' blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSonOfLars committed Nov 11, 2023
1 parent 80a1e73 commit f7f2bb4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions md2htmlV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ func (cv ConverterV2) md2html(in []rune, enableButtons bool) (string, []ButtonV2
// TODO: How do we decide the language; first word? first line?
firstLine := strings.TrimSpace(splitLines[0])
if len(firstLine) > 0 && strings.HasPrefix(nestedT, firstLine) {
content := strings.TrimPrefix(nestedT, firstLine)
content := strings.TrimPrefix(nestedT, firstLine+"\n")
return out.String() + "<pre><code class=\"language-" + firstLine + "\">" + content + "</code></pre>" + followT, followB
}
}
return out.String() + "<pre>" + nestedT + "</pre>" + followT, followB
return out.String() + "<pre>" + strings.TrimPrefix(nestedT, "\n") + "</pre>" + followT, followB
}

// internal won't have any interesting item closings
Expand Down
6 changes: 3 additions & 3 deletions md2htmlV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ var basicMDv2 = []struct {
out: "<pre>content</pre>",
}, {
in: "```code\ncontent```",
out: "<pre><code class=\"language-code\">\ncontent</code></pre>",
out: "<pre><code class=\"language-code\">content</code></pre>",
}, {
in: "```spaced words\ncontent```",
out: "<pre><code class=\"language-spaced words\">\ncontent</code></pre>",
out: "<pre><code class=\"language-spaced words\">content</code></pre>",
}, {
in: "```quoted\"words\ncontent```",
out: "<pre><code class=\"language-quoted&#34;words\">\ncontent</code></pre>",
out: "<pre><code class=\"language-quoted&#34;words\">content</code></pre>",
}, {
// NOTE: Decide on whether this is just a sad casualty of markdown parsing, or if:
// The closing tag should be the last viable part, if in a sequence. (eg 3x'_', last two are underline closes)
Expand Down
2 changes: 1 addition & 1 deletion reverseV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (cv ConverterV2) reverse(in []rune, buttons []ButtonV2) (string, error) {
if len(m) > 0 {
// This <pre> block contains a <code class...> block; handle the language.
lang, code := m[1], m[2]
out.WriteString("```" + lang + code + "```")
out.WriteString("```" + lang + "\n" + code + "```")
} else {
// This is a regular boring pre block
out.WriteString("```" + content + "```")
Expand Down

0 comments on commit f7f2bb4

Please sign in to comment.