Skip to main content

MkDocs plugin that adds a configurable shell-ps1 code fence with copy-safe prompt character

Project description

superfences-ps1

MkDocs plugin that adds a configurable shell-prompt SuperFences fence with copy-safe PS1 prompt characters.

The plugin registers a custom SuperFences fence (default name shell-ps1) that prepends a configurable PS1 prompt character to every command line. The prompt is rendered visibly in the documentation but is never copied to the clipboard and is never selected by mouse — the plugin injects a data-copy attribute with the raw source text so Material for MkDocs' copy button bypasses the prompt spans entirely, and user-select: none CSS is injected to prevent mouse selection of the prompt.

Installation

pip install superfences-ps1

Or with uv:

uv add superfences-ps1

Requirements

  • pymdownx.superfences must be listed under markdown_extensions in mkdocs.yaml

Usage

mkdocs.yaml configuration

plugins:
  - superfences-ps1:
      fence_name: shell-ps1    # fence language identifier (default: shell-ps1)
      prompt_char: "$"         # PS1 prompt character prepended to each line (default: $)
      prompt_color: "#5fb3b3"  # optional CSS color for the prompt character

markdown_extensions:
  - pymdownx.superfences

Writing shell fences

Use the configured fence_name in your markdown:

```shell-ps1
echo "Hello, world!"
ls -la
```

The plugin prepends the prompt character to each non-empty line before passing the content to Pygments. The rendered output shows the prompt visually, but the copy button and mouse selection only grab the commands themselves.

Configuration options

Option Type Default Description
fence_name str shell-ps1 The fence language identifier used in markdown
prompt_char str $ The PS1 prompt character prepended to each command line
prompt_color str or None None Optional CSS color value for the rendered prompt

[!NOTE] prompt_char must be one of $, %, or # — the only characters Pygments' BashSessionLexer recognises as prompt markers, emitting them as Generic.Prompt (.gp) tokens. Any other value will cause a PluginError at build time. > in particular is the continuation prompt (_ps2) and causes the entire line to be tokenised as Generic.Output (.go), which would treat the command text as output.

How it works

  1. On on_config, the plugin validates that pymdownx.superfences is present and injects a custom fence formatter into mdx_configs["pymdownx.superfences"]["custom_fences"].
  2. When MkDocs processes a page containing a fenced code block with the configured fence_name, SuperFences calls the injected formatter.
  3. The formatter prepends <prompt_char> to every non-empty line, then passes the result to Pygments using the console (BashSessionLexer) lexer. Pygments wraps the prompt in <span class="gp"> and the command in additional token spans.
  4. The formatter injects a data-copy attribute on the wrapper <div> containing the raw (un-prompted) source. Material for MkDocs' copy button reads data-copy in preference to innerText, so the prompt is never included in clipboard content.
  5. On on_post_page, the plugin injects a <style> block into each page's <head> with user-select: none on .gp spans, preventing mouse selection of the prompt. If prompt_color is configured, the color rule is combined into the same <style> block.

Development

git clone https://github.com/dusktreader/superfences-ps1
cd superfences-ps1
uv sync
make qa/full

License

MIT — see LICENSE.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

superfences_ps1-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

superfences_ps1-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file superfences_ps1-0.1.0.tar.gz.

File metadata

  • Download URL: superfences_ps1-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for superfences_ps1-0.1.0.tar.gz
Algorithm Hash digest
SHA256 17334254064954d03204fb80c0c2e1e9634390934c34c07f95caecdc79803e0f
MD5 b784c1c33be3215992e6268b6dd456a9
BLAKE2b-256 c44c7de690a91a0d57f1f41859051474ab03f0a8a17b0832051412081147e77d

See more details on using hashes here.

File details

Details for the file superfences_ps1-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: superfences_ps1-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for superfences_ps1-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eed17bf0a457cb0333f496becc42c7f0e497d504070ba3aa29cb9816e37bfdb9
MD5 3d0b0fa2f1bcc2ce1a6738d302a93689
BLAKE2b-256 92b7c84f4cf96a04c79d4a621be132ccdf7aff566dbbc4580c531d68bb018428

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page