Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit a2f95f3

Browse files
committed
mkdocs: add mkdocs-macros-plugin
Add the macros plugin which enables using jinja2 in markdown source files and provides hooks to inject variables, macros, and filters into the jinja2 rendering context. This plugin is injected into the mkdocs plugin list before mdpo which means that mdpo sees the output of macros when collecting translation units from the English source. This will allow us to use macros to generate translation units, but comes with a side effect that some output may break mdpo. A really easy example of this is that adding a `{{ macros_info() }}` block produces output which causes mdpo's initialization code to fall into a recursion loop which eventually crashes mkdocs.
1 parent 390291f commit a2f95f3

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

macros/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2021 Wikimedia Foundation and contributors.
2+
# All Rights Reserved.
3+
#
4+
# This file is part of Wikimedia Developer Portal.
5+
#
6+
# Wikimedia Developer Portal is free software: you can redistribute it and/or
7+
# modify it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or (at your
9+
# option) any later version.
10+
#
11+
# Wikimedia Developer Portal is distributed in the hope that it will be
12+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14+
# Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License along with
17+
# Wikimedia Developer Portal. If not, see <http://www.gnu.org/licenses/>.
18+
19+
def define_env(env):
20+
"""Setup local variables, macros, and filters for mkdocs-macros-plugin."""
21+
22+
@env.macro
23+
def say_hello(s):
24+
return "Hello {}".format(s)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ markdown_extensions:
5757
plugins:
5858
- search:
5959
lang: en
60+
- macros
6061
- mdpo:
6162
locale_dir: locale
6263
lc_messages: true

poetry.lock

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ python = "^3.7"
1212
mkdocs = "^1.2.3"
1313
mkdocs-mdpo-plugin = "^0.0.16"
1414
mkdocs-material = "^7.3.4"
15+
mkdocs-macros-plugin = "^0.6.0"
1516

1617
[tool.poetry.dev-dependencies]
1718

0 commit comments

Comments
 (0)