Skip to content

Commit

Permalink
fix for fralau#215: Do not explicitly assign page.title
Browse files Browse the repository at this point in the history
- allow macros in meta variables
- allow automatic parsing of title by mkdocs as explicitly  assigning page.title will override that.
  • Loading branch information
AnvithLobo committed Mar 4, 2024
1 parent 814205a commit 2c5c885
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mkdocs_macros/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ def render(self, markdown: str, force_rendering:bool=False):
# expand the template
on_error_fail = self.config['on_error_fail']
try:

# If title meta variable is present,
# render the jinja2 template and update the title
if meta_variables and meta_variables.get('title'):
self.variables["page"].meta["title"] = self.env.from_string(
meta_variables["title"]
).render(**page_variables)

md_template = self.env.from_string(markdown)
# Execute the jinja2 template and return
return md_template.render(**page_variables)
Expand Down Expand Up @@ -784,15 +792,6 @@ def on_page_markdown(self, markdown, page, config,
markdown=self.markdown,
force_rendering=force_rendering
)
# Convert macros in the title from render (if exists)
# to answer 144
# There is a bizarre issue #215 where setting the title
# prevents interpretation of icons with pymdownx.emoji
debug("Page title:",page.title)
if "{" in page.title:
page.title = self.render(markdown=page.title,
force_rendering=force_rendering)
debug("Page title after macro rendering:",page.title)

# execute the post-macro functions in the various modules
for func in self.post_macro_functions:
Expand Down

0 comments on commit 2c5c885

Please sign in to comment.