Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Pretty-print your chess games using Prettier (github.com/gmasclet)
101 points by gmasclet 2 days ago | hide | past | favorite | 9 comments
Hi,

As an enthusiast chess player, I like to manage my games and my opening repertoire as a set of PGN files stored in a Git repository (PGN is a text file format for recording chess games). So I wanted a way to pretty-print PGN files using a CLI and integrating in my editor.

Today, it looks like most people use GUI-based software. So I decided to create a Prettier plugin that formats PGN files. Prettier is a well-known pretty-printer in the Node.js ecosystem, used to ensure consistent source code formatting in software projects. One upside of implementing this PGN formatter as a Prettier plugin is that it benefits from its editor integration.

The plugin is currently near complete, even if the project is still at an early stage. It's usable, even if there might be some bugs.

Hope you find this useful. Comments and ideas are welcome. Have a nice weekend.






I was actually thinking of developing something similar to make it easier to copy my chess game review comments into my Obsidian notes.

Thank you!


You're welcome!

By the way, something I've considered but not implemented yet are options to tweak the formatting (for instance, whether to indent or inline comments / variations). The Prettier approach is to be opinionated, but some language-specific options may be useful.


I've always wanted to look into writing my own Prettier plugins, how'd you feel about getting started working with their little mini DSL (fill, join, hardline, line, etc.)?

The DSL itself is pretty nice. However, one thing I found annoying is that the printing function itself is hard to unit test: there is no easy way to instantiate its parameters (in particular the `ASTPath` class). So I relied on testing it by calling `Prettier.format()`, which is more a end-to-end test of the whole plugin. Maybe I'll figure out another solution at some point.

What about using a fenced code block?

You mean inside markdown? Prettier supported that since 2017 [1], it will call the individual plugins to handle content inside the code blocks.

[1]: https://prettier.io/blog/2017/11/07/1.8.0.html


PGN is just a format to communicate the games. So pgn pretty-printing is at the same level as pretty printing json. Nothing wrong with that, but at some point you might want to publish a game with diagrams variations, ....

For that purpose, you can use Latex (yes, I know, not everybody's cup of tea)

https://www.overleaf.com/learn/latex/Chess_notation


This looks a bit cumbersome to write to me.

I really like the JS preview/rendering plugins for fenced code blocks in Markdown. For example Mermaid, which is supported by many Markdown renderers or IDEs. [1]

It would be fun to have something like this for chess notation, that interactively renders the last position with forward and back buttons.

Static PDFs are mostly a thing of the past.

[1]: https://github.blog/developer-skills/github/include-diagrams...


Thanks for the idea, I'd not considered it. LaTex may have some use, I'll take a look. Indeed, probably the best solution to publish a game with diagrams.

For personal notes, I would also consider embedding PGN into Markdown. Sadly, PGN rendering in Markdown isn't supported yet, as far as I know (something like Mermaid would be awesome).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: