Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center align image in README.adoc (AsciiDoc) on GitHub

I want to center align an image in a README.adoc file in GitHub.

I know that for Markdown files, adding HTML like the following works:

<p align="center">
  <img width="460" height="300" src="http://www.fillmurray.com/460/300">
</p>

However, I want to write the file in AsciiDoc, not Markdown.

What I have tried but has not worked

Suppose there is a map.png image in the same dir as the README.

image::map.png[A map, 350, align=center]

This displays the correct image, but aligned to the left.

like image 785
HerCerM Avatar asked Jun 22 '20 23:06

HerCerM


People also ask

How do I center an image in a readme GitHub?

So, that means to center or align images in GitHub readmes, your only solution is to use the deprecated HTML align attribute (that happens to still function), as this answer shows.

How do I center an image in Asciidoc?

Open the asciidoctor-default. css and find the place where for imageblock the text-align attribute is set to left and change that to center . For me, this was in line 177. Rebuild your ASCIIDoctor document and the rendered HTML should have centered image caption.

How do I center align an image in markdown?

Solution 2 : use the "align" deprecated attribute This is not recommended, but in some cases this is the only way to center the image. Insert this HTML snippet into your markdown file. You can also try to put the "align" attribute directly into the "img" tag.

How do I center an image in ul li tag?

You can just remove img {display: block;} , by default it is inline level, they will get centered with text-align: center; set on the container, which you already did.


1 Answers

GitHub is using Asciidoctor but strips away CSS classes and inline CSS styles. As a workaround you can use a passthrough (which is not ideal):

++++
<p align="center">
  <img width="460" height="300" src="http://www.fillmurray.com/460/300">
</p>
++++

You can also comment/vote for this issue: https://github.com/github/markup/issues/984

I recommend using a conditional block to use this passthrough only when the README is rendered on GitHub:

ifdef::env-github[]
++++
<p align="center">
  <img width="460" height="300" src="http://www.fillmurray.com/460/300">
</p>
++++
endif::[]

ifndef::env-github[]
image::map.png[A map, 350, align=center]
endif::[]
like image 176
Mogztter Avatar answered Sep 30 '22 05:09

Mogztter