mirror of
https://github.com/remy/inliner.git
synced 2024-09-11 17:25:30 +03:00
feat: preserve media query from link tag to style tag
This commit is contained in:
parent
df3619f89b
commit
fc5708f249
@ -6,6 +6,7 @@ function resolve(inliner, todo, $) {
|
||||
debug('start %s links', todo.length);
|
||||
return todo.map(function links(link) {
|
||||
var url = $(link).attr('href');
|
||||
var media_query = $(link).attr('media');
|
||||
if (inliner.options.skipAbsoluteUrls &&
|
||||
(url.indexOf('//') === 0 || url.indexOf('http') === 0)) {
|
||||
debug('skipping remote links');
|
||||
@ -22,7 +23,11 @@ function resolve(inliner, todo, $) {
|
||||
return inliner.cssImports(url, css)
|
||||
.then(inliner.cssImages.bind(inliner, url));
|
||||
}).then(function then(css) {
|
||||
$(link).replaceWith('<style>' + css + '</style>');
|
||||
if(media_query) {
|
||||
$(link).replaceWith('<style media="' + media_query + '">' + css + '</style>');
|
||||
} else {
|
||||
$(link).replaceWith('<style>' + css + '</style>');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
2
test/fixtures/import-from-google.result.html
vendored
2
test/fixtures/import-from-google.result.html
vendored
@ -1 +1 @@
|
||||
<style> @font-face{ font-family:'PT Sans';font-style:normal;font-weight:400;src:local('PT Sans'), local('PTSans-Regular'), format('woff2');unicode-range:U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;}@font-face{ font-family:'PT Sans';font-style:normal;font-weight:400;src:local('PT Sans'), local('PTSans-Regular'), format('woff2');unicode-range:U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;}html{ font-family:"PT Sans",courier;font-size:14px;}</style>
|
||||
<style media="all"> @font-face{ font-family:'PT Sans';font-style:normal;font-weight:400;src:local('PT Sans'), local('PTSans-Regular'), format('woff2');unicode-range:U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;}@font-face{ font-family:'PT Sans';font-style:normal;font-weight:400;src:local('PT Sans'), local('PTSans-Regular'), format('woff2');unicode-range:U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;}html{ font-family:"PT Sans",courier;font-size:14px;}</style>
|
||||
|
3
test/fixtures/link-media-query-1.css
vendored
Normal file
3
test/fixtures/link-media-query-1.css
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.title1 {
|
||||
left: 1px;
|
||||
}
|
3
test/fixtures/link-media-query-2.css
vendored
Normal file
3
test/fixtures/link-media-query-2.css
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.title2 {
|
||||
left: 2px;
|
||||
}
|
1
test/fixtures/link-media-query.result.html
vendored
Normal file
1
test/fixtures/link-media-query.result.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html> <html> <head> <title>link tag's media query to style tag</title> <style media="screen and (max-width:480px)">.title1{ left:1px;}</style> <style>.title2{ left:2px;}</style> </head> <body> </body> </html>
|
11
test/fixtures/link-media-query.src.html
vendored
Normal file
11
test/fixtures/link-media-query.src.html
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>link tag's media query to style tag</title>
|
||||
<link href="link-media-query-1.css" rel="stylesheet" type="text/css" media="screen and (max-width:480px)" />
|
||||
<link href="link-media-query-2.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user