merge duplicate .markdown-body rules

This commit is contained in:
Sindre Sorhus 2014-06-22 18:56:54 +02:00
parent ce827dda3c
commit 209ee6dd9f
2 changed files with 25 additions and 20 deletions

View File

@ -2,6 +2,13 @@
font-family: sans-serif; font-family: sans-serif;
-ms-text-size-adjust: 100%; -ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
font: 13px Helvetica, arial, freesans, clean, sans-serif;
line-height: 1.4;
color: #333333;
font-size: 15px;
line-height: 1.7;
overflow: hidden;
word-wrap: break-word;
} }
.markdown-body a { .markdown-body a {
@ -52,15 +59,6 @@
padding: 0; padding: 0;
} }
.markdown-body {
font: 13px Helvetica, arial, freesans, clean, sans-serif;
line-height: 1.4;
}
.markdown-body {
color: #333333;
}
.markdown-body * { .markdown-body * {
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
@ -164,13 +162,6 @@
margin-bottom: 0; margin-bottom: 0;
} }
.markdown-body {
font-size: 15px;
line-height: 1.7;
overflow: hidden;
word-wrap: break-word;
}
.markdown-body>*:first-child { .markdown-body>*:first-child {
margin-top: 0 !important; margin-top: 0 !important;
} }

View File

@ -40,6 +40,7 @@ function getRenderedFixture(cb) {
function cleanupCss(str) { function cleanupCss(str) {
var css = require('css'); var css = require('css');
var style = css.parse(str); var style = css.parse(str);
var mdBodyProps = [];
style.stylesheet.rules = style.stylesheet.rules.filter(function (el) { style.stylesheet.rules = style.stylesheet.rules.filter(function (el) {
if (el.type === 'keyframes' || el.type === 'comment') { if (el.type === 'keyframes' || el.type === 'comment') {
@ -60,10 +61,6 @@ function cleanupCss(str) {
}); });
} }
if (el.declarations.length === 0) {
return false;
}
el.selectors = el.selectors.map(function (selector) { el.selectors = el.selectors.map(function (selector) {
if (/^(?:body|html)$/.test(selector)) { if (/^(?:body|html)$/.test(selector)) {
selector = '.markdown-body'; selector = '.markdown-body';
@ -76,9 +73,26 @@ function cleanupCss(str) {
return selector; return selector;
}); });
if (el.declarations.length === 0) {
return false;
}
// collect `.markdown-body` rules
if (el.selectors.length === 1 && el.selectors[0] === '.markdown-body') {
[].push.apply(mdBodyProps, el.declarations);
return false;
}
return true; return true;
}); });
// merge `.markdown-body` rules
style.stylesheet.rules.unshift({
type: 'rule',
selectors: ['.markdown-body'],
declarations: mdBodyProps
});
return css.stringify(style); return css.stringify(style);
} }