yogthos/markdown-clj

Unexpected empty paragraph after footer

whitecoop opened this issue · 8 comments

Is the empty <p></p> after the </footer> expected behavior?

(md->html "> Quote text\n>- Author Name\n\nA normal paragraph")
;; => "<blockquote><p> Quote text </p><footer> Author Name</footer><p></p></blockquote><p>A normal paragraph</p>"

Looks like it has to do with the double newlines after the footer, since these work as expected:

(md->html "> Quote text\n>- Author Name\nA normal paragraph")
;; => "<blockquote><p> Quote text </p><footer> Author Name</footer><p>A normal paragraph </p></blockquote>"
(md->html "> Quote text\n\nA normal paragraph")
;; => "<blockquote><p> Quote text </p></blockquote><p>A normal paragraph</p>"

That does look like a bug in parsing the the footer content.

I am looking into this.
And from the short analysis I can see that the problem lies in blockquote function in markdown.transformers.
Here is the the distilled example string which demonstrated the problem
">\n>- Author Name\n"
generates
<blockquote><p> </p><footer> Author Name</footer><p></p></blockquote>

So it's not so much a problem of double new lines but simply a problem when footer is the last element.
This is because each conditional in the blockquote function opens a paragraph tag when it's done. So when footer is last in the blockquote it opens a new p tag and closing blockquote tag will close it. Just removing the opening p tag from end of footer won't cut it, because any following content expects to have an opened p tag.

I am proposing a more context sensitive way of opening and closing of p tags within blockquote. I'll try to work out an elegant way, and create a pull request.

Just pushed out a new version with the fix.

I'm still running into the same <p></p> after the footer with 0.9.91.

(md->html "> Quote text\n>- Author Name\n\nA normal paragraph")
;;=> "<blockquote><p> Quote text </p><footer> Author Name</footer><p></p></blockquote><p>A normal paragraph</p>"

I haven't been able to reproduce this. I pulled the code from the master, and tried the same example and got
`"

Quote text

Author Name

A normal paragraph

"

the only difference perhaps is that I didn't try the clojurescript version but the clojure version, but it should be the same it uses the same functions. Could you just double check you've pulled the new version.

@whitecoop have you tried doing a clean to make sure the project doesn't have any stale artifacts?

I just needed to clean. Sorry about that.

great to hear