Skip to content

Commit

Permalink
Remove empty line at the end of markdown partials
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasschlueter committed Dec 8, 2018
1 parent 93e0928 commit 4c0bcd1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions partial_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func partialHelper(name string, data map[string]interface{}, help HelperContext)

if strings.HasSuffix(name, ".md") {
part = string(github_flavored_markdown.Markdown([]byte(part)))
part = strings.TrimSuffix(part, "\n")
}

if ct, ok := help.Value("contentType").(string); ok {
Expand Down
34 changes: 33 additions & 1 deletion partial_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func Test_PartialHelper_Markdown_With_Layout(t *testing.T) {

html, err := partialHelper(name, data, help)
r.NoError(err)
r.Equal("<html>This <em>is</em> a <p><strong>test</strong></p>\n</html>", string(html))
r.Equal("<html>This <em>is</em> a <p><strong>test</strong></p></html>", string(html))
}

func Test_PartialHelper_Markdown_With_Layout_Reversed(t *testing.T) {
Expand All @@ -302,3 +302,35 @@ func Test_PartialHelper_Markdown_With_Layout_Reversed(t *testing.T) {
r.NoError(err)
r.Equal(`<p>This <em>is</em> a <strong>test</strong></p>`, strings.TrimSpace(string(html)))
}

func Test_PartialHelpers_With_Indentatio(t *testing.T) {
r := require.New(t)

main := `<div>
<div>
<%= partial("dummy.md") %>
</div>
</div>`
partial := "```go\n" +
"if true {\n" +
" fmt.Println()\n" +
"}\n" +
"```"

ctx := NewContext()
ctx.Set("partialFeeder", func(string) (string, error) {
return partial, nil
})

html, err := Render(main, ctx)
r.NoError(err)
r.Equal(`<div>
<div>
<div class="highlight highlight-go"><pre>if true {
fmt.Println()
}
</pre></div>
</div>
</div>`,
string(html))
}

0 comments on commit 4c0bcd1

Please sign in to comment.