todvora / gitbook-plugin-image-captions

Image captions plugin for GitBook
Apache License 2.0
44 stars 18 forks source link

Paragraphs and inline image #1

Closed aschempp closed 9 years ago

aschempp commented 9 years ago

I've installed this plugin and like it a lot. However, I found out that the Markdown parser is always adding a paragraph for each line.

Problem 1

Lorem Ipsum dolor …

![foobar](foo/bar.jpeg)

… sit amet

will result in this HTML:

<p>Lorem Ipsum dolor …</p>

<p><img src="foo/bar.jpeg" alt="foobar"></p>

<p>… sit amet</p>

This plugin then converts it to a figure with caption. However, a figure (block element) is not allowed within a paragraph (invalid HTML).

Problem 2

Additionally, it will break the content if the image is inline.

Lorem Ipsum dolor ![foobar](foo/bar.jpeg) … sit amet

will result in

<p>Lorem Ipsum dolor <img src="foo/bar.jpeg" alt="foobar"> sit amet</p>

Converting the inline image in this case is wrong, because it would become a block element due to <figure> (apart from problem 1).

Solution

I have changed the plugin to only handle image tags that are inside empty paragraphs, and then also remove the paragraph. I hope my assumption about the markdown parser is correct, but as the plugin is for Gitbook I guess we can assume always the same parser…

todvora commented 9 years ago

Hi Andreas, Thank you very much for your changes! They are now merged and the plugin released as 0.2.0.

Best regards, Tomas

aschempp commented 9 years ago

Thanks! :+1: