Apply style to a specific set of keywords in a post?

Viewed 18

I'd like to apply some style to any instances of a specific set of words in a post. Such as names, places, etc.

I believe this is sufficiently different to syntax highlighting that would only apply to a code block.

So, in my post front matter I would have:

keywords: [Deneba, Star Wars, Han Solo, Obiwan]

and in the rendered Post I would like to see:

Han Solo was on his way to Deneba with Obiwan.
— Excerpt from Star Wars

I'm hosting on GitHub Pages, but can change that if I need to.

Thoughts appreciated!

1 Answers

I hacked this together:

{% assign modified = content %}
{% for noun in page.nouns %}
{% assign italic = noun | prepend: '<em>' | append: '</em>' %}
{% assign modified = modified | replace: noun,italic %}
{% endfor %}
{{ modified }}
Related