-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register extension from plugin #1942
Comments
You could use the on_config event to add one or more global extensions to the However, if you need to pass page specific data to your extensions, it gets more complicated. The problem stems from the fact that Python-Markdown does not anticipate page specific information being passed to extensions. Sure it is doable as demonstrated by our private extension which handles relative internal links. Note that we recreate a new instance of that extensions and add it to a copy of the global list of extensions separately for each page: mkdocs/mkdocs/structure/pages.py Lines 170 to 184 in c9032bd
For a page specific extension in a plugin. what I might consider doing is using the on_page_content event. In my event function, I would ignore (discard) the You also seem to have some questions regarding the internal working of Python-Markdown and its extension API. That would be something to take upstream to Python-Markdown/markdown. MkDocs simply uses the library as it is provided. |
Hmmm, thank you for your answer, it helps a lot. I think The trick using the I'll play with that tomorrow, thank you very much @waylan ! |
I see what you mean now. I thought the extensions would be instantiated and available through the config object, just like the plugins objects, but they are not. The config object only contains the list of extensions as strings, not Python objects. So there's no way to instantiate my extension with a reference to self and add it to the config extensions 馃槩 Next try is the HTML discarding trick. Maybe I'll also open a new issue/feature request to ask for exposing the instantiated markdown extensions through the config object, just like plugins. |
You can pass an extension instance to Markdown. From the I am certainly open to suggestions for how to address this. However, the current system is built with the YAML config file in mind, which expects only strings. So any solution needs to keep that working consistently. |
Ah, indeed, I was able to append the instantiated extension to Thank you again @waylan! |
Hi! Thanks for mkdocs, I love it 馃檪
I am building a plugin to support API documentation generation: mkdocstrings (inspired by mkautodoc and mkdocs-autoreflinks-plugin).
My code is currently very ugly because I'm parsing markdown lines like
::: text
manually, in Python, with a for loop on lines (so without any markdown processor), then converting Python docstrings to markdown inon_page_markdown
(using lots of markdown extensions features), and then finally tweaking the HTML (to add divs) inon_page_content
.Since I'm using other markdown extensions features in the markdown I generate, the end user needs to add all these extensions in
mkdocs.yml
.It could be much, much cleaner to implement it with a single markdown extension (with a few dependencies to other extensions like
pymdownx.inlinehilite
), as the end-user would only need to set this extension inmkdocs.yml
.The thing is, the extension would still need to have access to some context of mkdocs, particularly the pages, in order to support objects references in Python docstrings, like Sphinx's rst+autodoc
:class:
or:meth:
functionality.For this, I need a way to pass data from the plugin to the extension. Is this possible? A maybe very similar question, but formulated differently, is: is it possible to register a markdown extension from a plugin (without having to add the extension to
mkdocs.yml
)? Or: do we have access to markdown extensions from a plugin, and can we modify them?I'm planning to inspect contents of the plugin at runtime when I get some free time, but maybe you'll have some hints for me 馃檪
The text was updated successfully, but these errors were encountered: