Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions src/mkdocs_table_reader_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ def on_config(self, config, **kwargs):
f"[table-reader]: Incompatible plugin order: Define 'table-reader' before '{post_load_plugin}' in your mkdocs.yml."
)

# Plugins required after table-reader
for post_load_plugin in ["macros"]:
if post_load_plugin in plugins:
if plugins.index("table-reader") < plugins.index(post_load_plugin):
raise ConfigurationError(
f"[table-reader]: Incompatible plugin order: Define 'table-reader' after '{post_load_plugin}' in your mkdocs.yml."
)

# Compatibility with mkdocs-macros-plugin
self.external_jinja_engine = False
if "macros" in config.plugins:
self.external_jinja_engine = True

# Define extra macros and filters
self.macros = {
macro: MACROS[macro].set_config_context(
mkdocs_config=config, plugin_config=self.config
Expand All @@ -80,17 +77,28 @@ def on_config(self, config, **kwargs):
"add_indentation": add_indentation,
"convert_to_md_table": convert_to_md_table,
}
config.plugins["macros"].macros.update(self.macros)
config.plugins["macros"].variables["macros"].update(self.macros)
config.plugins["macros"].env.globals.update(self.macros)

config.plugins["macros"].filters.update(self.filters)
config.plugins["macros"].variables["filters"].update(self.filters)
config.plugins["macros"].env.filters.update(self.filters)
# Use the new registration system
if "register_macros" in dir(config.plugins["macros"]):
config.plugins["macros"].register_macros(items=self.macros)
config.plugins["macros"].register_filters(items=self.filters)

# Use the old registration 'system'
else:
# Ensure macros is defined _after_ table-reader plugin
for post_load_plugin in ["macros"]:
if post_load_plugin in plugins:
if plugins.index("table-reader") < plugins.index(post_load_plugin):
raise ConfigurationError(
f"[table-reader]: Incompatible plugin order: Define 'table-reader' after '{post_load_plugin}' in your mkdocs.yml."
)
config.plugins["macros"].macros.update(self.macros)
config.plugins["macros"].variables["macros"].update(self.macros)
config.plugins["macros"].env.globals.update(self.macros)
config.plugins["macros"].filters.update(self.filters)
config.plugins["macros"].variables["filters"].update(self.filters)
config.plugins["macros"].env.filters.update(self.filters)

self.external_jinja_engine = True
else:
self.external_jinja_engine = False

def on_pre_page(self, page, config, **kwargs):
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/jinja/mkdocs_table_before_macro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
site_name: test git_table_reader site
use_directory_urls: true

theme:
name: material

plugins:
- search
- table-reader
- macros

markdown_extensions:
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
Loading