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

Shortcodes in included rst files are not rendered #3648

Open
orencio opened this issue Dec 10, 2022 · 4 comments
Open

Shortcodes in included rst files are not rendered #3648

orencio opened this issue Dec 10, 2022 · 4 comments

Comments

@orencio
Copy link

orencio commented Dec 10, 2022

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 orencio added the bug label Dec 10, 2022
@orencio
Copy link
Author

orencio commented Dec 10, 2022

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:

  • 1 → 3 → 2 → 4.
  • Or if itsn't, 1 → 2 → 3 (recursively for others includes in the includes?) → 2 (again) → 4.

Is this correct?

@Kwpolska Kwpolska changed the title Included rst files are not correctly rendered. Shortcodes in included rst files are not rendered Dec 10, 2022
@Kwpolska
Copy link
Member

Kwpolska commented Dec 10, 2022

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:

  • copying the Include directive from docutils into Nikola's source code, and adding some code to replace shortcodes and place the new replacements list in some state area accessible
  • extracting the new replacements list from the state in the reST compiler and adding it into the shortcodes dict

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

@Kwpolska
Copy link
Member

(Closed by mistake.)

@Kwpolska Kwpolska reopened this Dec 10, 2022
@orencio
Copy link
Author

orencio commented Dec 10, 2022

I would like this behavior.

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

No branches or pull requests

2 participants