← Crossfit RTP | New Bars, New PRs →

reST Go Diagrams Implemented

The go diagram rendering I was working on a couple weeks ago is functional now, at least on a basic level. It can show full or partial boards. I'm currently rendering the image as a data URI, because it looks like the ability to figure out where to save the image file is dependent not on docutils, but on the layer above that, whether it be sphinx or pelican, or some other library.

Here's an example, which is the result of my recent game with enzondio on Dragon Go Server. I lost the game by quite a bit, but had a good time in the process, and learned quite a bit.

jcdyer vs. enzondio

The markup to generate the above diagram looks like:

.. go::
    :alt: A basic go diagram.

    $$ ---------------------------------------
    $$ |O O O . X O O X X O O . . . . . . . .|
    $$ |X X O O O O X X X X O . . O . . . . .|
    $$ |X . X O X X X O . X O . O . O O . . .|
    $$ |. X X O O O O X X . X O O O X X O . .|
    $$ |X . X O . O X X . X X X X X X O O O .|
    $$ |. X O O O O O X . X . O O . X X X O .|
    $$ |. X O . . O X X X X O O X X X O O . .|
    $$ |. X O O . O O O X O X X X O O O . O O|
    $$ |. . X O O X X O X . . . O X X O O X X|
    $$ |. . X O O X O O X O . . X X . X X X .|
    $$ |. O X X O X O O X . X . X . . . . X X|
    $$ |. X . . X X X X . X X X . X X X X O X|
    $$ |. X . X . X . X X O X O X X X . O . O|
    $$ |. X X X . X X O O O O O O X . X O O O|
    $$ |. O O O . X X X O O . X X O X X X X X|
    $$ |. O X X X . X O O . O O O O X X O O X|
    $$ |. O O X . X X X O O O X X X X X O . O|
    $$ |O X X . X X O O O O X X O O X O O O .|
    $$ |X . . X . X X O . O X . O . O O . . .|
    $$ ---------------------------------------

There are still a number of features that need to be implemented in the diagrams themselves, but I'm pretty excited to have gotten it working.

The code is available on BitBucket at http://bitbucket.org/cliff/rstgo and you can pip install it from PyPI as rstgo. In order to use it from a pelican blog, just put the following in your Pelican settings file:

If you look at the code, you'll also see a setup() function, which is used by sphinx to load rstgo if you add 'rstgo.rst' to the list of extensions in your sphinx configuration file. With sphinx (though not with pelican) you can optionally specify a filename where you want to save the image by passing a filename as an argument to the directive:

.. go: go-board.png

   $$ ------
   $$ |. . .
   $$ |. X .
   $$ |. . .

The file will be saved in the _images directory in the output generated by sphinx, and the HTML document will point to it. No additional processing should be necessary.

There are still a number of rough edges and unimplemented features, but it works, and it's out there ready to be used.

Comments !