Skip to content

Instantly share code, notes, and snippets.

@drewsberry
Last active August 29, 2015 14:04
Show Gist options
  • Save drewsberry/48efc382a5a87ed8cf77 to your computer and use it in GitHub Desktop.
Save drewsberry/48efc382a5a87ed8cf77 to your computer and use it in GitHub Desktop.
Add lineanchors to all Liquid highlight tags

This small bash script replaces all Liquid codeblock tags with one including the lineanchors option. For instance:


{% highlight vim %}

{% highlight ruby %}```

Is converted to:

```{% highlight python lineanchors %}

{% highlight vim lineanchors %}

{% highlight ruby lineanchors %}```

The context of this is that CSS counters for codeblocks need lineanchors to be enabled, but the plugin I was using, [Pygments Global Options](https://gist.github.com/danasilver/8121699), is incompatible with the new Jekyll 2.2.0. Hence, I needed a way to add `lineanchors` to all the Liquid tags *after* the language (`highlight lineanchors lang` simply doesn't work, as Jekyll interprets `lineanchors` as the language instead of `lang`).

This seemed like the simplest solution to the problem. If anyone has a simpler/more elegant one, let me know.
#!/bin/bash
# Adds lineanchors option to all codeblock Liquid tags
languages=( vim python perl ruby yaml css html bash cpp c )
posts="../_posts/*"
for lang in "${languages[@]}"
do
:
perl -pi -e "s/highlight $lang/highlight $lang lineanchors/g" $posts
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment