jonkemp / inline-css

Inline css into an html file.
MIT License
429 stars 85 forks source link

Support extracting content from data url #94

Open ttimasdf opened 4 years ago

ttimasdf commented 4 years ago

Expected behaviour:

Extract CSS stylesheet data from base64 encoded string.

<link rel="stylesheet" type="text/css" href="data:text/css;base64,LyotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t"/>

I'm not familiar with JS so I'm not sure whether I'm using the right way to invoke callback function 😅 feel free to change the codes.

jonkemp commented 4 years ago

Hello @ttimasdf! I ask that you please read the contributing guidelines.

https://github.com/jonkemp/inline-css/blob/master/CONTRIBUTING.md#feature-requests

Specifically, this section:

Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible.

I have no idea if your pull request addresses a bug or is a feature request, so please ask first before making a pull request, or at least provide more context. Thank you!

ttimasdf commented 3 years ago

Sorry, I've been working on other projects that almost forgot this PR. I'll add some contexts. @jonkemp

I consider this PR a bug fix that it handles the case that the CSS data is embedded in the corresponding HTML tag.

The following file is an HTML page generated by VSCode Plugin Markdown Extended , from a markdown file with random content with a custom CSS theme.

Test.html.txt (Github is limiting file extension so remove .txt after downloads)

part of the file content as follows

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test.md</title>

<!-- official styles start -->
<!-- markdown.css -->
<link rel="stylesheet" type="text/css" href="data:text/css;base64,LyotLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0KICogIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLiBBbGwgcmlna
HRzIHJlc2VydmVkLgogKiAgTGljZW5zZ...

The current version will fail with some DNS related issues. Maybe it thinks data is a hostname. However, this is a valid stylesheet that could be parsed by any browser.

Error: getaddrinfo ENOTFOUND data
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'data',
  response: undefined
}