Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix raw tag parsing for multiple lines #110

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ Here are the names of the defaults:
}
```

## Raw HTML

If you need to include raw html, you can wrap raw content in `<raw>` tags

```html
<raw>
<button></button>
<asdf></asdf>
</raw>
```

This is a feature intended for advanced users. You will be responsible for ensuring all markup between `<raw>` tags is valid. All content after an opening `<raw>` tag will be inserted "As Is" until the next closing `</raw>` tag.

This means that `<raw>` tags CANNOT be nested


## Programmatic Use

The Inky parser can be accessed directly for programmatic use. It takes in a [Cheerio](https://github.com/cheeriojs/cheerio) object of HTML, and gives you back a converted Cheerio object.
Expand Down
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 *)?< *raw *>([\s\S]*?)<\/ *raw *>(?: *\n)?/i;
while(raw = str.match(regex)) {
raws[i] = raw[1];
str = str.replace(regex, '###RAW' + i + '###');
Expand Down
94 changes: 94 additions & 0 deletions test/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,98 @@ describe('raw', () => {

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