Skip to main content

Sphinx extension asciiart

Project description

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

A Sphinx extension, which turns ANSI color sequences in Sphinx documents into colored HTML 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::

                                                  :. ,..
                                                .' :~.':_.,
                                              .'   ::.::'.'
                                             :     ::'  .:
                                           `.:    .:  .:/
                                            `::--.:'.::'
                                              |. _:===-'
                                            / /
                           ,---.---.    __,','
                          (~`.  \   )   )','.,---..
                           `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 to change global setting, you also can change the behavior for only one ascii art literal block..

global setting

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

extensions = ['sphinxcontrib-asciiart']

Then you can configure many other global configuration:

ascii_art_output_format

ascii_art_output_format give the output format of the ascii art block. We use the suffix to control the build output foramt. 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')

That means when you build html output, the ascii art block is built as html file and then linked to the whole document. When you build latex output, it’s .png file and .txt when building plain text output. the .html format is only supported when you building html output.

Besides tht .html and .txt format, we support many other kinds of output format:

bmp
dib
eps
gif
icns
ico
im
jpeg
jpeg 2000
msp
pcx
png
ppm
sgi
spider
tga
tiff
webp
xbm

palm
pdf
xv thumbnails

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.

For example:

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

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

Changelog

1.0.0 Initial upload.

1.0.1 Automatically add the img[“height”] to keep the original height x width to avoid to magnify in pdf if there is no height, width and scale option in the image attribute. We’d want to show the original font in the PDF.

1.0.2 Adjust the box-shadow of the html output.

1.0.3 bug fix: if there is already .png, didn’t insert the img[“height”].

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.0.3.tar.gz (9.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: sphinxcontrib-asciiart-1.0.3.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for sphinxcontrib-asciiart-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b0d80911e5e6a1945064f8a6826517bd32fb1bc02e5e8d4c58a99eba220b98c7
MD5 f47fdeee89825de625701e61664c02eb
BLAKE2b-256 f582671fdef3864d3e94c543c3ce5b131c59a051dc666a8eec2ef869e9729618

See more details on using hashes here.

Supported by

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