Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Markdown, is there a way to stop images from being wrapped with <p> tags?

I'm using Jekyll and all my posts are in .md format for convenience. The problem is that the generator is automatically wrapping every line in paragraph tags.

line

<img>

line

becomes

<p>line</p>

<p><img></p>

<p>line</p>

and this means that my images are restricted to the width I've set for my paragraphs, which is messing up my styles.

Any ideas what I can do to avoid this? I've tried both html syntax and markdown syntax for the images but nothing seems to work.

Thanks!

like image 708
Joel Avatar asked Jun 27 '14 15:06

Joel


People also ask

Can Markdown embed images?

Images can be added to any markdown page using the following markdown syntax: ![ alt text for screen readers](/path/to/image. png "Text to show on mouseover") .

What Markdown syntax would you use to display images from the image column?

Type it in using Markdown ! [](image. png) or HTML syntax. Using the Embed Image Dialog to select images or Urls.

How do you add a tag in Markdown?

If your Markdown application supports HTML, you can use the <br> HTML tag. For compatibility, use trailing white space or the <br> HTML tag at the end of the line.


2 Answers

I don't think so. The original Markdown spec says:

A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines.

It might be possible to come up with some nifty CSS to fix your styling issues though.

Or you could try this hack (works in Pandoc):

line

<div><img></div>

line
like image 169
mb21 Avatar answered Oct 07 '22 15:10

mb21


Images are inline elements, intended to reside within a block-level element like a paragraph. Markdown parsers are therefore correcting your ‘mistake’ and wrapping the img inside a paragraph tag.

Wrapping your img tag inside an appropriate block-level element, like figure should prevent this behaviour. Eg:

<figure><img src=""></figure>

If you want to automate things a little and you are not planning to generate your site on Github pages (where plugins are not allowed) then you can make use of a plugin to assist in this and make image insertion in your posts easier. I'm using a modified version of this plugin:

https://github.com/opattison/jekyll-figure-image-tag/blob/master/figure_image_tag.rb

like image 10
Seth Warburton Avatar answered Oct 07 '22 16:10

Seth Warburton