honkit / honkit

:book: HonKit is building beautiful books using Markdown - Fork of GitBook

Home Page:https://honkit.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Template escaping doesn't work in included adoc files

jeff-button opened this issue · comments

HonKit version: 4.0.4

I'm using {% raw %} and {% endraw %} in several adoc files. They are removed correctly by honkit build . dist except when included in another adoc file.

Parent Adoc

{% raw %} PARENT - this will {{ not be processed }} {% endraw %}

include::./child.adoc[]

Child Adoc
{% raw %} CHILD - this will {{ not be processed }} {% endraw %}

Html Output

<pre>PARENT - this will {{ not be processed }}</pre>
<p>{% raw %} CHILD - this will {{ not be processed }} {% endraw %}</p>

Repo

https://github.com/jeff-button/honkitTemplateExample

commented

Probably, It is caused by the order of processing.

// Render templating syntax
.then(async (content) => {
// console.log("page:preparePage", Date.now() - start);
const absoluteFilePath = path.join(book.getContentRoot(), filePath);
// if has compiled pages, use it instead of compiling page
const pageHash = page.hash();
const cachedPage = cache.getKey(pageHash);
if (cachedPage) {
return Page.fromJSON(output);
}
try {
const output = await Templating.render(engine, absoluteFilePath, content, context);
// update cache
cache.setKey(pageHash, Page.toJSON(output));
return output;
} catch (error) {
console.error("Template Rendering Error", error);
console.log("Template content", content);
throw error;
}
})
.then((output) => {
// console.log("page:render", Date.now() - start);
const content = output.getContent();
return parser.parsePage(content).then((result) => {
return output.setContent(result.content);
});
})
// Post processing for templating syntax
.then((output) => {
// console.log("page:parsePage", Date.now() - start);
return Templating.postRender(engine, output);
})

Current

  1. render template
  2. parse markup

{% raw %} is processed by template engine. So 1 treat it.
But, include::./child.adoc[] is asciidoc feature. So 2 treat it.
As a result, it can not process {% raw %} in child.asoc.

I am not aware if this order can be changed.(It may breaks something)

Workaround: Probably, it can be avoided by using inclulde tag.

{% include "./child.adoc" %}

It is processed by template engine.

That works. Thank you!