Skip to content

Commit 3c3fa25

Browse files
kdaveniklasf
authored andcommitted
Add ascii board as description of svg
The tag <desc> in SVG can store a textual description, eg. for better accessibility. For the chess board there could be the string representation (basically str(chess.Board()) and enclosed in <pre> it is readable in text browsers like links or w3m when the svg is embedded in html.
1 parent 457f5f4 commit 3c3fa25

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

chess/svg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ def board(board: Optional[chess.BaseBoard] = None, *,
286286
if style:
287287
ET.SubElement(svg, "style").text = style
288288

289+
if board:
290+
desc = ET.SubElement(svg, "desc")
291+
asciiboard = ET.SubElement(desc, "pre")
292+
asciiboard.text = str(board)
293+
289294
defs = ET.SubElement(svg, "defs")
290295
if board:
291296
for piece_color in chess.COLORS:

0 commit comments

Comments
 (0)