Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/tasks/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 changes: 1 addition & 1 deletion test/fixtures/import-from-google.result.html
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions test/fixtures/link-media-query-1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title1 {
left: 1px;
}
3 changes: 3 additions & 0 deletions test/fixtures/link-media-query-2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title2 {
left: 2px;
}
1 change: 1 addition & 0 deletions test/fixtures/link-media-query.result.html
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions test/fixtures/link-media-query.src.html
Original file line number Diff line number Diff line change
@@ -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>