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: playground
height: 500px
params:
console: open
theme: lightThen add livecodes to a fenced code block:
```js livecodes
console.log("Hello from LiveCodes");
``````jsx livecodes
export default function App() {
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 | meta
auto: false # transform all fences unless livecodes=false
height: 500px
class_name: livecodes-frame
app_url: https://livecodes.io
text: Edit in LiveCodes
params:
console: open
theme: light
view: 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
export default () => <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: material
plugins:
- search
- livecodes:
render: button
params:
console: open
markdown_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.