azu / gitbook-plugin-include-codeblock

GitBook plugin for including file
Other
40 stars 25 forks source link

Error When Importing YAML with {{}} Markup #80

Open suzuki-shm opened 1 month ago

suzuki-shm commented 1 month ago

Hello,

I’ve encountered an issue when importing YAML content that includes {{}}. This expression often appears in the GitHub Actions definitions documentation. It appears that HTML markup is being applied to the text within the {{}}, which causes rendering failures during nunjucks processing.

error: error while generating page "MY_DOCUMENT.md":
Template render error: (/home/USER_NAME/path/to/file/MY_DOCUMENT.md) [Line 62, Column 220]
  unexpected token: <
    at Object._prettifyError (/home/USER_NAME/PROJECT_DIR/node_modules/nunjucks/src/lib.js:32:11)
    at Template.render (/home/USER_NAME/PROJECT_DIR/node_modules/nunjucks/src/environment.js:442:21)
    at Environment.renderString (/home/USER_NAME/PROJECT_DIR/node_modules/nunjucks/src/environment.js:313:17)
    at Promise.apply (/home/USER_NAME/PROJECT_DIR/node_modules/q/q.js:1185:26)
    at Promise.promise.promiseDispatch (/home/USER_NAME/PROJECT_DIR/node_modules/q/q.js:808:41)
    at /home/USER_NAME/PROJECT_DIR/node_modules/q/q.js:1411:14
    at runSingle (/home/USER_NAME/PROJECT_DIR/node_modules/q/q.js:137:13)
    at flush (/home/USER_NAME/PROJECT_DIR/node_modules/q/q.js:125:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Steps to Reproduce:

Import YAML content containing {{}} into the markdown, and set "YAML" as lang. Then, convert this document using honkit such as npx honkit pdf

Expected Behavior: The content within {{}} should not have HTML markup applied, as it seems to interfere with the nunjucks rendering process.

Actual Behavior: HTML markup is applied to the content within {{}}, leading to rendering errors with nunjucks.

Possible Solution: A potential fix would be to adjust the import process to exclude the application of HTML markup to the content within {{}}. This should allow for successful rendering with nunjucks without encountering errors.

Thank you for looking into this issue. I believe addressing this could improve the experience.

azu commented 1 month ago

Thanks for report.

Is this is only occur in pdf? It would be helpful to have a repository to reproduce if possible.

Wrapping {{{content}}} of this plugin's template with {% raw %} may resolve this issue. https://github.com/azu/gitbook-plugin-include-codeblock/blob/master/templates/default-template.hbs https://honkit.netlify.app/templating/

suzuki-shm commented 1 month ago

Yes, the build to compile to HTML works fine. The issue occurs when compiling to PDF. I will consider creating a reproducible repository later to demonstrate the problem.

suzuki-shm commented 1 month ago

Hello @azu,

As requested, I have created a repository to demonstrate the issue with YAML content containing {{}} when converting to PDF. You can find the reproducible repository here:

https://github.com/suzuki-shm/gitbook-plugin-include-codeblock-issue80

Additionally, I have set up a GitHub Actions workflow in the repository to automatically reproduce the bug. This should make it easier to observe and investigate the issue.

During testing, I discovered that using the ace plugin together with the YAML content is necessary to reproduce the error. This combination seems to trigger the issue during the PDF conversion process.

Please let me know if you need any additional information or if there are any further steps I should take.

Thank you for your assistance in resolving this issue.

azu commented 1 month ago

ace template does not work on pdf. As as workaround, just use default template.

book.js (book config can be js file)

module.exports = {
    "root": "./docs",
    "language": "ja",
    "title": "Test document",
    "author": "Shinya Suzuki",
    "plugins": [
        "include-codeblock",
        "ace"
    ],
    "pluginsConfig": {
        "include-codeblock": process.env.PDF_BUILD ? {} : {
            "template": "ace"
        }
    }
}
PDF_BUILD=true npx honkit pdf
azu commented 1 month ago

https://github.com/azu/gitbook-plugin-include-codeblock/blob/master/templates/ace-template.hbs Probabaly, fix it by adding a condition like {% if output.name != "ebook" %}to ace template. I didn't see an immediate solution.

suzuki-shm commented 3 weeks ago

Thank you for your prompt response.

As a temporary measure, we will use the full template to visualize YAML content during PDF builds!

I appreciate your quick assistance.