8000 merge duplicate `.markdown-body` rules · lbarr/github-markdown-css@209ee6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 209ee6d

Browse files
committed
merge duplicate .markdown-body rules
1 parent ce827dd commit 209ee6d

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

github-markdown.css

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
font-family: sans-serif;
33
-ms-text-size-adjust: 100%;
44
-webkit-text-size-adjust: 100%;
5+
font: 13px Helvetica, arial, freesans, clean, sans-serif;
6+
line-height: 1.4;
7+
color: #333333;
8+
font-size: 15px;
9+
line-height: 1.7;
10+
overflow: hidden;
11+
word-wrap: break-word;
512
}
613

714
.markdown-body a {
@@ -52,15 +59,6 @@
5259
padding: 0;
5360
}
5461

55-
.markdown-body {
56-
font: 13px Helvetica, arial, freesans, clean, sans-serif;
57-
line-height: 1.4;
58-
}
59-
60-
.markdown-body {
61-
color: #333333;
62-
}
63-
6462
.markdown-body * {
6563
-moz-box-sizing: border-box;
6664
box-sizing: border-box;
@@ -164,13 +162,6 @@
164162
margin-bottom: 0;
165163
}
166164

167-
.markdown-body {
168-
font-size: 15px;
169-
line-height: 1.7;
170-
overflow: hidden;
171-
word-wrap: break-word;
172-
}
173-
174165
.markdown-body>*:first-child {
175166
margin-top: 0 !important;
176167
}

index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function getRenderedFixture(cb) {
4040
function cleanupCss(str) {
4141
var css = require('css');
4242
var style = css.parse(str);
43+
var mdBodyProps = [];
4344

4445
style.stylesheet.rules = style.stylesheet.rules.filter(function (el) {
4546
if (el.type === 'keyframes' || el.type === 'comment') {
@@ -60,10 +61,6 @@ function cleanupCss(str) {
6061
});
6162
}
6263

63-
if (el.declarations.length === 0) {
64-
return false;
65-
}
66-
6764
el.selectors = el.selectors.map(function (selector) {
6865
if (/^(?:body|html)$/.test(selector)) {
6966
selector = '.markdown-body';
@@ -76,9 +73,26 @@ function cleanupCss(str) {
7673
return selector;
7774
});
7875

76+
if (el.declarations.length === 0) {
77+
return false;
78+
}
79+
80+
// collect `.markdown-body` rules
81+
if (el.selectors.length === 1 && el.selectors[0] === '.markdown-body') {
82+
[].push.apply(mdBodyProps, el.declarations);
83+
return false;
84+
}
85+
7986
return true;
8087
});
8188

89+
// merge `.markdown-body` rules
90+
style.stylesheet.rules.unshift({
91+
type: 'rule',
92+
selectors: ['.markdown-body'],
93+
declarations: mdBodyProps
94+
});
95+
8296
return css.stringify(style);
8397
}
8498

0 commit comments

Comments
 (0)
0