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

Variable not rendered when using pymdown snippet extension #176

Closed
siryugo opened this issue Aug 28, 2023 · 4 comments
Closed

Variable not rendered when using pymdown snippet extension #176

siryugo opened this issue Aug 28, 2023 · 4 comments
Labels
info required Further information is requested useful tip A how-to, good to know

Comments

@siryugo
Copy link

siryugo commented Aug 28, 2023

Hi,

I'm currently using pymdown snippet extension to include an specific delimited part from one page into another using the section feature: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/#snippet-sections

Unfortunately, if the source page contains a variable, mkdocs-macro-plugin is not rendering it as expected. For example:

mkdocs.yml:

extra:
  internal-url: https://custom.url

source.md

<!-- --8<-- [start:func] -->
This is the internal url: {{ internal-url }}
<!-- --8<-- [end:func] -->

destination.md

The following text show the internal url:
--8<-- source.md:func

Expected result in destination page:

The following text show the internal url:
This is the internal url: https://custom.url

Current result in destination page:

The following text show the internal url:
This is the internal url: {{ internal-url }}

I tried using the include jinja2 function as suggested in other issues but it appears we can only "include" the full page (which makes sense). That's why I tried using pymdown snippet extension but facing this issue.

Is this something possible to solve using mkdocs-macros plugin?

Thanks!

@github-actions
Copy link

Welcome to this project and thank you!' first issue

@fralau
Copy link
Owner

fralau commented Aug 28, 2023

@siryugo I would say, certainly yes. The simplest way would be to use the standard {% include ... %} command of Jinja2. That is, if you want to include the whole file.

Do you really need to include only a section of the file? If yes, and you are willing to write a Python function e.g. extract_snippet(filename, section), to be inserted in a main.py file, that shouldn't be difficult.

Here are instructions on how to write a module.

@fralau fralau added useful tip A how-to, good to know info required Further information is requested labels Aug 28, 2023
@fralau
Copy link
Owner

fralau commented Sep 7, 2023

@siryugo What is the status of that issue, for you?

@siryugo
Copy link
Author

siryugo commented Sep 7, 2023

Hi @fralau, thanks for your help! We have finally found a workaround for our specific need for now. Anyway, I will work on your solution in the next weeks. We can close the issue.

Thanks again!

@siryugo siryugo closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info required Further information is requested useful tip A how-to, good to know
Projects
None yet
Development

No branches or pull requests

2 participants