improve word-splitting in history list, and don't show lone pawns

This commit is contained in:
Jesse D. McDonald 2020-03-14 12:53:14 -05:00
parent bd450b3322
commit b9de793ce8
1 changed files with 9 additions and 3 deletions

View File

@ -354,14 +354,19 @@ function renderHistory(board) {
board = board['prior']; board = board['prior'];
} }
const NBSP = '\u00a0'; /* non-breaking space */
const SHY = '\u00ad' /* soft hyphen */
const ZWSP = '\u200b'; /* zero-width space */
var result = ''; var result = '';
var n = 0; var n = 0;
while (list.length > 0) { while (list.length > 0) {
const move = list.pop(); const move = list.pop();
if (move['from'] === 'phantom') { if (move['from'] === 'phantom') {
const piece = move['type'] === 'p' ? '' : move['type'].toUpperCase();
const took = move['took'] ? 'x' : ''; const took = move['took'] ? 'x' : '';
result += '*' + move['type'].toUpperCase() + took + move['to']; result += SHY + '*' + piece + took + move['to'];
} else { } else {
if (n > 0 || move['side'] === 'dark') { if (n > 0 || move['side'] === 'dark') {
result += ' '; result += ' ';
@ -369,7 +374,7 @@ function renderHistory(board) {
if (move['side'] === 'light') { if (move['side'] === 'light') {
++n; ++n;
result += String(n) + '. '; result += String(n) + '.' + NBSP;
} }
if (move['pass']) { if (move['pass']) {
@ -385,8 +390,9 @@ function renderHistory(board) {
} else if (move['queen_castle']) { } else if (move['queen_castle']) {
result += 'O-O-O'; result += 'O-O-O';
} else { } else {
const piece = move['type'] === 'p' ? '' : move['type'].toUpperCase();
const took = move['took'] ? 'x' : ''; const took = move['took'] ? 'x' : '';
result += move['type'].toUpperCase() + move['from'] + took + move['to']; result += piece + move['from'] + took + move['to'];
} }
} }