Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
12 changes: 12 additions & 0 deletions lib/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
2 changes: 2 additions & 0 deletions spec/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `"<p>4</p>"`;

exports[`Multiple variable names at once output multiple variables at once 1`] = `"<p>first second ef</p>"`;

exports[`Normal Links and Images Applies curly injectors to images 1`] = `"<p><img src="url" alt="alt text">{width:100px}</p>"`;

exports[`Normal Links and Images Renders normal images 1`] = `"<p><img src="url" alt="alt text"></p>"`;
Expand Down
8 changes: 8 additions & 0 deletions spec/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down