Open olleeriksson opened 1 year ago
Hi. It's currently not really possible (except by subclassing chess.pgn.StringExporter
), but I think it makes sense to add.
By the way, which PGN viewer has this requirement?
This is how Lichess.org outputs comments + annotations:
2... Nf6 { Queen's Gambit Declined - Marshall defense } { [%csl Gc4][%cal Gc4d5] }
And Chesstempo.org: (though it's not obvious how to create these so not a lot of people are probably creating annotations here, but maybe some people import into Chesstempo and then export, in which case you also get this)
1.e4 e5 { This is a comment } {[%cal Gf2f5,Gg2g3][%csl Gb3,Yc4]}
And this NodeJS library for parsing PGN files seem to want it formatted this way too.
https://www.npmjs.com/package/pgn-parser
Check out test/test_grammer.js around line 170 for a test that tells alot.
I have sort of gotten around this by now by creating python script using your parser and a hack that inserts } { between the text part and the [% part after it is printed, but at least based on these three frameworks/sites I would guess this would be something good to support.
I'm trying to use python-chess to merge two pgn games, which is working fine. But it appears some PGN viewers really want the normal text comments and the %cal and %csl annotations separated into their own comment, like so:
I seem to have no way to create this type of comment since the "comment" field in the GameNode class in pgn.py is a string, when I think I want it to be a list of strings. So I end up with this:
I have also tried setting node.comment = f"{text} }} {{ {annotations}" , ie injecting a } and a { inside the comment but it doesn't work, and is hacky anyway. It appears to insert the { but the } never appears.
What's your take on this? Just something the library doesn't support?