Google Apps Script templating syntax gets stripped
VladimirMikulic opened this issue · comments
Vladimir Mikulic commented
Details
As the title suggests using postHTML strips Google Apps Script templating syntax from
the HTML file.
Reproduction (Code)
The example HTML file can be found here.
Sample code demonstrating the issue:
const fs = require('fs');
const posthtml = require('posthtml');
const entryFilePath = path.resolve(__dirname, 'index.html');
const html = fs.readFileSync(entryFilePath, 'utf-8');
const result = posthtml().process(html, { sync: true }).html;
/*
<? for (var i = 0; i < LANGUAGES.length; i++) { ?>
<p class="dropdown-item"><?= LANGUAGES[i].name ?></p>
<? } ?> -> source
<p class="dropdown-item"></p> -> postHTML output
*/
console.log(result);
Environment
OS | node | npm/yarn | package |
---|---|---|---|
[Kubuntu][20.04] | [12.18.3] | [6.14.7] | [0.13.1] |
Ivan Demidov commented
@VladimirMikulic Here you can clearly see the use of custom directives <?
& ?>
that you did not specify in the options for parsing.
import posthtml from "posthtml";
const php = `
<component>
<title><? echo $title; ?></title>
<text><? echo $article; ?></text>
</component>
`;
const result = posthtml()
.use(require("posthtml-custom-elements")())
.process(html, {
directives: [{ name: "?", start: "<", end: ">" }]
}).html;
console.log(result);
Do not hesitate to reopen the problem if I can help you with something else.
Vladimir Mikulic commented
Hi @Scrum.
Thank you very much. This does work.
Could you please tell me how could I achieve the same functionality but with plugins in the config file (.posthtmlrc
)?