yogthos / markdown-clj

Markdown parser in Clojure
Eclipse Public License 1.0
540 stars 120 forks source link

Unexpected empty paragraph after footer #111

Closed whitecoop closed 7 years ago

whitecoop commented 7 years ago

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>"
yogthos commented 7 years ago

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

GoranZic commented 7 years ago

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.

yogthos commented 7 years ago

Just pushed out a new version with the fix.

whitecoop commented 7 years ago

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>"
GoranZic commented 7 years ago

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.

yogthos commented 7 years ago

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

whitecoop commented 7 years ago

I just needed to clean. Sorry about that.

yogthos commented 7 years ago

great to hear