From 071f8d8b5c58a881794f3c7bf02ee94ec52ab13f Mon Sep 17 00:00:00 2001 From: Simone Date: Sun, 2 May 2021 20:04:12 +0100 Subject: [PATCH 1/4] rm bundled.html --- bundled.html | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 bundled.html diff --git a/bundled.html b/bundled.html deleted file mode 100644 index 21a2e8e..0000000 --- a/bundled.html +++ /dev/null @@ -1,11 +0,0 @@ -

hi from myHtml

- - - -

line 2

- - - -

line 3

From 8a3ed35ca00761baf7c3cca5c9fca257ddbb54d5 Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 3 May 2021 15:46:09 +0100 Subject: [PATCH 2/4] Stylesheet regex without quotes and remove leading slashes --- src/inlineStylesheets.js | 4 ++-- test/testInlineStylesheets/index.html | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/inlineStylesheets.js b/src/inlineStylesheets.js index 7ec6b96..c8c3a20 100644 --- a/src/inlineStylesheets.js +++ b/src/inlineStylesheets.js @@ -4,7 +4,7 @@ const fs = require('fs').promises; const path = require('path'); let inlineHtmlStyles = async htmlPath => { - const linkTagRegex = /|/; + const linkTagRegex = /|/; let html = await fs.readFile(htmlPath, 'utf8'); let matches = html.match(new RegExp(linkTagRegex, 'g')); if (!matches) @@ -12,7 +12,7 @@ let inlineHtmlStyles = async htmlPath => { let stylesheetPromises = matches .map(linkTag => { let m = linkTag.match(linkTagRegex); - return m[1] || m[2]; + return (m[1] || m[2]).replace(/^\/+/, ''); }) .map(relPath => path.resolve(path.dirname(htmlPath), relPath)) .map(stylesheetPath => fs.readFile(stylesheetPath, 'utf8')); diff --git a/test/testInlineStylesheets/index.html b/test/testInlineStylesheets/index.html index 70fad65..1246b59 100644 --- a/test/testInlineStylesheets/index.html +++ b/test/testInlineStylesheets/index.html @@ -9,12 +9,17 @@ Incorrect syntax - Link tags with `rel="stylesheet"` should be replaced. - +Should also work with `rel=stylesheet` (no double quotes) + + Space between attributes is optional +Nesting + +Leading slashes are removed + From d47c25d10fd3c489f997182f5a9a050e922d8301 Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 3 May 2021 15:53:08 +0100 Subject: [PATCH 3/4] Handle missing double quotes also in scriptTags and inlineImages --- src/inlineImages.js | 2 +- src/inlineScriptTags.js | 2 +- test/testInlineImages/index.html | 2 ++ test/testInlineScriptTags/index.html | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/inlineImages.js b/src/inlineImages.js index 9b635fc..9a0eb55 100644 --- a/src/inlineImages.js +++ b/src/inlineImages.js @@ -4,7 +4,7 @@ const fs = require('fs').promises; const path = require('path'); let inlineImages = async htmlPath => { - const imgTagRegex = //; + const imgTagRegex = //; let html = await fs.readFile(htmlPath, 'utf8'); let matches = html.match(new RegExp(imgTagRegex, 'g')); if (!matches) diff --git a/src/inlineScriptTags.js b/src/inlineScriptTags.js index d19699b..3678a34 100644 --- a/src/inlineScriptTags.js +++ b/src/inlineScriptTags.js @@ -4,7 +4,7 @@ const fs = require('fs').promises; const path = require('path'); let inlineHtmlScripts = async htmlPath => { - const scriptTagRegex = /

line 3

+ + From b420631be6c9e02d08ee4a793f6f243e6b023b19 Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 3 May 2021 16:42:36 +0100 Subject: [PATCH 4/4] Remove leading slashes in scriptTags and inlineImages --- src/inlineImages.js | 2 +- src/inlineScriptTags.js | 2 +- test/testInlineImages/index.html | 2 ++ test/testInlineScriptTags/index.html | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/inlineImages.js b/src/inlineImages.js index 9a0eb55..b9af882 100644 --- a/src/inlineImages.js +++ b/src/inlineImages.js @@ -10,7 +10,7 @@ let inlineImages = async htmlPath => { if (!matches) return html; let imgPromises = matches - .map(imgTag => imgTag.match(imgTagRegex)[2]) + .map(imgTag => imgTag.match(imgTagRegex)[2].replace(/^\/+/, '')) .map(relImgPath => path.resolve(path.dirname(htmlPath), relImgPath)) .map(imgPath => fs.readFile(imgPath)); let i = 0; diff --git a/src/inlineScriptTags.js b/src/inlineScriptTags.js index 3678a34..81de5b6 100644 --- a/src/inlineScriptTags.js +++ b/src/inlineScriptTags.js @@ -10,7 +10,7 @@ let inlineHtmlScripts = async htmlPath => { if (!matches) return html; let scriptPromises = matches - .map(scriptTag => scriptTag.match(scriptTagRegex)[1]) + .map(scriptTag => scriptTag.match(scriptTagRegex)[1].replace(/^\/+/, '')) .map(relScriptPath => path.resolve(path.dirname(htmlPath), relScriptPath)) .map(scriptPath => fs.readFile(scriptPath, 'utf8')); let i = 0; diff --git a/test/testInlineImages/index.html b/test/testInlineImages/index.html index 3e2d339..1572ef0 100644 --- a/test/testInlineImages/index.html +++ b/test/testInlineImages/index.html @@ -3,3 +3,5 @@ + + diff --git a/test/testInlineScriptTags/index.html b/test/testInlineScriptTags/index.html index 47d7ede..7851c63 100644 --- a/test/testInlineScriptTags/index.html +++ b/test/testInlineScriptTags/index.html @@ -9,3 +9,5 @@

line 3

+ +