npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docusaurus-live-brython

v3.0.0-beta.28

Published

Docusaurus live code block component for python.

Downloads

40

Readme

Docusaurus Live Codeblock for Python

NPM Version

[!NOTE]
This theme works with Docusaurus v3+.

[!WARNING] This theme is still in development and the api is not considered stable in the beta phase.

Live demo here

Python-Playground

You can create live code editors with a code block live_py meta string.

Install

npm i docusaurus-live-brython # or yarn add docusaurus-live-brython

Modify your docusaurus.config.js

module.exports = {
  ...
+ themes: ['docusaurus-live-brython'],
  presets: ['@docusaurus/preset-classic']
  ...
}

Configure 👉 Brython source:

module.exports = {
  ...
+ themes: [
+   ['docusaurus-live-brython'],
+   {
+     brythonSrc: 'https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js', // default
+     brythonStdlibSrc: 'https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.js' // default
+   }
  presets: ['@docusaurus/preset-classic']
  ...
}

Example:

import turtle
t = turtle.Turtle()
t.width(5) 
t.speed(5)
for c in ['red', '#00ff00', '#fa0', 'rgb(0,0,200)']:
    t.color(c)
    t.forward(100)
    t.left(90)

# dot() and write() do not require the pen to be down
t.penup()
t.goto(-30, -100)
t.dot(40, 'rgba(255, 0, 0, 0.5')
t.goto(30, -100)
t.dot(40, 'rgba(0, 255, 0, 0.5')
t.goto(0, -70)
t.dot(40, 'rgba(0, 0, 255, 0.5')

t.goto(0, 125)
t.color('purple')
t.write("I love Brython!", font=("Arial", 20, "normal"))

results in an live editable code block:

Brython Demo

Options

A brython live code block can have additional options in the meta string:

  • title=Some-Text The title shown in the codeblock header. The title must be unique per page. Single hyphens/underscores (- and _) are replaced by a space, double hyphens/underscores are replaced with a single hyphen/undescore: title=Foo-Bar--Bazz => Foo Bar-Bazz; title=Foo_Bar__Bazz => Foo Bar_Bazz
  • persistent when added, the reset button will not be shown.
  • slim displays only the play button, without a header and without the option to persist changes.

Storage

User edited code is stored in the localStorage. To lookup the edits, id's for each codeblock are generated after the following rules:

  • title is present -> use a sanitized version as the key.
  • title is not present -> all codeblocks on the page are enumerated and the index number is used as the key. !! Saved Edits are probably not correctly applied.

Development

Ensure to locally link the plugin to the website, s.t. changes take place immediately.

To compile and copy the changed .css files to the lib folder, run

yarn run watch

To see the changes within docusaurus, launch the documentation website located under website/.

Initially link the plugin to the website (only needed once)

# in the project root
yarn link

cd website

yarn link docusaurus-live-brython

Then start the website

yarn run start

Publish

yarn run build
# when running inside wsl, use --auth=legacy
npm login --auth=legacy
npm publish --auth=legacy