How to center text?

Markdown doesn’t seem to support centering text on its own, so I believe that I have to use html. According to the documentation, this is best done using a shortcode. So I defined the following shortcode:

<p style="text-align: center;">{{.Inner}}</p>

And then I try to use it as follows:

{{% center %}}
*emphasized test*
{{% /center %}}

In the resulting html, I obtain <!-- raw HTML omitted -->. I gather that this is because by default the feature is disabled in goldmark. Therefore, I added the following to my config:

      unsafe = true

The resulting html is

<p style="text-align: center;">
*emphasized test*

Markdown is not processed (no new lines and no emphasized text). According to the shortcode documentation, using % instead of < as the shortcode symbol should process markdown. So I don’t know what I am doing wrong.

Any help is greatly appreciated! Thanks.

I haven’t tried this in a shortcode, but I have done something similar using HTML div tag wrapping around Markdown and using the Goldmark-version Hugo… Try putting a blank line above and below the Markdown you are trying to wrap, and may be use div tag instead of p tag.


Thank you @kaushalmodi, this works.

Here is the shortcode:

<div style="text-align: center;">

which outputs

<div style="text-align: center;">
<em>emphasized test</em></p>

Cool! But also show the Markdown content you typed to get that so that someone else who stumbles across the same can use that.

It’s given in the original post. I kept it the same.

Try to render a html file that is supported too. You can use pugjs in combination with hugo what I personally do also.