rosscdh / mkdocs-markdownextradata-plugin

A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template
MIT License
83 stars 18 forks source link

Variables don't get resolved in Snippets #45

Open Stwissel opened 1 year ago

Stwissel commented 1 year ago

I'm using your nice plugin together with the pymdownx.snippets plugin

I have

extra:
  test: 1.0.0
plugins:
  - search
  - awesome-pages
  - section-index
  - tags
  - markdownextradata: {}

and a test.md

# Test of extras

This is top: {{test}}

--8<-- "snippet.md"

End

and a snippet.md

In the snippet: {{test}}

Expected outcome

<h1>Test of extras</h1>

This is top: 1.0.0
In the snippet: 1.0.0

End

Actual outcome

<h1>Test of extras</h1>

This is top: 1.0.0
In the snippet: {{test}}

End

What do I miss?

rosscdh commented 1 year ago

Hey there thanks for your interest.

Off the top of my head try

Becomes

Hope that helps. Been a while since ive worked on this app!

On Fri, 17 Feb 2023 at 22:04, Stephan H. Wissel @.***> wrote:

I'm using your nice plugin together with the pymdownx.snippets plugin I have

extra: test: 1.0.0plugins:

  • search
  • awesome-pages
  • section-index
  • tags
  • markdownextradata: {}

and a test.md

Test of extras

This is top: {{test}}

--8<-- "snippet.md"

End

and a snippet.md

In the snippet: {{test}}

Expected outcome

Test of extras

This is top: 1.0.0 In the snippet: 1.0.0

End

Actual outcome

Test of extras

This is top: 1.0.0 In the snippet: {{test}}

End

What do I miss?

— Reply to this email directly, view it on GitHub https://github.com/rosscdh/mkdocs-markdownextradata-plugin/issues/45, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADA6MXCT6JXMNTLMKH2HXDWX5LNNANCNFSM6AAAAAAU7JLO3I . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Stwissel commented 1 year ago

Tried that too. I suspect it might be the sequence of plugins. Mkdocs is particular about it. I'll experiment and report back

Stwissel commented 1 year ago

Played with various combinations of plugin and markdown extension sequences to no success. I also renamed in one attempt the snippet directory to .snippet so it would be first in the directory list.

Interesting observation: when I load snippet.md directly from the URL, it works as expected and variables are resolved. Looks to me like a lifecycle issue where the snippet plugin ignores the markdownextradata.

rosscdh commented 1 year ago

Thanks for the feedback.

Would you kind sending your yaml and I’ll try replicate and fix when I get a second?

Best

On Sat, 18 Feb 2023 at 16:41, Stephan H. Wissel @.***> wrote:

Played with various combinations of plugin and markdown extension sequences to no success. I also renamed in one attempt the snippet directory to .snippet so it would be first in the directory list.

Interesting observation: when I load snippet.md directly from the URL, it works as expected and variables are resolved. Looks to me like a lifecycle issue where the snippet plugin ignores the markdownextradata.

— Reply to this email directly, view it on GitHub https://github.com/rosscdh/mkdocs-markdownextradata-plugin/issues/45#issuecomment-1435491366, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADA6MTSSHMLI67SXDBMBS3WYBOJTANCNFSM6AAAAAAU7JLO3I . You are receiving this because you commented.Message ID: @.***>

Stwissel commented 1 year ago

Here you go:

#Project Information
site_name: MKDocs Test
site_url: https://github.com/
site_description: >-
  A test
use_directory_urls: false
# Theme Configuration
theme:
  name: material
  language: en
  features:
    - navigation.tabs
    - navigation.indexes
    - navigation.top
    - navigation.instant
    - search.highlight
    - search.share
    - search.suggest
  #custom_dir: theme_overrides/
  icon:
    repo: fontawesome/brands/github
  font:
    text: Roboto
    code: Roboto Mono
  favicon: favicon.ico

  # Static files
  static_templates:
    - 404.html

# Markdown Extensions
markdown_extensions:
  - admonition
  - pymdownx.details
  - pymdownx.superfences
  - attr_list
  - pymdownx.tabbed:
      alternate_style: true
  - pymdownx.emoji:
      emoji_index: !!python/name:materialx.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg
  - pymdownx.snippets:
      base_path:
        - "docs/snippets"

extra:
  test: 1.0.0

plugins:
  - markdownextradata
  - search
  - awesome-pages
  - section-index
  - tags