getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 445 forks source link

Shortcodes in included rst files are not rendered #3648

Open orencio opened 1 year ago

orencio commented 1 year ago

Environment.

$ python -V
Python 3.10.8

$ pip freeze | grep Nikola
Nikola==8.2.3

$ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo

$ uname -a
Linux p 6.0.11-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 02 Dec 2022 17:25:31 +0000 x86_64 GNU/Linux

Description.

Trying to include other rst file doesn't reder shorcodes:

$ grep -E 'include|example' pages/index.rst 
.. include:: ./includes/definiciones.rst
Esto es otra cosa: |example|

$ cat includes/definiciones.rst
.. |example| replace::
   {{% raw %}} <span class="logo"/> {{% /raw %}}

This doesn't render raw shortcode, only include the text as it is: {{% raw %}} <span class="logo"/> {{% /raw %}}.

I think the problem is that Nikola only render shortcodes of the main rst file and not of the included files.

Although include directive (https://docutils.sourceforge.io/docs/ref/rst/directives.html#including-an-external-document-fragment) permits specify parser parameter. If this parser may be Nikola Parser, the problem should be resolved. Something like this:

.. include::  ./includes/definiciones.rst
   :parser: nikolaParser

Is there anyway of render includes files?

Regards.

orencio commented 1 year ago

This is related to #3206.

It says:

Basically, this is how it works now:

  1. Get the post source
  2. Replace the shortcodes with placeholders
  3. Process with docutils or whatever compiler
  4. Replace the placeholders with the HTML generated by the shortcodes

Perhaps the process should be:

Is this correct?

Kwpolska commented 1 year ago

The replacement-with-placeholders step must happen before compilation, because a compiler might mess up the contents of your shortcodes (eg. replace foo_bar_baz with foo<em>bar</em>baz).

What could be done in this specific case is this: when processing include reST directives, the included source code should undergo the placeholder replacement, and the generated placeholders/shortcodes should be added to the main post’s replacement list (as if they were in the main post).

This would require:

If anyone wants to have a go at implementing this, we'll be happy to accept a pull request.

Kwpolska commented 1 year ago

(Closed by mistake.)

orencio commented 1 year ago

I would like this behavior.