Skip to main content

Sphinx extension asciiart

Project description

http://packages.python.org/sphinxcontrib-asciiart

A Sphinx extension, which turns ascii art color sequences in Sphinx documents into colored HTML or .png or other output.

Installation

This extension can be installed from the Python Package Index:

pip install sphinxcontrib-asciiart

Usage

Just add sphinxcontrib.asciiart to the list of extensions in the conf.py file. For example:

extensions = ['sphinxcontrib.asciiart']

And then use the asciiart block to include your ascii art code:

.. asciiart::
    :line-height: 1.0em
    :spacing: 0

                                                  :. ,..
                                                .' :~.':_.,
                                              .'   ::.::'.'
                                             :     ::'  .:
                                           `.:    .:  .:/
                                            `::--.:'.::'
                                              |. _:===-'
                                            / /
                           ,---.---.    __,','
                          (~`.  \   )   )','.,---..
                           `v`\ | ,' .-'.:,'_____   `.
                               )|/.-~.--~~--.   ~~~-. \
                             _/-'_.-~        ""---.._`.|
                        _.-~~_.-~                    ""'
                 _..--~~_.(~~
      __...---~~~_..--~~
    '___...---~~~

Then it would be rendered as a colorful literal block or image. To show the content of the pypi webpage, I remove the colors:

                                              :. ,..
                                            .' :~.':_.,
                                          .'   ::.::'.'
                                         :     ::'  .:
                                       `.:    .:  .:/
                                        `::--.:'.::'
                                          |. _:===-'
                                         / /
                        ,---.---.    __,','
                       (~`.  \   )   )','.,---..
                        `v`\ | ,' .-'.:,'_____   `.
                            )|/.-~.--~~--.   ~~~-. \
                          _/-'_.-~        ""---.._`.|
                     _.-~~_.-~                    ""'
              _..--~~_.(~~
   __...---~~~_..--~~
,'___...---~~~

Options

sphinxcontrib-asciiart provide rich options to custimize the output. You can configure the global setting, you also can change the behavior for only one ascii art literal block.

When the global setting and literal block based setting are change, or if the content of the literal block is changed, it would re-build the target image even there is target image cache already.

global setting

First of all, you should configure the sphinxcontrib-asciiart in the conf.py to enable the sphinxcontrib-asciiart:

extensions = ['sphinxcontrib-asciiart']
  • ascii_art_output_format: We use the suffix to control the build output format for different target. The default value is as below and you can change it in your conf.py in the following format:

    ascii_art_output_format = dict(html='.html', latex='.png', text='.txt')

Besides the .png, we support many other kinds of image output format:

bmp dib eps gif icns ico im jpg jpeg msp pcx png ppm sgi spider tga tiff
webp xbm palm pdf xv bufr fits grib hdf5 mpeg
  • ascii_art_image_font: When we render the image instead of “.html” and “.txt”, which font name we use, It’s a list of font name that we want to use to render the ascii art. The front one have high priority to be used. the default is:

    ascii_art_image_font = 'NSimSun, simsun, monospace'
  • ascii_art_image_fontsize: When we render the image instead of “.html” and “.txt”, the font size we want to use, it’s an integer, the default value is:

    ascii_art_image_fontsize = 14

block specific setting

  • ‘spacing’: int, The space between each lines. The default value is -1.

  • ‘font’: str, A list of font name that we want to use to render the ascii art. The front one have high priority to be used.

  • ‘fontsize’: int, The font size we want to use to render the ascii art.

  • ‘include’: Use the content of the file given in include as ascii content.

  • ‘textwidth’: The maxmium seen character number in each lines. Lines longer than that would case line break. Default is 0 and 0 means never line break.

  • ‘leadingspace’: When textwidth option is given, then the wrapped text would start at leadingspace.

For example:

.. asciiart::
    :font: simsun, monospace, "Times new roman"
    :fontsize: 14
    :spacing: 0

    .· .·.   /╲     /|
            ·│  \  ╱ |
       \-.___ / \  \/ / /
        \ __ ╲  .,.| ╱__
        ╱  乁  '\|)╱ ̄  ╲
    -<`︶╲__╱ ︶╲    ╲ \
         ̄ ̄ /   /  ╱﹀乀 \│
             ╲  ' /╲  ·╲/
               \| /   \  ; `
                \/     \  ·,
    .----/      ′      ︳  ·__,

Changelog

  1. 1.0.0 Initial upload.

  2. 1.1.2 Support new options: textwidth, include

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

sphinxcontrib-asciiart-1.1.2.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file sphinxcontrib-asciiart-1.1.2.tar.gz.

File metadata

  • Download URL: sphinxcontrib-asciiart-1.1.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for sphinxcontrib-asciiart-1.1.2.tar.gz
Algorithm Hash digest
SHA256 afe36b1154e76772f12ea57d9fcd5b42a8eed33090366093ba79ecf323229b6a
MD5 278b3d08dbde35650efa9bb1e28eb2fe
BLAKE2b-256 c227f387dfe358b52ddf3a396107b341a11067473dc101a66093a22d50b3fe48

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