Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix markdown partials in markdown partials #81

Merged
merged 3 commits into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
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_Indentation(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))
}