gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.22k stars 7.55k forks source link

Allow to parse and evaluate shortcodes *after* markup is rendered #8784

Open jirutka opened 3 years ago

jirutka commented 3 years ago

I’m thinking how to improve support for AsciiDoc syntax, specifically how to allow using standard Asciidoctor macros for cross-document references, code blocks with syntax highlighting provided by Hugo etc. I think that the most feasible way is to write a custom Asciidoctor HTML template (btw, I’m author of asciidoctor-html5s) that will render Hugo shortcodes instead of HTML markup for certain syntax elements (such as xref, listing etc.).

The problem is that this would require parsing, evaluating a substituting shortcodes after rendering the markup. I think that it might be possible once #7297 is implemented. However, this function has been requested multiple times in past years and it’s still not implemented, so it’s probably too complicated.

Maybe there’s some easier way how to achieve what I need? I’d appreciate even some hints how to quickly hack it in the code base (I’ve already looked into it, but I’m a bit lost), so I can start using it (I’m currently considering Hugo and this is a deal breaker).

bep commented 3 years ago

I'm pretty sure we support that already, that is the difference between {{< and {{%.

jirutka commented 3 years ago

Either I’m doing something wrong or it doesn’t work like that.

I have the following document:

= Title

See *document* xref:intro.adoc[].

I modified Asciidoctor backend to render xref macro as {{% relref "<path>" %}}, so Hugo gets the following HTML from asciidoctor:

See <strong>document</strong> {{% relref "intro.adoc" %}}.

And writes it as-is into output; it doesn’t process the relref shortcode. The same happens when I use {{< instead of {{%.

bep commented 3 years ago

OK, we talk about different things. Yes, what you ask for is not possible.

jirutka commented 3 years ago

Okay, do you know about any other (even hackish) way how to achieve what I’m asking for?