From 474e08575b13b8184f02cf999d81f316654acc89 Mon Sep 17 00:00:00 2001 From: Sampson Crowley Date: Sun, 5 May 2019 20:44:40 -0600 Subject: [PATCH] fix raw tag parsing for multiple lines --- README.md | 16 ++++++++ lib/inky.js | 2 +- package.json | 2 +- test/components.js | 100 +++++++++++++++++++++++++++++++++++++++++++-- test/inky.js | 2 +- 5 files changed, 115 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4af247e..5ff8416 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,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/package.json b/package.json index 8e57e50..d6da538 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/components.js b/test/components.js index b653850..7d4f5d2 100644 --- a/test/components.js +++ b/test/components.js @@ -52,9 +52,7 @@ describe('Center', () => { - +
- -
@@ -442,7 +440,7 @@ describe('h-line', () => { compare(input, expected); }); }); - + describe('raw', () => { it('creates a wrapper that ignores anything inside', () => { var input = `<>`; @@ -450,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`, () => {