Skip to content

Commit

Permalink
fix raw tag parsing for multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
SampsonCrowley committed May 6, 2019
1 parent 2345421 commit 1078248
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/inky.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Inky.extractRaws = function(string) {
var i = 0;
var raw;
var str = string
var regex = /\< *raw *\>(.*?)\<\/ *raw *\>/i;
var regex = /(?:\n\s*)?< *raw *>([\s\S]*?)<\/ *raw *>(?:\s*\n)?/i;
while(raw = str.match(regex)) {
raws[i] = raw[1];
str = str.replace(regex, '###RAW' + i + '###');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"babel-register": "^6.4.3",
"browserify": "^13.1.0",
"chalk": "^1.1.1",
"gulp": "git+https://github.com/gulpjs/gulp.git#4.0",
"gulp": "4.0",
"gulp-uglify": "^2.0.0",
"mocha": "^2.4.5",
"rimraf": "^2.5.1",
Expand Down
100 changes: 96 additions & 4 deletions test/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ describe('Center', () => {
<table>
<tbody>
<tr>
<th class="menu-item float-center">
<a href="#"></a>
</th>
<th class="menu-item float-center"><a href="#"></a></th>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -442,12 +440,106 @@ describe('h-line', () => {
compare(input, expected);
});
});

describe('raw', () => {
it('creates a wrapper that ignores anything inside', () => {
var input = `<raw><<LCG Program\TG LCG Coupon Code Default='246996'>></raw>`;
var expected = `<<LCG Program\TG LCG Coupon Code Default='246996'>>`;

compare(input, expected);
});


it('works across multiple lines', () => {
var input = `
<body>
<raw>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>
<button href="#">Test</button>
</raw>
</body>
`;
var expected = `
<body>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>
<button href="#">Test</button>
</body>
`;

compare(input, expected);
});

it('stops at the first </raw> tag', () => {
var input = `
<body>
<raw>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>
</raw>
<button href="#">Test</button>
</raw>
</body>
`;
var expected = `
<body>
<<LCG ProgramTG LCG Coupon Code Default='246996'>>
<table class="button">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td><a href="#">Test</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
`;

compare(input, expected);
});

it('matches all raw tags', () => {
var first = "<<LCG ProgramTG LCG Coupon Code Default='246996'>>";
var second = "<asdf>more raw content</asdf>";
var input = `
<body>
<raw>
${first}
</raw>
<button href="#">Test</button>
<raw>
${second}
</raw>
</body>
`
var expected = `
<body>
${first}
<table class="button">
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td><a href="#">Test</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
${second}
</body>
`

compare(input, expected);
});
});
2 changes: 1 addition & 1 deletion test/inky.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Inky', () => {

it('should have an array of component tags', () => {
var inky = new Inky();
assert(Array.isArray(inky.componentTags), 'Inky.zftags is an array');
assert(Array.isArray(inky.componentTags), 'Inky.componentTags is an array');
});

it(`doesn't choke on inline elements`, () => {
Expand Down

0 comments on commit 1078248

Please sign in to comment.