Convert MkDocs Markdown code fences to interactive LiveCodes playgrounds, links, or buttons.
This package is intended to provide MkDocs and Material for MkDocs users with syntax similar to the existing JavaScript Markdown integrations for LiveCodes.
pip install mkdocs-livecodesEnable the plugin in mkdocs.yml:
plugins:
- search
- livecodes:
render: playgroundheight: 500pxparams:
console: opentheme: lightThen add livecodes to a fenced code block:
```js livecodes
console.log("Hello from LiveCodes");
``````jsx livecodes
exportdefaultfunctionApp() {
return<h1>Hello</h1>;
}
``````python livecodes render=button
print("Hello from Python")
``````ts livecodes render=link
console.log("Hello");
``````js livecodes render=meta
console.log("Hello");
```render=meta preserves the code block and appends a hidden element with data-livecodes-url.
plugins:
- livecodes:
render: playground # playground | button | link | metaauto: false # transform all fences unless livecodes=falseheight: 500pxclass_name: livecodes-frameapp_url: https://livecodes.iotext: Edit in LiveCodesparams:
console: opentheme: lightview: splitBoth Python-style and JavaScript-style names are accepted where useful:
class_nameandclassNameapp_urlandappUrl
Per-block parameters override global options:
```jsx livecodes render=button className=dark-btn console=open theme=dark
exportdefault () =><h1>Hello</h1>;
```Use lang to override the code fence language sent to LiveCodes:
```py livecodes lang=python
print("Hello")
```When auto: true, opt out per block with:
```js livecodes=false
console.log("do not transform this block");
```Example configuration:
theme:
name: materialplugins:
- search
- livecodes:
render: buttonparams:
console: openmarkdown_extensions:
- pymdownx.highlight
- pymdownx.superfencesFor render: button, render: link, and render: meta, the original code block is preserved, so syntax highlighting extensions can still process it.
pip install -e .[test]
pytestThe plugin transforms Markdown in MkDocs' on_page_markdown phase, before Markdown is rendered to HTML. It intentionally preserves non-LiveCodes fences exactly.