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
335 stars 51 forks source link

Modifying global variables #127

Closed maxhenze closed 2 years ago

maxhenze commented 2 years ago

Hey. Wanted to use this plugin for consecutive numbering of images across markdown pages.

I defined a counter variable in my extra section in my mkdocs.yml and assigned 0 to it. I then created a function increment:

    def increment():
        env.variables.counter += 1
        return env.variables.counter

It works correctly on the first page I used this macro on, but on the second page it repeated the increments from the first page and then added the increments from the second page on top.

Any ideas what could be the problem, or what i should do instead ?

Something else i tried was assigning local variables in every markdown file and importing it in the following, so I could keep incrementing on top of it. It worked well for the first import but on the second import I recieved an error:

RecursionError: maximum recursion depth exceeded while calling a Python object

Hopefully my explanations make sense and leave a hint what I could do to improve it :)

github-actions[bot] commented 2 years ago

Welcome to this project and thank you!' first issue