Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content inside raw/verbatim block is still processed by PostHTML #25

Closed
gterras opened this issue Aug 9, 2019 · 4 comments · Fixed by #26
Closed

Content inside raw/verbatim block is still processed by PostHTML #25

gterras opened this issue Aug 9, 2019 · 4 comments · Fixed by #26
Assignees

Comments

@gterras
Copy link

gterras commented Aug 9, 2019

Hi,

I noticed HTML content between raw blocks are still processed by PostHTML. So this :

{% raw %}
<img src="{{ data.image }}" >
{% endraw %}

will trigger a build error {{ data.image }}: ENOENT: no such file or directory

I don't know if this issue is out of scope (as writing an html string directly inside Nunjucks tags would work), do you consider this expected behavior ?

Thank you

@chocolateboy chocolateboy self-assigned this Aug 9, 2019
@chocolateboy
Copy link
Owner

Yes, it's the expected behavior (in Parcel) for HTML assets to be processed by PostHTML. It doesn't appear to provide a way to disable this.

However, it makes sense to allow further processing to be disabled in parcel-plugin-nunjucks, which could be done by using an njk asset-type, either via the filename, e.g. index.njk.njk, or via the assetType option, e.g.:

$ cat index.txt.njk
<html>
    <body>
        <h1>Hello, {{ name }}!</h1>

        {% raw %}
            <img src="{{ data.image }}" />
        {% endraw %}

        <a href="./foo.html">Foo</a>
    </body>
</html>
$ cat nunjucks.config.js
module.exports = {
    data: { name: 'world' },
    assetType (path) {
        return path.baseExt === '.txt'
            ? 'njk'  // stop after nunjucks processing (plain text)
            : false  // default asset-type i.e. determined by filename
    }
}
$ cat dist/index.txt.njk
<html>
    <body>
        <h1>Hello, world!</h1>
        <img src="{{ data.image }}" />
        <a href="./foo.html">Foo</a>
    </body>
</html>

Note: if you only want to protect a specific section from processing by PostHTML, you'll need to use whatever the equivalent of the raw/verbatim tag is in PostHTML, or request it (probably here).

chocolateboy added a commit that referenced this issue Aug 10, 2019
+ load Parcel files from src/ (Parcel on Node.js >= 8) rather than lib/
(Parcel on Node.js < 8), as per our minimum-supported node version
chocolateboy added a commit that referenced this issue Aug 10, 2019
+ load Parcel files from src/ (Parcel on Node.js >= 8) rather than lib/
(Parcel on Node.js < 8), as per our minimum-supported node version
chocolateboy added a commit that referenced this issue Aug 10, 2019
Allow the `assetType` option to be supplied as an object with a `raw`
property (default: false). If set to true, the specified type is used as
the file's extension and processing stops after the nunjucks template
processing.

+ load Parcel files from src/ (Parcel on Node.js >= 8) rather than lib/
(Parcel on Node.js < 8), as per our minimum-supported node version
chocolateboy added a commit that referenced this issue Aug 10, 2019
Allow the `assetType` option to be supplied as an object with a `raw`
property (default: false). If set to true, the specified type is used as
the file's extension and processing stops after the nunjucks template
processing.

+ load Parcel files from src/ (Parcel on Node.js >= 8) rather than lib/
(Parcel on Node.js < 8), as per our minimum-supported node version
@gterras
Copy link
Author

gterras commented Aug 10, 2019

Hi,

thanks for your response. Indeed this is more a parcel/postml issue. Apparently parcel2 will provide some ways to do so. I will try to write a plugin for this.

By the way it seems that your example triggers a cannot resolves entry "/my/path/index.txt.njk" from "/my/path" . Changing the "root" option does not seem to change this behavior.

@chocolateboy
Copy link
Owner

chocolateboy commented Aug 10, 2019

The example is not what was implemented. See the PR and the documentation for the final implementation.

@gterras
Copy link
Author

gterras commented Aug 12, 2019

Yes I've seen that afterwards, thanks for doing this.

FYI I've opened a Parcel issue for my specific case (src attributes easier control) here : parcel-bundler/parcel#3348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants