asciidoctor / jekyll-asciidoc

:syringe: A Jekyll plugin that converts AsciiDoc source files in your site to HTML pages using Asciidoctor.

Home Page:https://github.com/asciidoctor/jekyll-asciidoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Liquid preprocessor not applied to included AsciiDoc files

lschmelzeisen opened this issue · 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 %}

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

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.

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 :)

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.

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

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

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

Nope, sorry.

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