diff --git a/README.md b/README.md index d7bed42..6c5fd73 100644 --- a/README.md +++ b/README.md @@ -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 `` tags + +```html + + + + +``` + +This is a feature intended for advanced users. You will be responsible for ensuring all markup between `` tags is valid. All content after an opening `` tag will be inserted "As Is" until the next closing `` tag. + +This means that `` 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. diff --git a/lib/inky.js b/lib/inky.js index ecdf227..2114c4e 100644 --- a/lib/inky.js +++ b/lib/inky.js @@ -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 + '###'); diff --git a/test/components.js b/test/components.js index b4a27fb..b378a33 100644 --- a/test/components.js +++ b/test/components.js @@ -448,4 +448,98 @@ describe('raw', () => { compare(input, expected); }); + + + it('works across multiple lines', () => { + var input = ` + + + <> + + + + `; + var expected = ` + + <> + + + `; + + compare(input, expected); + }); + + it('stops at the first tag', () => { + var input = ` + + + <> + + + + + `; + var expected = ` + + <> + + + + + + +
+ + + + + + +
Test
+
+ + + `; + + compare(input, expected); + }); + + it('matches all raw tags', () => { + var first = "<>"; + var second = "more raw content"; + var input = ` + + + ${first} + + + + ${second} + + + ` + var expected = ` + + ${first} + + + + + + +
+ + + + + + +
Test
+
+ ${second} + + ` + + compare(input, expected); + }); }); diff --git a/test/inky.js b/test/inky.js index 05aaa13..322bf3a 100644 --- a/test/inky.js +++ b/test/inky.js @@ -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`, () => {