blackfriday
blackfriday copied to clipboard
blackfriday does not parse markdown within <div> blocks
Using the function markdownCommon
does not parse markdown within div
blocks. This feature worked previously on golang 1.2.1, blackfriday 1.1 with markdownCommon
currently using golang 1.4.2 blackfriday v1.2
Test Case 1
output := blackfriday.MarkdownCommon(body)
Test Case 2
hello-world-div.md | blackfriday-tool
Input: hello-world-div.md
<div>
## hello
</div>
## world
Output:
$ cat ~/hello-world-div.md | blackfriday-tool -page=false
<div>
## hello
</div>
<h2>world</h2>
Fails to parse markdown within a div block
Using EXTENSION_LAX_HTML_BLOCKS had no effect in html div block rendering
extensions := 0
extensions |= blackfriday.EXTENSION_LAX_HTML_BLOCKS
- Currently not able to replicate on go1.2.1 or blackfriday1.1 either
package main
import (
"fmt"
"github.com/russross/blackfriday"
)
func main() {
outb := blackfriday.MarkdownCommon([]byte(`
<div>
## hello
</div>
## world
`))
fmt.Print(string(outb))
}
This is expected behavior according to Markdown spec:
Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style emphasis inside an HTML block.
Is EXTENSION_LAX_HTML_BLOCKS // loosen up HTML block parsing rules
implemented to parse within block-level HTML tags?
I could help resolve the implementation or create a EXTENSION_PARSE_HTML_BLOCKS feature.
The benefit of this extension feature is to put markdown text into bootstrap column grid. Life would be flexible with CSS div block formatting.
Small hack for markdown parsing in HTML. Works great! on all my mix markdown and html documents.
Uncomment p.htmlFindEnd
block.go
//j = p.htmlFindEnd(curtag, data[i-1:])
TODO: Write Extension and tests
I believe CommonMark handles this. Rather than a completely custom extension, it would be nice to match their approach. See here:
http://spec.commonmark.org/0.21/#html-blocks
As I understand it, a blank line after the opening
On Mon, Sep 7, 2015 at 4:03 PM, John Appleseed [email protected] wrote:
Small hack for markdown parsing in HTML. Works great! on all my mix markdown and html documents.
Uncomment p.htmlFindEnd
block.go
//j = p.htmlFindEnd(curtag, data[i-1:])
TODO: Write Extension and tests
— Reply to this email directly or view it on GitHub https://github.com/russross/blackfriday/issues/184#issuecomment-138384018 .
@russross - following the Markdown spec makes sense (of course) but also could be extended with a means to explicitly override the default (as is done in other markdown renderers).
<div markdown="1">
*Hello*
</div>
Renders:
<div>
<p><em>Hello</em></p>
</div>
+1 for the markdown=1
option!
Apparently you can get blackfriday to parse markdown within a div by altering the use of whitespace; for instance, in the following example the markdown inside the divs is parsed just fine.
This is testing some stuff
<div class="row">
<div class="col-lg-6 bg-light-gray">
## Simple text test
- stuff
- other stuff
</div>
<div class="col-lg-6">
## h2 test
</div>
</div>
But delete the line This is testing some stuff
so that the doc begins with an html tag, (with or without newline whitepace around it) and suddenly it doesn't parse the markdown any more. Is this a bug?
Thanks @russross for the link to the commonmark spec behavior regarding when to parse markdown in a div; some of the examples there (e.g. #116 are likewise a bit counter-intuitive, but make sense in light of the rules given. I thought this might explain what blackfriday is doing in the above example, but it does not (at least, I don't seem to be getting the same behavior, e.g. in the above example, as described in commonmark). It would be great to either have blackfriday follow the commonmark spec or at least get a better understanding about when blackfriday does or does not parse markdown inside the div.
Sorry to bump this issue. Are there any plans to add this feature?