-
Notifications
You must be signed in to change notification settings - Fork 56
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
Markdown rendering error (nested partial, code block) #82
Comments
In case someone wants to work on this, here's a tests case to reproduce: func Test_PartialHelpers_Markdown_With_Text_Before_Partial_In_Partial(t *testing.T) {
r := require.New(t)
main := `<%= partial("outer.md") %>`
outer := `<span>Some text</span>
<%= partial("inner.md") %>
`
inner := "```go\n" + `if true {
fmt.Println()
}` + "\n```"
ctx := NewContext()
ctx.Set("partialFeeder", func(name string) (string, error) {
if name == "outer.md" {
return outer, nil
}
return inner, nil
})
html, err := Render(main, ctx)
r.NoError(err)
r.Equal(`<p><span>Some text</span>
<div class="highlight highlight-go"><pre>if true {
fmt.Println()
}
</pre></div>
</p>`, string(html))
} |
* Add empty line as a workaround for gobuffalo/plush#82 * Update plush
This is intended behavior, not of nested partials but of markdown. In your code the First, the inner partial will be translated as (in html) <div class="highlight highlight-go"><pre>if true {
fmt.Println()
}
</pre></div> The above is the expected result. So let's write the <span>Some text</span>
<div class="highlight highlight-go"><pre>if true {
fmt.Println()
}
</pre></div> As you can see, the
The reason that adding a line after resolves this issue is that it made the content correct. from https://daringfireball.net/projects/markdown/syntax#html |
So, this is some very specific issue that the
gobuffalo
repo ran into.The problem
Text explanation
In fact, I'm even having some difficulties describing it in an easy way:
If a markdown partial starting with code (
```...```
, ignoring white-space in the beginning) inside of a markdown partial is directly preceded by an html tag displaying some text (didn't happen withdiv
for example), the code will get parsed incorrectly.Code sample
Here's some code, hopefully that's more clear:
This should result in the following html code:
The actual output is the following:
This actually only happens with partials in partials.
Why does this happen?
The markdown parser interprets the indentation of
fmt.Println()
as a new code block (see https://guides.github.com/features/mastering-markdown/).I don't know why it does that though. I also don't know why it does that for inside of partials only.
Workarounds
There are multiple ways to prevent this from happening:
1. Don't use partials in partials
The following is working correctly - please don't ask me why.
2. Add an empty line between html and partial
If the
span
(or similar) is separated from the partial by an empty line, this also doesn't appear:3. Don't start partials with code
If the inner partial doesn't directly start with the code, this issue also doesn't happen.
Please note that adding white-space does not work, but adding
<div></div>
does.The text was updated successfully, but these errors were encountered: