From 405069fdd35849d4fede8183b14918e060d7b78c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 19 Apr 2021 12:34:05 -0300 Subject: transform replacer arguments --- upd8.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/upd8.js b/upd8.js index df6b5c6..10b87cc 100755 --- a/upd8.js +++ b/upd8.js @@ -1304,9 +1304,6 @@ const replacerSpec = { const source = input.slice(node.i, node.iEnd); const replacerKey = node.data.replacerKey?.data || 'track'; - const replacerValue = transformNodes(node.data.replacerValue, opts); - const hash = node.data.hash && transformNodes(node.data.hash, opts); - const enteredLabel = node.data.label && transformNode(node.data.label, opts); if (!replacerSpec[replacerKey]) { logWarn`The link ${source} has an invalid replacer key!`; @@ -1321,6 +1318,8 @@ const replacerSpec = { transformName } = replacerSpec[replacerKey]; + const replacerValue = transformNodes(node.data.replacerValue, opts); + const value = ( valueFn ? valueFn(replacerValue) : searchKey ? search[searchKey](replacerValue) : @@ -1334,6 +1333,8 @@ const replacerSpec = { return search; } + const enteredLabel = node.data.label && transformNode(node.data.label, opts); + const label = (enteredLabel || transformName && transformName(value.name, node, input) || value.name); @@ -1343,12 +1344,20 @@ const replacerSpec = { return search; } + const hash = node.data.hash && transformNodes(node.data.hash, opts); + + const args = node.data.args && Object.fromEntries(node.data.args.map( + ({ key, value }) => [ + transformNode(key, opts), + transformNodes(value, opts) + ])); + const fn = (htmlFn ? htmlFn : strings.link[linkKey]); try { - return fn(value, {text: label, hash, strings, to}); + return fn(value, {text: label, hash, args, strings, to}); } catch (error) { logError`The link ${source} failed to be processed: ${error}`; return source; -- cgit 1.3.0-6-gf8a5