The following is just a start. It does not filter out the { xxx } or ';' comments called for in your PGN chess link.
But it does the majority of the work for you.
Code:
<!DOC HTML>
<html>
<head>
<title> PGN Conversion </title>
<script type="text/javascript">
//<![CDATA[
// "KQBNR" are "¢£¤¥¦"
String.prototype.PGNamer = function() {
var PGNsymbols = ['¢','£','¤','¥','¦'];
var tstr = ''; var ptr = '';
var tarr = this.split('');
for (var i=0; i<tarr.length; i++) {
ptr = 'KQBNR'.indexOf(tarr[i]);
if (ptr == -1) { tstr += tarr[i]; }
else { tstr += PGNsymbols[ptr]; }
}
return tstr+' ';
}
function PGNconverter() {
var str = '';
var tarr = document.getElementById('fromText').value.split(' ');
for (var i=0; i<tarr.length; i++) {
str += tarr[i].PGNamer();
}
document.getElementById('toPGN').value = str;
}
//]]>
</script>
</head>
<body>
From text:<br>
<textarea rows="8" cols="80" id="fromText">
1. d4 Nf6 2. Nf3 g6 3. Nc3 d5 4. Bf4 Bg7 5. e3 O-O 6. Be2 b6 7. Ne5 Bb7
8. h4 Nbd7 9. f3 Nxe5 10. Bxe5 Ne8 11. Bxg7 Nxg7 12. f4 e5 13. fxe5 f6
14. Bf3 fxe5 15. dxe5 c6 16. Qd2 Qe8 17. O-O-O Rd8 18. h5 gxh5 19. Qd4 c5
20. Qh4 Qxe5
</textarea><p>
<button onclick="PGNconverter()">Converted to PGN</button>:<br>
<textarea rows="8" cols="80" id="toPGN">
</textarea><p>
</body>
</html>
Good Luck!
Bookmarks