jekyll-asciidoc icon indicating copy to clipboard operation
jekyll-asciidoc copied to clipboard

Liquid preprocessor not applied to included AsciiDoc files

Open lschmelzeisen opened this issue 8 years ago • 8 comments

According to the documentation, one should be able to set :page-liquid: to have the Liquid preprocessor be applied to AsciiDoc files. Currently, it seems like this is not applied to AsciiDoc files included from other files.

The reason for this is probably that Liquid is being run before the content is being passed to the AsciiDoc processor.

Steps to reproduce:

  1. Clone jekyll-asciidoc-quickstart

  2. Replace index.adoc by the following content:

    = Liquid in AsciiDoc Includes Test
    :showtitle:
    :page-liquid:
    
    {% for i in (1..3) %}
    {{ i }}
    {% endfor %}
    
    include::_myinclude.adoc[]
    
  3. Add file _myinclude.adoc to the root of the project with following content:

    {% for i in (1..3) %}
    {{ i }}
    {% endfor %}
    
  4. run jekyll serve (or equivalent) in the root of project

  5. visit the page generated by jekyll

Expected output

1
2
3
1
2
3

Observed output:

1
2
3
{% for i in (1..3) %} {{ i }} {% endfor %}

lschmelzeisen avatar Sep 24 '17 20:09 lschmelzeisen

Hmm. Something definitely does not seem right here. Thanks for reporting. I'll dig into it and see what's going on.

mojavelinux avatar Sep 25 '17 19:09 mojavelinux

The problem is that the liquid filter is applied to the raw source, before the AsciiDoc plugin gets involved. That step doesn't know anything about AsciiDoc includes, so it only looks at the flat source. Then Asciidoctor comes in and converts the content. Only then is the include file folded in, but Asciidoctor doesn't know anything about liquid. That's why the liquid tags are not processed in the include file.

There was never a test for this scenario, which is why it got overlooked.

In order to solve this, we'd need to introduce a custom IncludeProcessor that applies the liquid filter on the included content. At the moment, that has side effects, so it needs to be handled carefully.

mojavelinux avatar Oct 03 '17 05:10 mojavelinux

Hello :)

So, if I got it well, it means it's not currently possible to make Liquid-specific instructions (like cycle for example) work in an .ADOC file ? We have to choose one of those two scenarios for each page:

  1. Either begin the file with the classical AOC header (with layout etc), and give up Liquid instructions ;
  2. Either begin the file with the :page-liquid: instruction, making the Liquid-specific code work, but disabling the ADOC header and some (if not all) ADOC features.

Just want to be sure I understood quite well the current situation. Thanks :)

sitesref avatar Feb 01 '18 08:02 sitesref

This limitation is only scoped to include files. You can use liquid markup in the primary AsciiDoc document.

The limitation is not based on how you define the page data (i.e., front matter). It applies to all AsciiDoc files. The problem is, Jekyll has already run the Liquid engine before Asciidoctor has a chance to process includes. In order to add support for Liquid markup in included files, we'd have to implement a custom include processor, but that currently has other side effects.

mojavelinux avatar Feb 02 '18 01:02 mojavelinux

If we get the following issue fixed in Asciidoctor core, then it would open the door for adding liquid processing to include files: https://github.com/asciidoctor/asciidoctor/issues/571

(I need that feature for another use case, so it's very likely I'll implement it soon).

mojavelinux avatar Feb 02 '18 01:02 mojavelinux

@mojavelinux, any update on this? I have a project site that uses includes heavily, and this is blocker for us :(

rkratky avatar Aug 14 '19 19:08 rkratky

Nope, sorry.

mojavelinux avatar Aug 14 '19 20:08 mojavelinux

An easy workaround is to use liquid-level include: {% include stuff.adoc %}

ydirson avatar Apr 30 '20 09:04 ydirson