mdbook-chess

Crates.iomdbook-chess
lib.rsmdbook-chess
version0.2.2
sourcesrc
created_at2022-08-06 20:54:55.887721
updated_at2023-08-11 18:37:35.541188
descriptionAn mdbook preprocessing plugin to generate chess boards
homepagehttps://github.com/xd009642/mdbook-chess
repositoryhttps://github.com/xd009642/mdbook-chess
max_upload_size
id639988
size164,914
(xd009642)

documentation

https://docs.rs/mdbook-chess

README

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.

Commit count: 28

cargo fmt