דילוג לתוכן הראשי
chessapp.dev

משחק בתוך מאמר: InlinePgnGame

<InlinePgnGame> puts a game into an article: a window of its moves on a board, beside the moves as PGN writes them, side lines and all. One game can be shown as many times as the article has positions to talk about — each board its own window, opened where the text needs it.

Morphy's Opera Game: the last nine moves, opened before 13. Rxd7!

12. O-O-O
8
7
6
5
4
3
2
a1
b
c
d
e
f
g
h

The markup

The game is written once, at the top of the article, and every board takes it:

export const miniature = `[Event "Paris"]
1. e4 e5 2. Nf3 d6 … 16. Qb8+! Nxb8 17. Rd8# 1-0`

<InlinePgnGame pgn={miniature} from="9" to="17" start="12" caption="…" />

A longer game is better kept in a file of its own beside the article, imported as text — the game review does that:

import game from "./rubinstein-capablanca-1911.pgn?raw"

<InlinePgnGame pgn={game} from="13..." to="17" />

The props

  • pgn — the game, as PGN. Its first game is read, with its side lines, comments and ! / ? marks.
  • game — which game of a PGN holding several, counted from 1 (a lichess study's chapters). Default the first.
  • showNextMoveArrow={false} — no arrows to the next moves on the board (green the game's, blue a side line's); the moves stay in the list, and a comment's own drawing still shows.
  • shapes — the arrows and circles a comment draws ([%cal], [%csl]), on by default; shapes={false} leaves them off. See Arrows and circles.
  • from, to — the first and last position the reader can reach, as move numbers: "9" is the position after White's 9th move, "9..." after Black's. Absent: the start and the end. See Windows.
  • start — where the board opens: a move number, or a line of moves that may go into a side line. Absent: from. See Side lines.
  • fromPly, toPly, startPly — the same three in plies, the start being 0: ply 21 is the position after White's 11th move. A ply wins over a move number.
  • variations — the side lines that branch inside the window, shown by default; variations={false} shows the mainline alone.
  • comments — show the PGN comment of the move on the board, under the moves.
  • orientation — "black" to face the board from Black's side.
  • caption — a line above the board; it also names the board for a screen reader.

The reader steps with the buttons above the board, clicks a move in the list, or drags a piece along an arrow — but only within the window. From the keyboard, ← and → step back and on; Home and End go to the start and end of the line on screen — in a side line its first and last move, and Home pressed again climbs out to the line it branched from; and Page Up and Page Down go to the window's first and last position. A page can hold many boards: the keys drive the one the reader last clicked or tabbed into, which is ringed — and before any is touched, the first board in view. The board's arrows are the moves on from the position: green the game's, blue a side line's.

<InlinePgnGame2colH> and <InlinePgnGame2colV> take every prop above and show the same board with its moves in two columns — beside the board in a box no taller than it, or under it in a box half its height — see Moves in two columns.