Skip to content

JeffersGlass/mkdocs-pyscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Nov 3, 2023
abc580c · Nov 3, 2023
Nov 2, 2023
Nov 2, 2023
Nov 2, 2023
Oct 26, 2023
Oct 10, 2023
Oct 10, 2023
Nov 3, 2023
Nov 2, 2023
Nov 2, 2023
Oct 10, 2023
Oct 10, 2023
Nov 3, 2023
Nov 2, 2023
Nov 2, 2023
Oct 11, 2023
Nov 2, 2023
Nov 2, 2023

Repository files navigation

mkdocs-pyscript

mkdocs-pyscript is a plugin for mkdocs that allows you to transform code blocks into executable Python scripts that run in the user's browser, with no backend server, using PyScript.

Installation

Install the plugin into your environment using pip, or your favorite environment manager that ues PYPI:

pip3 install mkdocs-pyscript

Enable the plugin by adding it to mkdocs.yaml:

plugins:
    - mkdocs-pyscript

Usage

With this plugin enabled, all Python fenced code blocks (type py or python or any other label that maps to lang-python) will have an added LOAD button in the lower-right corrner. When clicked, the code block will be transformed into an editable code snippet (using codemirror). When the user clicks on the green "run" arrow in the lower right corner, or pressed SHIFT+ENTER when focused, will run the inner Python code using PyScript.

The included code is run in a Web Worker, so as not to block the main thread. Each snippet is run in a separate web worker; variables, objects, and names are not shared between executions of the same cell.

pre and post code

Some demo code snippets may require setup and/or teardown code to properly function, which don't necessarily need to be displayed to the user. To run a chunk of Python code before any code the user runs in a particular code editor, add the .py-pre class to a fenced code block immediately before the user-visible code block, using the style of the attr_list markdown plugin. To run a chunk of code after a user runs a particular code editor add the .py-post class to a fenced code block immediately after the user-visible code block:

```{.py .py-pre}
print("This is some pre-code")
```

```py
print("This is the main tag")
# Only this code will be displayed in the code editor
```

```{.py .py-post}
print("This is some post code")
```

Configuration

mkdocs-pyscript supports options that can be set in mkdocs.yaml to control the behavior of the plugin

pyscript_version

The pyscript_version property of the plugin controls the version of PyScript that is loaded. If not specified, the current default version is snapshots/2023.09.1.RC2.

To support both pre-release snapshots and released versions of PyScript, the provided value is inserted into the following string:

SCRIPT = f'https://pyscript.net/{pyscript_version}/core.js'

That is, to load a specific release or snapshot, use:

#Load a release
plugins:
    - mkdocs-pyscript:
        pyscript_version: "releases/2023.11.1"

#Load a snapshot
plugins:
    - mkdocs-pyscript:
        pyscript_version: "snapshots/2023.11.1.RC3"

#Load the most recent (unstable) build:
plugins:
    - mkdocs-pyscript:
        pyscript_version: "unstable"

selective

By default, mkdocs-pyscript turns all blocks with type py or python into exectuable code snippets. To cause only selected blocks to be transformed:

  1. Set the selective property to true:
plugins:
    - mkdocs-pyscript:
        selective: true
  1. Specify .pyscript as an additional class for the codeblocks that you want to be runnable:
```{.py .pyscript}
print("Hello, world!")
```

About

Use PyScript in mkdocs

Resources

License

GitHub · Build and ship software on a single, collaborative platform · GitHub
Skip to content

Build and ship software on a single, collaborative platform

Join the world’s most widely adopted AI-powered developer platform.

Try GitHub Copilot

GitHub features

A demonstration animation of a code editor using GitHub Copilot Chat, where the user requests GitHub Copilot to refactor duplicated logic and extract it into a reusable function for a given code snippet.

Build code quickly and more securely with GitHub Copilot embedded throughout your workflows.

GitHub is used by

ShopifyEYFigmaDuolingoNew York TimesMercado LibreAmerican AirlinesFordMercedes BenzSociété GénéraleVodafonePhilipsSAPInfosysSpotify

Accelerate performance

With GitHub Copilot embedded throughout the platform, you can simplify your toolchain, automate tasks, and improve the developer experience.

A Copilot chat window with extensions enabled. The user inputs the @ symbol to reveal a list of five Copilot Extensions. @Sentry is selected from the list, which shifts the window to a chat directly with that extension. There are three sample prompts at the bottom of the chat window, allowing the user to Get incident information, Edit status on incident, or List the latest issues. The last one is activated to send the prompt: @Sentry List the latest issues. The extension then lists several new issues and their metadata.

Work 55% faster.Jump to footnote 1 Increase productivity with AI-powered coding assistance, including code completion, chat, and more.

Duolingo boosts developer speed by 25% with GitHub Copilot

Read customer story

2024 Gartner® Magic Quadrant™ for AI Code Assistants

Read report

Optimize your process with simple and secured CI/CD.

A list of workflows displays a heading ‘45,167 workflow runs’ at the top. Below are five rows of completed workflows accompanied by their completion time and their duration formatted in minutes and seconds.Discover GitHub Actions

Built-in application security
where found means fixed

Use AI to find and fix vulnerabilities—freeing your teams to ship more secure software faster.

Apply fixes in seconds. Spend less time fixing vulnerabilities and more time building features with Copilot Autofix.

Copilot Autofix identifies vulnerable code and provides an explanation, together with a secure code suggestion to remediate the vulnerability.

Solve security debt. Leverage AI-assisted security campaigns to reduce application vulnerabilities and zero-day attacks.

Discover security campaigns
A security campaign screen displays the campaign’s progress bar with 97% completed of 701 alerts. A total of 23 alerts are left with 13 in progress, and the campaign started 20 days ago. The status below shows that there are 7 days left in the campaign with a due date of November 15, 2024.

Dependencies you can depend on. Update vulnerable dependencies with supported fixes for breaking changes.

Learn about Dependabot
List of dependencies defined in a requirements .txt file.

Your secrets, your business: protected. Detect, prevent, and remediate leaked secrets across your organization.

Read about secret scanning
GitHub push protection confirms and displays an active secret, and blocks the push.

Work together, achieve more

Collaborate with your teams, use management tools that sync with your projects, and code from anywhere—all on a single, integrated platform.

A project management dashboard showing tasks for the ‘OctoArcade Invaders’ project, with tasks grouped under project phase categories like ‘Prototype,’ ‘Beta,’ and ‘Launch’ in a table layout. One of the columns displays sub-issue progress bars with percentages for each issue.

Your workflows, your way. Plan effectively with an adaptable spreadsheet that syncs with your work.

It helps us onboard new software engineers and get them productive right away. We have all our source code, issues, and pull requests in one place... GitHub is a complete platform that frees us from menial tasks and enables us to do our best work.
Fabian FaulhaberApplication manager at Mercedes-Benz

Create issues and manage projects with tools that adapt to your code.

Display of task tracking within an issue, showing the status of related sub-issues and their connection to the main issue.Explore GitHub Issues

Millions of developers and businesses call GitHub home

Whether you’re scaling your development process or just learning how to code, GitHub is where you belong. Join the world’s most widely adopted AI-powered developer platform to build the technologies that redefine what’s possible.

Footnotes

  1. Survey: The AI wave continues to grow on software development teams, 2024.

  2. This 7X times factor is based on data from the industry’s longest running analysis of fix rates Veracode State of Software Security 2023, which cites the average time to fix 50% of flaws as 198 days vs. GitHub’s fix rates of 72% of flaws with in 28 days which is at a minimum of 7X faster when compared.

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published