fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
318 stars 50 forks source link

Variable not rendered when using pymdown snippet extension #176

Closed siryugo closed 11 months ago

siryugo commented 12 months ago

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[bot] commented 12 months ago

Welcome to this project and thank you!' first issue

fralau commented 12 months ago

@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 commented 11 months ago

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

siryugo commented 11 months ago

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!