A few weeks ago, I decided to move from Wordpress to a more flat blog engine. After some test, I chose to use Jekyll. I may write a blogpost about this and the related motivation but this is not the actual topic.

During the setup, I needed to implement a search engine. As Jekyll is a flat blog engine, I can’t really implement any dynamic solution. My solution was to implement a lunr.js on the website. For it to operate, it requires a big json file with all the text to search.

The json file is generated during the build stage. Due to this, it will parse the other md files to generate the content. This means that the template file of the json will remplace the Liquid variables with some other Markdown but more especially Liquid variables and statements.

This lead to a classic error :

{% highlight console %} was not properly terminated with regexp: /}}/ in search_data.json {% endhighlight %}

I skip the first part of the error as it’s not relevant. I longly googled on this. But, most of the page foscused on a variable containing Liquid statement that would have be published as this. This is not valid in my case as I want to parse the embedded content and use some other Liquid filters as I would do with :

{% endhighlight %} {{ content | replace: ‘{foo}’, ‘bar’ }} {% endhighlight %}

So, it returned the error. Logic as Liquid will parse this statement, replace ‘content’ with it’s value, another Liquid statement, also finishing with }}. I tried several solutions to escape this with no luck.

I ended with a magical and even more obvious solution : ‘markdownify’

{% endhighlight %} {{ content | markdownify | replace: ‘{foo}’, ‘bar’ }} {% endhighlight %}

This solved the case at once !

Updated: