Open flynneva opened 2 years ago
@h3ndrk I figured it out, was just missing a comment in the markdown like this:
<!-- interactive-widgets -->
And also had to adjust the plugins.py
logic a bit to loop over all the comments in the file:
comments = soup.find_all(string=lambda text: isinstance(text, bs4.Comment))
for comment in comments:
if comment.strip() == 'interactive-widgets':
current_head = comment
assert current_head is not None
I'll make a PR in a bit with the fix
I saw your comments and will reply in more detail later. For the moment, here is an example project that uses the widgets already: https://github.com/HULKs/recruiting-website Maybe you find some answers while looking into the code. This project is also deployed, if you want to see it in action: https://recruiting.hulks.de
@h3ndrk no rush, thanks for replying! I'll check out the example tomorrow and should be able to figure it out from there.
Thanks again for your amazing work here 👏
Sorry for answering that late. Commit d419dc232b53b575aad2a70502db2ee0565c8896 should fix your issue and also #2. Before this commit the MkDocs plugin requires a comment <!-- interactive-widgets -->
somewhere in the <head>
of the rendered page. It uses this comment to inject some scripts and other resources that need to be available for the widgets to work in the browser. Since I always used a custom MkDocs theme which has the comment in the theme HTML (see here), I didn't notice that this required comment is missing in e.g. the default theme. The pushed commit allows to omit the comment in the <head>
and if it is missing it will just append the scripts to the bottom of the <head>
.
The added comment in the Markdown that you tried does not work because the scripts need to be added to the <head>
but all Markdown content will be part of the <body>
. This will indeed result in #2 because the necessary resources are missing then and we have some undefined references.
Feel free to close this issue and #2 if you think they are resolved. If you have questions, I'm happy to answer them.
Here is my test setup, if you want to have a minimal reproducible example that worked for me:
docs/index.md
:
# Test
Hello World!
<x-button command="date" image="ubuntu:latest" label="Print date" working-directory="/data" />
mkdocs.yml
:
site_name: Test
plugins:
- interactive_widgets
Also required:
docker pull ubuntu:latest
(images that are used in widgets need to be present)interactive-widgets-backend
and docker compose build
pip install git+https://github.com/h3ndrk/interactive-widgets-mkdocs.git
mkdocs build && cd site && docker compose up --build
Hi @h3ndrk!
First off - amazing stuff! This project seems to be exactly what I was looking for when trying to add some "interact-ability" to my mkdocs project.
I made it pretty far and was able to install everything (along with the backend) just fine and was even able to build my mkdocs project after adding the plugin to the mkdocs.yml config (tricky bit was guessing the right plugin name
interactive_widgets
:wink:)The error I am seeing is when I try to add simple button (like in the README) that prints the date I am seeing an error.
Here is the button I added to a
.md
package:And when I try and run
mkdocs build
after adding that page to my project I get:Any ideas on what might be causing the error?