Adding styling to text blocks without using inline HTML

So I have finally managed to remove all inline HTML in my blog that was previously used to style the images inserted into my posts. I’ve done this using CSS selectors so that Markdown such as

![](Landscape.jpg#align-left)

produces the result I want. My question is how do I do something similar for text spans? As an example, I have one blog post where I’m using span blocks to add CSS to set the text color. These effects have disappeared now that I removed the following from my config.toml file. I needed this block to get the inline HTML to render previously.

[markup]
   [markup.goldmark]     
      [markup.goldmark.renderer]        
         unsafe = true

Is there an analogous idea to what I’m using for images to apply to text?

Thanks in advance for your help!

Hi, I hope others will contradict me, but I don’t think that there is a really usable or straightforward way to do that. Depending on how many different elements you want to style, you might create shortcodes for these elements and use that. (You can pass parameters to shortcodes, so you can set the color/class/whatever from the markdown that way).

Also, this might be an interesting idea.

HTH

Not. Yet. Maybe some day :slight_smile:

Thanks to you both for confirming this. After lots of web searching, I concluded there’s no other present path besides what I’m doing now. So I’ve gone back and switched unsafe = true once again.

As a workaround, you could set some predefined styles in some shortcodes and then apply them to the inner data (images or text or whatever). It’s not elegant, but it works!

1 Like