I have a JavaScript macro chessboard.js
which accepts a string parameter and is supposed to extract a substring from it. If I pass a hardcoded string value in ChessBoard
, it produces the expected output. If I pick the value from another tiddler (StartingPositionFEN
) - the result is wrong. I’d like to understand why, how to write the non-hardcoded version correctly, and which relevant parts of docs should I read to understand what’s going on here.
I can’t attach a file to the post, so I’m pasting the JSON dump of the tiddlers below
[{"text":"<<chessboard \"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\">>\n\n<<chessboard {{StartingPositionFEN}}>>\n\n","title":"ChessBoard","type":"text/vnd.tiddlywiki","revision":"0","bag":"default"},{"text":"/*\\\ntitle: chessboard.js\ntype: application/javascript\nmodule-type: macro\n\n\\*/\n\n(function () {\n\n /*jslint node: true, browser: true */\n /*global $tw: false */\n \"use strict\";\n\n exports.name = \"chessboard\";\n\n exports.params = [{\n name: \"fen\",\n default: \"\"\n }];\n\n exports.run = function (fen) {\n try {\n var nonl = fen.replaceAll(\"\\n\", \"\");\n var trimmedfen = nonl.trim();\n var parts = trimmedfen.split(\" \");\n return parts[0];\n } catch (err) {\n console.error(err.stack)\n return \"(ERROR: \" + err.message + \") \";\n }\n };\n\n})();\n","title":"chessboard.js","type":"application/javascript","module-type":"macro","revision":"0","bag":"default"},{"text":"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\n","title":"StartingPositionFEN","type":"text/vnd.tiddlywiki","revision":"0","bag":"default"}]