pawamoy / markdown-exec

Utilities to execute code blocks in Markdown files.
https://pawamoy.github.io/markdown-exec
ISC License
103 stars 8 forks source link

Feature request: default behaviour for code blocs #24

Closed andynameistaken closed 3 months ago

andynameistaken commented 1 year ago

I'm using Code Emiter plugin for Obsidian which allows me to run code from code blocks, when I'm writing notes which I later publish to mkdocs with material theme. Could you provide option for default behaviour for codeblocks?

Example:

Block with exec=on doesn't allow Code emitter to run

```python exec="on"
print("Hello Markdown!")

Maybe some config in `mkdocs.yml`  allowing to execute regular codeblock might be good idea?
It would be nice, because:
- documets will be more portable
- person can focus more on what to write and not how to do it (most important thing I think)
pawamoy commented 1 year ago

Hello, thanks for the feature request!

I initially didn't want to implement such a feature, but it could be very easy with an environment variable, so why not.

Basically something like

EXEC_AUTO = [lang.strip() for lang in os.getenv("MARKDOWN_EXEC_AUTO", "").split(",")]

# and in our validator
exec_value = (language in EXEC_AUTO) | _to_bool(inputs.pop("exec", "no"))

Happy to review a PR with these changes, otherwise I'll try to get to it soon :slightly_smiling_face:

andynameistaken commented 9 months ago

Could you put it inside when you have time? I never did PR in my life and I don't know how to do it (yet).