-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Allow to pass Asciidoctor converter templates #12314
Comments
AsciiDoc's converter templates are the equivalent of Hugo's Markdown render hooks. Maybe a fixed location such as:
Or maybe all in one directory:
I'm not sure if the AsciiDoc has a large number of convertible contexts, so this seems like it would be a very powerful feature for AsciiDoc users. However, those who have contributed things like this in the past have not stuck around to maintain them. Which means existing maintainers (essentially one person) have a steep learning curve every time they have to (or need to) touch this stuff. And for a content format that's used by << 1% of sites in the wild, that's not a great investment. |
Thanks for your answer @jmooring! I really like your idea of treating converter templates as render hooks and I don’t have a strong opinion on whether they should be put together in the same folder or not. Maybe there’s a risk of conflict and the best would be to have something like this?
However this is a breaking change. Regarding your objection on AsciiDoc oriented features, I mostly agree with you. On the other hand, this feature would “just” be a matter of passing an extra argument ( |
https://docs.asciidoctor.org/asciidoctor/latest/convert/templates/#apply-your-templates
ConfigurationWe would need a way to set:
Although I would like to limit Limit the GemsTo support the template engines above you must install these gems: Miscellaneous
Example configuration
Test site
Then visit Footnotes |
@yann-soubeyrand Comments regarding the above? |
Wow, thanks a lot for all the work done so far! I planned to have a look this weekend at the questions you had, I haven’t seen that you already answered most of them! The first remark that comes to my mind is that there are several implementations of Asciidoctor other than the Ruby one, for example Asciidoctor.js, which a lot easier to work with in my opinion (just Second, it’s more a question on the feasibility than a remark, because I’m not aware enough of the inner working of Hugo: could we imagine building a temporary union folder for the templates (in a temporary directory)? This could of course be done in a second time. Other than that, it seems pretty appealing to me! |
If we pursue this, we should focus on the most common implementation (gem) first. If it works with Node.js, great. If it doesn't, that's a separate proposal.
I don't see that happening. We would need to do this every time we build (and maybe rebuild) the site, probably stuffing them somewhere in the cache directory. Keep it simple.
One of my concerns about this proposal is the potential for arbitrary code execution. I have no idea which, if any, of the available template engines provide this capability. For all I know, you might be able to do that with |
Regarding arbitrary code execution... Testing an
Testing a
Testing a
All three deleted the file. This is scary, and makes this proposal DOA unless there's a template engine that prevents code execution. |
Closing based on the thread above. This is insecure. |
From the doc:
Maybe Handlebars could be a candidate, right? |
OK, I can make
Unfortunately,
I don't know enough about |
Isn’t it that you need something like this in your Hugo config?
|
Regarding union filesystem, couldn’t we pass several template dirs, that is, the theme templates first, then the user supplied templates? From Asciidoctor documentation and a basic test I did, this should work as intended: https://docs.asciidoctor.org/asciidoctor/latest/convert/templates/#use-multiple-template-directories. |
Yes, this stops tilt from trying to "lazy load" the template engine:
Yes, we could change
Asciidoctor uses a right-to-left order of precedence (last one wins) , which is opposite to other Hugo options (e.g., when using multiple themes). We will need to reverse the order when reading the array, so that the first one wins. The above would allow you to use a directory in a theme, falling back to a directory in the root of your project, but both paths must be relative to the project root:
Note that the directories above are outside of the layouts directory. You cannot place handlebars templates anywhere within the layouts directory. Handlebars templates use the same If the converter templates are provided by a module, you will need to vendor the the module (
The above will use the project root first, falling back to the theme, falling back to the module. Note that The remaining question is: are we certain that the handlebars template engine doesn't allow arbitrary code execution? |
Sadly, no… Asciidoctor supports a helper file (https://docs.asciidoctor.org/asciidoctor.js/latest/extend/converter/template-converter/#helpers-js-file) and I just tested that I can read a file anywhere in my home directory… We’d need to check that no template directory contains a |
We could (potentially) disable the converter templates feature when running Asciidoctor via Node. We know already it won't work with the snap package, so this is just another exception.
We could check for the existence of a helper.js file in each directory, and skip those that contain one, but this is pretty weak (e.g., the Asciidoctor team might decide to allow "other_helpers.js" too). As you pointed out here, I think we'd need an Asciidoctor CLI flag to disable this capability, and then we would have to do version checking to make sure the flag actually does something, etc. EDIT: We already have to avoid adding empty template-dirs (meaning we have to read each directory anyway), so we can just reject any directory that contains files with extensions other than |
Converter templates are the AsciiDoc equivalent of Markdown render hooks: https://docs.asciidoctor.org/asciidoctor/latest/convert/templates/ Requires the following gems: concurrent-ruby, tilt, and tilt-handlebars. Handlebars is the only allowed template engine, and all files must have the .handlebars file extension. Handlebars templates may not be placed within the layouts directory. Supports multiple converter template directories, with left-to-right precedence. The path to each converter template directory must be relative to the project directory. Hugo will intentionally skip converter template directories that contain files with extensions other than .handlebars. For example, Hugo will skip directories that contain a helpers.js file. Example configuration: [markup.asciidocExt] extensions = ['tilt-handlebars'] templateDirectories = ['adoc-templates/a','adoc-templates/b'] templateEngine = 'handlebars' Hugo's snap package does not support AsciiDoc converter templates. Closes gohugoio#12314
@yann-soubeyrand If you can build from source, please test #12318. Example site:
|
@jmooring good job, it works as expected! Regarding the two challenges to handle union file system:
|
If you want this proposal and draft PR to have a chance of being accepted by the project lead, the changes must be isolated to the markup/asciidocext package. Keep it simple and be happy if either or both are accepted.
Sure, but the path will vary by OS, user, environment variables, etc., and the path will typically be external to the project directory (we don't want that). With a shared project, the only stable module path is
I want you to break it, find holes, etc. |
You can add add ignore/include regexps to the layouts mount(s): https://gohugo.io/hugo-modules/configuration/#module-configuration-mounts |
Regarding asciidoctor/asciidoctor.js#1727, an asciidoctor CLI flag would be useful only in conjunction with version checking (i.e., that flag will have no effect with current and previous versions). With #12318 we reject a directory if it contains anything other than ".handlebars" files. |
@yann-soubeyrand What's your current opinion on this proposal? Do the restrictions (e.g., handlebars only, no access to virtual file system) limit its usefulness to the degree that we should not pursue this? |
Hello @jmooring, sorry for the late reply… My opinion is that the restriction on handlebars only is not a problem (after all, better a single template engine than none), but the lack of access to the virtual filesystem limit the usefulness. To elaborate, my initial use case was to enhance AsciiDoc support with Docsy theme: I wanted to adapt how AsciiDoc blocks (like code blocks, admonitions, etc) were rendered so that the theme CSS doesn’t have to be modified. However, my goal for these AsciiDoc converter templates was that they be shareable in a Docsy derived theme or even upstreamed. If it’s not possible, I’ll end up modifying the theme CSS (which can be distributed in a derived theme and/or upstreamed). |
It's not possible out-of-the-box as discussed in previous comments in this issue. Given that limitation, I'm inclined to close this proposal. I've pinged a few other AsciiDoctor site authors, and the response has been tepid. Also, I'm not 100% convinced that we've eliminated the possibility of arbitrary code execution. |
Yes, I think we can close this for the moment. Thanks a lot for the PoC! |
I share the same opinion. Better one engine than none.
I'm also on the same page here. It's essentially the same issue is with respect to
The approach with converter templates was imho the right one. But as you mentioned Hugo's limitations are too restrictive for this. Providing additional CSS is ways simpler than vendoring a theme module and using the assets folder where it indeed is more a layout render hook. Furthermore these required arbitrary code execution prevention mechanisms ( |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Asciidoctor allows to customize its output by passing it so called converter templates. It is done by passing it as argument the path to a folder containing these templates.
I’d need this feature to customize the rendering of AsciiDoc admonitions so that they better integrate in the theme I’m using.
I’m wondering if this is something you would be accepting a PR for? If so, how do you see this implemented:
What do you think?
The text was updated successfully, but these errors were encountered: