Skip to content
Closed
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
5 changes: 5 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const cli = meow(
rootSelector: {
type: 'string',
},
include: {
type: 'boolean',
},
useFixture: {
type: 'boolean',
default: true,
Expand All @@ -90,6 +93,7 @@ const {
onlyStyle,
onlyVariables,
rootSelector,
include,
useFixture,
} = cli.flags;

Expand Down Expand Up @@ -146,6 +150,7 @@ console.log(
onlyStyles: onlyStyle,
onlyVariables,
rootSelector,
include,
useFixture,
}),
);
12 changes: 12 additions & 0 deletions include.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root_selector {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
root_selector {
padding: 15px;
}
}
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'node:fs';
import postcss from 'postcss';
import {cachedFetch, getUniqueClasses, renderMarkdown, reverseUnique, unique, zip} from './utilities.js';
import {ALLOW_CLASS, ALLOW_TAGS, manuallyAddedStyle} from './constants.js';
Expand Down Expand Up @@ -241,6 +242,7 @@ export default async function getCSS({
onlyStyles = false,
useFixture = true,
rootSelector = '.markdown-body',
include = false,
} = {}) {
if (onlyVariables && onlyStyles) {
// Would result in an empty output
Expand Down Expand Up @@ -426,5 +428,15 @@ export default async function getCSS({
string = string.replaceAll('.markdown-body', rootSelector);
}

if (include) {
try {
const includeCss = fs.readFileSync(new URL('include.css', import.meta.url), 'utf8');
const processedIncludeCss = includeCss.replaceAll('root_selector', rootSelector);
string = processedIncludeCss + string;
} catch {
// If include.css doesn't exist, continue without it
}
}

return string;
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"cli.js",
"utilities.js",
"constants.js",
"fixture.md"
"fixture.md",
"include.css"
],
"keywords": [
"cli-app",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ $ github-markdown-css --help
--only-variables Only output the variables for the specified themes
--no-use-fixture Exclude generated classes that come from GitHub Markdown API rendered fixture.md
--root-selector Specify the root selector when outputting styles, default '.markdown-body'
--include Prepends base styling and responsive padding

Examples
$ github-markdown-css --list
Expand Down