diff --git a/lib/index.cjs b/lib/index.cjs index 1fe9ba5..2bb6180 100644 --- a/lib/index.cjs +++ b/lib/index.cjs @@ -160,6 +160,18 @@ const lookupVar = function(label, index) { index--; } + // Normal lookup has failed, attempt to resolve multiple labels into individuals + if(label?.trim().indexOf(' ') > 0){ + const labels = label.split(' '); + const outputStrings = labels.map((string)=>{ + return lookupVar(string, index)?.content || string; + }); + return { + content : outputStrings.join(' '), + resolved : true + }; + } + return undefined; }; diff --git a/lib/index.umd.js b/lib/index.umd.js index c7fa33c..1b21ada 100644 --- a/lib/index.umd.js +++ b/lib/index.umd.js @@ -160,6 +160,18 @@ index--; } + // Normal lookup has failed, attempt to resolve multiple labels into individuals + if(label?.trim().indexOf(' ') > 0){ + const labels = label.split(' '); + const outputStrings = labels.map((string)=>{ + return lookupVar(string, index)?.content || string; + }); + return { + content : outputStrings.join(' '), + resolved : true + }; + } + return undefined; }; diff --git a/spec/__snapshots__/index.test.js.snap b/spec/__snapshots__/index.test.js.snap index eb8da88..82cfa8f 100644 --- a/spec/__snapshots__/index.test.js.snap +++ b/spec/__snapshots__/index.test.js.snap @@ -102,6 +102,8 @@ exports[`Math function parameter handling allows two variables in two-parameter exports[`Math function parameter handling allows variables in single-parameter functions 1`] = `"

4

"`; +exports[`Multiple variable names at once output multiple variables at once 1`] = `"

first second ef

"`; + exports[`Normal Links and Images Applies curly injectors to images 1`] = `"

alt text{width:100px}

"`; exports[`Normal Links and Images Renders normal images 1`] = `"

alt text

"`; diff --git a/spec/index.test.js b/spec/index.test.js index 3265e14..b935c24 100644 --- a/spec/index.test.js +++ b/spec/index.test.js @@ -410,6 +410,14 @@ describe('Variable names that are subsets of other names', ()=>{ }); }); +describe('Multiple variable names at once', ()=>{ + it('output multiple variables at once', function() { + const source = '[ab]: first\n\n[cd]: second\n\n$[ab cd ef]'; + const rendered = Markdown(source).trimReturns(); + expect(rendered).toMatchSnapshot(); + }); +}); + describe('Regression Tests', ()=>{ it('Don\'t Eat all the parentheticals!', function() { const source = '\n| title 1 | title 2 | title 3 | title 4|\n|-----------|---------|---------|--------|\n|[foo](bar) | Ipsum | ) | ) |\n'; diff --git a/src/index.js b/src/index.js index 95ce6b7..9deadb4 100644 --- a/src/index.js +++ b/src/index.js @@ -158,6 +158,18 @@ const lookupVar = function(label, index) { index--; } + // Normal lookup has failed, attempt to resolve multiple labels into individuals + if(label?.trim().indexOf(' ') > 0){ + const labels = label.split(' '); + const outputStrings = labels.map((string)=>{ + return lookupVar(string, index)?.content || string; + }); + return { + content : outputStrings.join(' '), + resolved : true + }; + } + return undefined; };