Skip to content

Commit b19ed0b

Browse files
authored
Fix task list style (#13)
1 parent 590af49 commit b19ed0b

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

fixture.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,3 +1733,7 @@ Hr's:
17331733
-oldCode()
17341734
+newCode()
17351735
```
1736+
1737+
footnotes[^1].
1738+
1739+
[^1]: hello world!.

index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const ALLOW_TAGS = new Set([
9696
'body',
9797
'html',
9898
'g-emoji',
99+
'input', // [type=checkbox], for task list
99100
]);
100101

101102
const ALLOW_CLASS = new Set([
@@ -104,6 +105,9 @@ const ALLOW_CLASS = new Set([
104105
'.highlight',
105106
'.octicon',
106107
'.octicon-link',
108+
'.contains-task-list',
109+
'.task-list-item',
110+
'.task-list-item-checkbox',
107111
]);
108112

109113
function extractStyles(styles, ast) {
@@ -134,14 +138,29 @@ function extractStyles(styles, ast) {
134138
return true;
135139
}
136140

141+
const klass = selector.match(/^\.[-\w]+/);
142+
if (klass) {
143+
return ALLOW_CLASS.has(klass[0]);
144+
}
145+
137146
return false;
138147
}
139148

149+
function fix(selector) {
150+
if (selector.startsWith('html ') || selector.startsWith('body ')) {
151+
return selector.slice(5);
152+
}
153+
154+
return selector;
155+
}
156+
140157
for (const rule of walkRules(ast)) {
141158
if (rule.declarations.some(({value}) => value.includes('prettylights'))) {
142159
styles.push(rule);
143160
} else {
144-
rule.selectors = rule.selectors.filter(selector => select(selector));
161+
rule.selectors = rule.selectors
162+
.filter(selector => select(selector))
163+
.map(selector => fix(selector));
145164
if (rule.selectors.length > 0) {
146165
styles.push(rule);
147166
}
@@ -259,7 +278,12 @@ async function getCSS({light = 'light', dark = 'dark', list = false} = {}) {
259278
let rules = [];
260279

261280
for (const [url, cssText] of zip(links, contents)) {
262-
const [name] = url.match(/(?<=\/)\w+(?=-\w+\.css$)/);
281+
const match = url.match(/(?<=\/)\w+(?=-\w+\.css$)/);
282+
if (!match) {
283+
continue;
284+
}
285+
286+
const [name] = match;
263287
const ast = css.parse(cssText);
264288

265289
if (/^(light|dark)/.test(name)) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
"meow": "^10.1.1"
4444
},
4545
"devDependencies": {
46-
"xo": "^0.45.0"
46+
"xo": "^0.46.4"
4747
}
4848
}

0 commit comments

Comments
 (0)