#chess #mdbook #chess-board #markdown

app mdbook-chess

An mdbook preprocessing plugin to generate chess boards

4 releases

0.2.2 Aug 11, 2023
0.2.1 Jul 18, 2023
0.2.0 Sep 4, 2022
0.1.0 Aug 6, 2022

#303 in Text processing

28 downloads per month

MIT/Apache

75KB
508 lines

mdbook-chess

Create chess boards in your mdbooks!

A chess board in starting position

Installation

Simply:

cargo install mdbook-chess

And then add to your mdbook project as so:

# book.toml
[book]
authors = ["xd009642"]
language = "en"
multilingual = false
src = "src"
title = "mdbook-chess"

[preprocessor.chess]

For an example book just look to the provided demo-book.

Usage

Currently the chess boards are specified via a very simple YAML structure. With 5 possible fields:

  • load - either "start" for the starting board or a FEN string. If not provided it's default starting board
  • save - name to save board under (can be a list)
  • moves - list of moves
  • overwrite - boolean of whether to overwrite saved version of the board with these moves
  • highlights - highlight a square on the board a list of squares
  • lines - lines and arrows from square to square (currently only straight)

So we can create a starting board like using a code block with the language set to chess. Like:

```chess
load: start
``` 

Or like:

```chess
# mdbook seems to hate empty code blocks so have at least a blank line
```

For brevity/formating the backticks and "chess" language specifier will be omitted for future examples.

Of course if we want to refer to this board later we need to save it. So we can create a board with a name to refer to it later as so:

save: our_board

We can then load it and apply some moves - this will overwrite it so to do alternatives can set overwrite to false and start from previous position. We can also save multiple boards from a point for exploring many different routes:

load: our_board
save: ["ck-main", "ck-2", "ck-3"]
moves: ["e4", "c6", "d4", "d5"]

Arrows are done by writing the two squares and the line between them, there are currently 3 styles:

  • - a line
  • -> a single direction arrow
  • <-> a bidirectional arrow

And we can use them as so:

load: our_board
moves: ["e4", "c6", "d4", "d5"]
lines: ["e2->e4", "d1<->h5", "a4-h4"]

Generally, if there's a syntax error in the markdown there's a reasonable chance you'll see a bunch of SVG text dumped into the book. If this happens read the log messages and hopefully an answer will be gleaned.

For an example of all the features in use please look to the demo book!

Roadmap

Potential future features

These are features I'd be willing to do if there was demand and they were sufficiently easy or willing to accept PRs for.

  • GIF generation
  • L shaped move arrow for horsey
  • Chess.com style icons (blunder, excellent etc)
  • Styling and theming
  • More layout options in page
  • Rank and file labels
  • Flip the board

Unlikely features

These are features where they will only be added via PR but the PR may not be accepted

  • Chess variants
  • Eval bar

License and Copyright

All chess SVGs were created by Wikimedia user Cburnett and are CC BY-SA 3.0 licensed. You can find them here I've edited them to template in a transform and remove the outer tags for ease of board generation.

All other aspects of this project are currently licensed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-MIT and LICENSE-APACHE for more details.

Dependencies

~15–28MB
~405K SLoC