1
0
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:
Oliver Steele 2017-08-22 11:10:39 -04:00
parent c96587c05b
commit f247ed4ebe
2 changed files with 13 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {