Skip to main content

MkDocs JSFiddle Plugin

A plugin for MkDocs that lets you augment your code fences with an "Try it in JSFiddle" button.

Installation

This package can be installed via pip.

pip install mkjsfiddle

Then, add jsfiddle to the plugins section of your mkdocs.yml file.

plugins:
  - jsfiddle

Usage

Code fences will be left alone by default, as many code blocks may not form a coherent block for a user to edit. To opt in for a given code fence, add jsfiddle- to your fence language declaration, like so.

```jsfiddle-html
<!DOCTYPE html>
<!-- Some content here -->
```

The html above will be preserved for syntax highlighting, and the jsfiddle- will be dropped. Other languages are theoretically supported, but will have no impact besides code highlighting.

The default behavior is for a simple HTML parser to extract the inline JS and CSS elements and put their contents in the appropriate JSFiddle panels. More specifically, if you have a script tag with the attribute type=text/javascript AND not having the src attribute, or if you have a style tag with the attribute type=text/css, it will be extracted to the appropriate panel. If you have multiple of these, they will all be extracted and concatenated with some newlines thrown in as breaks.

If you prefer to opt out of this behavior and just dump everything as-is into the HTML box, you can add -htmlonly to the language string (for a full string that looks something like jsfiddle-html-htmlonly).

Known limitations

We attempt to keep formatting as-is, but make no guarantees in the default mode. The -htmlonly option however should preserve formatting (if it does not, please submit a bug report). This has been developed and tested with Material for MkDocs, and has not been tested extensively with additional styles. Pull requests to improve styling are welcome.

Metadata

Release files for mkjsfiddle 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkjsfiddle 1.0.1
File Size Uploaded
mkjsfiddle-1.0.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkjsfiddle 1.0.1
File Interpreter ABI Platform
mkjsfiddle-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / mkjsfiddle-1.0.1.tar.gz

Download URL mkjsfiddle-1.0.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
88563c248eeeeb367f46fe2605d3f80b6786bc41d27d2e3e640b76e5e270526b
BLAKE2b-256 checksum
How to use checksums
f1efbd43a2d9784ef36d2ea861462cd6a85a2b7e07be4c0f77a11e5dc9aea2b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / mkjsfiddle-1.0.1-py3-none-any.whl

Download URL mkjsfiddle-1.0.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbd8ce498f048bd23b50d475e337558cf2b9d03957d6b25fd1a2158998767c88
BLAKE2b-256 checksum
How to use checksums
197bf95fe4b07a134e678d02e2d3466ab8fdcf17da4be1bc596dad582c4f308a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page