-
Notifications
You must be signed in to change notification settings - Fork 7
Add inline stylesheets #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
693aa4c
Add inline stylesheets
simonewebdesign e58c019
Change mode of cli files
simonewebdesign ea80957
Allow dash in inlineRequires and inlineScriptTags
simonewebdesign f1fa85f
Change attribute order
simonewebdesign 086b9f7
Update readme.md
simonewebdesign f209d17
Changes to inlineStylesheets
simonewebdesign 93afc23
Polish test html
simonewebdesign fe1e701
Stronger regex to match stylesheets
simonewebdesign d476ffe
Fix the test for inlineScriptTags
simonewebdesign ea8aa3d
Update test for inline-stylesheets
simonewebdesign File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
const wrapper = require('./wrapper'); | ||
const script = require('../inlineStylesheets'); | ||
|
||
wrapper(script); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs').promises; | ||
const path = require('path'); | ||
|
||
let inlineHtmlStyles = async htmlPath => { | ||
const linkTagRegex = /<link (?:.* )?rel="stylesheet"(?:.* )?href="([\w.\-\/]+)".*>|<link (?:.* )?href="([\w.\-\/]+)"(?:.* )?rel="stylesheet".*>/; | ||
let html = await fs.readFile(htmlPath, 'utf8'); | ||
let stylesheetPromises = html | ||
.match(new RegExp(linkTagRegex, 'g')) | ||
.map(linkTag => { | ||
let m = linkTag.match(linkTagRegex); | ||
return m[1] || m[2]; | ||
}) | ||
.map(relPath => path.resolve(path.dirname(htmlPath), relPath)) | ||
.map(stylesheetPath => fs.readFile(stylesheetPath, 'utf8')); | ||
let i = 0; | ||
return Promise.all(stylesheetPromises).then(stylesheets => | ||
html.replace(new RegExp(linkTagRegex, 'g'), () => | ||
`<style>${stylesheets[i++]}</style>`)); | ||
}; | ||
|
||
module.exports = inlineHtmlStyles; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
<p>Welcome</p> | ||
<p>hi from index.html</p> | ||
|
||
<script src="main.js"></script> | ||
<script src="myScript.js"></script> | ||
|
||
<p>line 2</p> | ||
|
||
<script src="nested/myNestedScript.js"></script> | ||
|
||
<p>line 3</p> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Link tags without `rel="stylesheet"` should not be replaced. | ||
|
||
Not a stylesheet | ||
<link href="/author.html" rel="author"> | ||
|
||
Missing rel attribute | ||
<link href="myStyle.css"> | ||
|
||
Incorrect syntax | ||
<linkrel="stylesheet" href="myStyle.css"> | ||
|
||
|
||
Link tags with `rel="stylesheet"` should be replaced. | ||
|
||
<link href="myStyle.css" rel="stylesheet"> | ||
|
||
Space between attributes is optional | ||
<link rel="stylesheet"href="myStyle.css"> | ||
|
||
<link href="nested/myNestedStylesheet.css" rel="stylesheet" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p { | ||
background: red; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p { | ||
color: green; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.