mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 21:34:45 +01:00
Don't get confused by <user@example.com> inside markdown=1
This commit is contained in:
parent
c96587c05b
commit
f247ed4ebe
@ -109,6 +109,12 @@ func stripMarkdownAttr(tag []byte) []byte {
|
||||
return tag
|
||||
}
|
||||
|
||||
// Used inside markdown=1.
|
||||
// TODO Instead of this approach, only count tags that match the start
|
||||
// tag. For example, if <div markdown="1"> kicked off the inner markdown,
|
||||
// count the div depth.
|
||||
var notATagRE = regexp.MustCompile(`@|(https?|ftp):`)
|
||||
|
||||
// called once markdown="1" attribute is detected.
|
||||
// Collects the HTML tokens into a string, applies markdown to them,
|
||||
// and writes the result
|
||||
@ -122,7 +128,9 @@ loop:
|
||||
case html.ErrorToken:
|
||||
return z.Err()
|
||||
case html.StartTagToken:
|
||||
depth++
|
||||
if !notATagRE.Match(z.Raw()) {
|
||||
depth++
|
||||
}
|
||||
case html.EndTagToken:
|
||||
depth--
|
||||
if depth == 0 {
|
||||
|
@ -16,6 +16,10 @@ func TestRenderMarkdown(t *testing.T) {
|
||||
|
||||
_, err := renderMarkdownString(`<div a=1 markdown=1><p></div>`)
|
||||
require.NotNil(t, err)
|
||||
require.Contains(t, err.Error(), "EOF")
|
||||
|
||||
require.Contains(t, mustMarkdownString(`<div markdown=1><user@example.com></div>`), `<a href="mailto:user@example.com">user@example.com</a>`)
|
||||
require.Contains(t, mustMarkdownString(`<div markdown=1><http://example.com></div>`), `<a href="http://example.com">http://example.com</a>`)
|
||||
}
|
||||
|
||||
func mustMarkdownString(md string) string {
|
||||
|
Loading…
Reference in New Issue
Block a user