This commit is contained in:
Sindre Sorhus 2014-05-07 20:02:46 +02:00
commit 4c84b3ca10
17 changed files with 1459 additions and 0 deletions

16
.editorconfig Normal file
View File

@ -0,0 +1,16 @@
# editorconfig.org
root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[package.json]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

19
.jshintrc Normal file
View File

@ -0,0 +1,19 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true
}

6
.travis.yml Normal file
View File

@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.10'
branches:
only:
- gh-pages

25
bower.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "github-markdown-css",
"description": "The minimal amount of CSS to replicate the GitHub Markdown style",
"license": "MIT",
"main": "github-markdown.css",
"keywords": [
"github",
"markdown",
"md",
"css",
"style",
"stylesheet"
],
"ignore": [
"**/.*",
"component.json",
"package.json",
"test.js",
"index.js",
"cli.js",
"index.html",
"screenshot.png",
"fixture.md"
]
}

30
cli.js Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env node
'use strict';
var pkg = require('./package.json');
var githubMarkdownCss = require('./index');
var input = process.argv[2];
function help() {
console.log(pkg.description);
console.log('');
console.log('Usage');
console.log(' $ github-markdown-css > <filename>');
}
if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) {
help();
return;
}
if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
githubMarkdownCss(function (err, css) {
if (err) {
throw err;
}
console.log(css);
});

18
component.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "github-markdown-css",
"version": "0.0.0",
"description": "The minimal amount of CSS to replicate the GitHub Markdown style",
"license": "MIT",
"repository": "sindresorhus/github-markdown-css",
"styles": [
"github-markdown.css"
],
"keywords": [
"github",
"markdown",
"md",
"css",
"style",
"stylesheet"
]
}

392
fixture.md Normal file
View File

@ -0,0 +1,392 @@
Borrowed from https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
---
This is intended as a quick reference and showcase. For more complete info, see [John Gruber's original spec](http://daringfireball.net/projects/markdown/) and the [Github-flavored Markdown info page](http://github.github.com/github-flavored-markdown/).
Note that there is also a [Cheatsheet specific to Markdown Here](./Markdown-Here-Cheatsheet) if that's what you're looking for.
PLEASE DO NOT EDIT THIS PAGE! You can play around with Markdown on our [live demo page](http://www.markdown-here.com/livedemo.html).
##### Table of Contents
[Headers](#headers)
[Emphasis](#emphasis)
[Lists](#lists)
[Links](#links)
[Images](#images)
[Code and Syntax Highlighting](#code)
[Tables](#tables)
[Blockquotes](#blockquotes)
[Inline HTML](#html)
[Horizontal Rule](#hr)
[Line Breaks](#lines)
[Youtube videos](#videos)
<a name="headers"/>
## Headers
```no-highlight
# H1
## H2
### H3
#### H4
##### H5
###### H6
Alternatively, for H1 and H2, an underline-ish style:
Alt-H1
======
Alt-H2
------
```
# H1
## H2
### H3
#### H4
##### H5
###### H6
Alternatively, for H1 and H2, an underline-ish style:
Alt-H1
======
Alt-H2
------
<a name="emphasis"/>
## Emphasis
```no-highlight
Emphasis, aka italics, with *asterisks* or _underscores_.
Strong emphasis, aka bold, with **asterisks** or __underscores__.
Combined emphasis with **asterisks and _underscores_**.
Strikethrough uses two tildes. ~~Scratch this.~~
```
Emphasis, aka italics, with *asterisks* or _underscores_.
Strong emphasis, aka bold, with **asterisks** or __underscores__.
Combined emphasis with **asterisks and _underscores_**.
Strikethrough uses two tildes. ~~Scratch this.~~
<a name="lists"/>
## Lists
(In this example, leading and trailing spaces are shown with with dots: ⋅)
```no-highlight
1. First ordered list item
2. Another item
⋅⋅* Unordered sub-list.
1. Actual numbers don't matter, just that it's a number
⋅⋅1. Ordered sub-list
4. And another item.
⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅
⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅
⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
* Unordered list can use asterisks
- Or minuses
+ Or pluses
```
1. First ordered list item
2. Another item
* Unordered sub-list.
1. Actual numbers don't matter, just that it's a number
1. Ordered sub-list
4. And another item.
You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
To have a line break without a paragraph, you will need to use two trailing spaces.
Note that this line is separate, but within the same paragraph.
(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
* Unordered list can use asterisks
- Or minuses
+ Or pluses
<a name="links"/>
## Links
There are two ways to create links.
```no-highlight
[I'm an inline-style link](https://www.google.com)
[I'm an inline-style link with title](https://www.google.com "Google's Homepage")
[I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](../blob/master/LICENSE)
[You can use numbers for reference-style link definitions][1]
Or leave it empty and use the [link text itself]
Some text to show that the reference links can follow later.
[arbitrary case-insensitive reference text]: https://www.mozilla.org
[1]: http://slashdot.org
[link text itself]: http://www.reddit.com
```
[I'm an inline-style link](https://www.google.com)
[I'm an inline-style link with title](https://www.google.com "Google's Homepage")
[I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](../blob/master/LICENSE)
[You can use numbers for reference-style link definitions][1]
Or leave it empty and use the [link text itself]
Some text to show that the reference links can follow later.
[arbitrary case-insensitive reference text]: https://www.mozilla.org
[1]: http://slashdot.org
[link text itself]: http://www.reddit.com
<a name="images"/>
## Images
```no-highlight
Here's our logo (hover to see the title text):
Inline-style:
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
Reference-style:
![alt text][logo]
[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
```
Here's our logo (hover to see the title text):
Inline-style:
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
Reference-style:
![alt text][logo]
[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2"
<a name="code"/>
## Code and Syntax Highlighting
Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and *Markdown Here* -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. *Markdown Here* supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html).
```no-highlight
Inline `code` has `back-ticks around` it.
```
Inline `code` has `back-ticks around` it.
Blocks of code are either fenced by lines with three back-ticks <code>```</code>, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.
<pre lang="no-highlight"><code>```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```
```python
s = "Python syntax highlighting"
print s
```
```
No language indicated, so no syntax highlighting.
But let's throw in a &lt;b&gt;tag&lt;/b&gt;.
```
</code></pre>
```javascript
var s = "JavaScript syntax highlighting";
alert(s);
```
```python
s = "Python syntax highlighting"
print s
```
```
No language indicated, so no syntax highlighting in Markdown Here (varies on Github).
But let's throw in a <b>tag</b>.
```
<a name="tables"/>
## Tables
Tables aren't part of the core Markdown spec, but they are part of GFM and *Markdown Here* supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.
```no-highlight
Colons can be used to align columns.
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | |
| col 2 is | centered | |
| zebra stripes | are neat | |
The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3
```
Colons can be used to align columns.
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | |
| col 2 is | centered | |
| zebra stripes | are neat | |
The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.
Markdown | Less | Pretty
--- | --- | ---
*Still* | `renders` | **nicely**
1 | 2 | 3
<a name="blockquotes"/>
## Blockquotes
```no-highlight
> Blockquotes are very handy in email to emulate reply text.
> This line is part of the same quote.
Quote break.
> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
```
> Blockquotes are very handy in email to emulate reply text.
> This line is part of the same quote.
Quote break.
> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
<a name="html"/>
## Inline HTML
You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
```no-highlight
<dl>
<dt>Definition list</dt>
<dd>Is something people use sometimes.</dd>
<dt>Markdown in HTML</dt>
<dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
</dl>
```
<dl>
<dt>Definition list</dt>
<dd>Is something people use sometimes.</dd>
<dt>Markdown in HTML</dt>
<dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
</dl>
<a name="hr"/>
## Horizontal Rule
```
Three or more...
---
Hyphens
***
Asterisks
___
Underscores
```
Three or more...
---
Hyphens
***
Asterisks
___
Underscores
<a name="lines"/>
## Line Breaks
My basic recommendation for learning how line breaks work is to experiment and discover -- hit &lt;Enter&gt; once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.
Here are some things to try out:
```
Here's a line for us to start with.
This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
This line is also a separate paragraph, but...
This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
```
Here's a line for us to start with.
This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
This line is also begins a separate paragraph, but...
This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
(Technical note: *Markdown Here* uses GFM line breaks, so there's no need to use MD's two-space line breaks.)
<a name="videos"/>
## Youtube videos
They can't be added directly but you can add an image with a link to the video like this:
```no-highlight
<a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
" target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a>
```
Or, in pure Markdown, but losing the image sizing and border:
```no-highlight
[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
```
Referencing a bug by #bugID in your git commit links it to the slip. For example #1.

663
github-markdown.css Normal file
View File

@ -0,0 +1,663 @@
article {
display: block;
}
html {
font-family: sans-serif;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
}
a:focus {
outline: thin dotted;
}
a:active,
a:hover {
outline: 0;
}
h1 {
font-size: 2em;
margin: .67em 0;
}
strong {
font-weight: bold;
}
hr {
-moz-box-sizing: content-box;
box-sizing: content-box;
height: 0;
}
code,
pre {
font-family: monospace, serif;
font-size: 1em;
}
img {
border: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
body {
font: 13px Helvetica, arial, freesans, clean, sans-serif;
line-height: 1.4;
}
body {
min-width: 1020px;
color: #333333;
background-color: #fff;
}
* {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
::-moz-selection {
text-shadow: none;
background: rgba(65,131,196,0.4);
}
::selection {
text-shadow: none;
background: rgba(65,131,196,0.4);
}
a {
color: #4183c4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:focus,
a:active {
text-decoration: underline;
}
hr {
height: 0;
margin: 15px 0;
overflow: hidden;
background: transparent;
border: 0;
border-bottom: 1px solid #ddd;
}
hr:before,
hr:after {
content: " ";
display: table;
}
hr:after {
clear: both;
}
ol ol {
list-style-type: lower-roman;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 15px;
margin-bottom: 15px;
line-height: 1.1;
}
h1 {
font-size: 30px;
}
h2 {
font-size: 21px;
}
h3 {
font-size: 16px;
}
h4 {
font-size: 14px;
}
h5 {
font-size: 12px;
}
h6 {
font-size: 11px;
}
blockquote {
margin: 0;
}
ul,
ol {
padding: 0;
margin-top: 0;
margin-bottom: 0;
}
dd {
margin-left: 0;
}
code,
pre {
font-family: Consolas, "Liberation Mono", Courier, monospace;
font-size: 12px;
}
pre {
margin-top: 0;
margin-bottom: 0;
}
.markdown-body {
font-size: 15px;
line-height: 1.7;
overflow: hidden;
word-wrap: break-word;
}
.markdown-body>*:first-child {
margin-top: 0 !important;
}
.markdown-body>*:last-child {
margin-bottom: 0 !important;
}
.markdown-body a.anchor {
display: block;
padding-right: 6px;
padding-left: 30px;
margin-left: -30px;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
bottom: 0;
}
.markdown-body a.anchor:focus {
outline: none;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin: 1em 0 15px;
padding: 0;
font-weight: bold;
line-height: 1.7;
cursor: text;
position: relative;
}
.markdown-body h1 {
font-size: 2.5em;
border-bottom: 1px solid #ddd;
}
.markdown-body h2 {
font-size: 2em;
border-bottom: 1px solid #eee;
}
.markdown-body h3 {
font-size: 1.5em;
}
.markdown-body h4 {
font-size: 1.2em;
}
.markdown-body h5 {
font-size: 1em;
}
.markdown-body h6 {
color: #777;
font-size: 1em;
}
.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre {
margin: 15px 0;
}
.markdown-body hr {
background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAECAYAAACtBE5DAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OENDRjNBN0E2NTZBMTFFMEI3QjRBODM4NzJDMjlGNDgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OENDRjNBN0I2NTZBMTFFMEI3QjRBODM4NzJDMjlGNDgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4Q0NGM0E3ODY1NkExMUUwQjdCNEE4Mzg3MkMyOUY0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4Q0NGM0E3OTY1NkExMUUwQjdCNEE4Mzg3MkMyOUY0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqqezsUAAAAfSURBVHjaYmRABcYwBiM2QSA4y4hNEKYDQxAEAAIMAHNGAzhkPOlYAAAAAElFTkSuQmCC) repeat-x 0 0;
border: 0 none;
color: #ccc;
height: 4px;
padding: 0;
margin: 15px 0;
}
.markdown-body ul,
.markdown-body ol {
padding-left: 30px;
}
.markdown-body ol ol,
.markdown-body ol ul {
margin-top: 0;
margin-bottom: 0;
}
.markdown-body dl {
padding: 0;
}
.markdown-body dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin-top: 15px;
}
.markdown-body dl dd {
margin-bottom: 15px;
padding: 0 15px;
}
.markdown-body blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}
.markdown-body blockquote>:first-child {
margin-top: 0px;
}
.markdown-body blockquote>:last-child {
margin-bottom: 0px;
}
.markdown-body table {
width: 100%;
overflow: auto;
display: block;
}
.markdown-body table th {
font-weight: bold;
}
.markdown-body table th,
.markdown-body table td {
border: 1px solid #ddd;
padding: 6px 13px;
}
.markdown-body table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}
.markdown-body table tr:nth-child(2n) {
background-color: #f8f8f8;
}
.markdown-body img {
max-width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.markdown-body code {
margin: 0;
border: 1px solid #ddd;
background-color: #f8f8f8;
border-radius: 3px;
padding: 0;
}
.markdown-body code:before,
.markdown-body code:after {
content: "\00a0";
letter-spacing: -0.2em;
}
.markdown-body pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}
.markdown-body .highlight pre,
.markdown-body pre {
background-color: #f8f8f8;
border: 1px solid #ddd;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}
.markdown-body pre {
word-wrap: normal;
}
.markdown-body pre code {
margin: 0;
padding: 0;
background-color: transparent;
border: none;
word-wrap: normal;
max-width: initial;
display: inline;
overflow: initial;
line-height: inherit;
}
.markdown-body pre code:before,
.markdown-body pre code:after {
content: normal;
}
.highlight {
background: #ffffff;
}
.highlight .c {
color: #999988;
font-style: italic;
}
.highlight .err {
color: #a61717;
background-color: #e3d2d2;
}
.highlight .k {
font-weight: bold;
}
.highlight .o {
font-weight: bold;
}
.highlight .cm {
color: #999988;
font-style: italic;
}
.highlight .cp {
color: #999999;
font-weight: bold;
}
.highlight .c1 {
color: #999988;
font-style: italic;
}
.highlight .cs {
color: #999999;
font-weight: bold;
font-style: italic;
}
.highlight .gd {
color: #000000;
background-color: #ffdddd;
}
.highlight .gd .x {
color: #000000;
background-color: #ffaaaa;
}
.highlight .ge {
font-style: italic;
}
.highlight .gr {
color: #aa0000;
}
.highlight .gh {
color: #999999;
}
.highlight .gi {
color: #000000;
background-color: #ddffdd;
}
.highlight .gi .x {
color: #000000;
background-color: #aaffaa;
}
.highlight .go {
color: #888888;
}
.highlight .gp {
color: #555555;
}
.highlight .gs {
font-weight: bold;
}
.highlight .gu {
color: #800080;
font-weight: bold;
}
.highlight .gt {
color: #aa0000;
}
.highlight .kc {
font-weight: bold;
}
.highlight .kd {
font-weight: bold;
}
.highlight .kn {
font-weight: bold;
}
.highlight .kp {
font-weight: bold;
}
.highlight .kr {
font-weight: bold;
}
.highlight .kt {
color: #445588;
font-weight: bold;
}
.highlight .m {
color: #009999;
}
.highlight .s {
color: #dd1144;
}
.highlight .n {
color: #333333;
}
.highlight .na {
color: teal;
}
.highlight .nb {
color: #0086b3;
}
.highlight .nc {
color: #445588;
font-weight: bold;
}
.highlight .no {
color: teal;
}
.highlight .ni {
color: purple;
}
.highlight .ne {
color: #990000;
font-weight: bold;
}
.highlight .nf {
color: #990000;
font-weight: bold;
}
.highlight .nn {
color: #555555;
}
.highlight .nt {
color: navy;
}
.highlight .nv {
color: teal;
}
.highlight .ow {
font-weight: bold;
}
.highlight .w {
color: #bbbbbb;
}
.highlight .mf {
color: #009999;
}
.highlight .mh {
color: #009999;
}
.highlight .mi {
color: #009999;
}
.highlight .mo {
color: #009999;
}
.highlight .sb {
color: #dd1144;
}
.highlight .sc {
color: #dd1144;
}
.highlight .sd {
color: #dd1144;
}
.highlight .s2 {
color: #dd1144;
}
.highlight .se {
color: #dd1144;
}
.highlight .sh {
color: #dd1144;
}
.highlight .si {
color: #dd1144;
}
.highlight .sx {
color: #dd1144;
}
.highlight .sr {
color: #009926;
}
.highlight .s1 {
color: #dd1144;
}
.highlight .ss {
color: #990073;
}
.highlight .bp {
color: #999999;
}
.highlight .vc {
color: teal;
}
.highlight .vg {
color: teal;
}
.highlight .vi {
color: teal;
}
.highlight .il {
color: #009999;
}
.highlight .gc {
color: #999;
background-color: #EAF2F5;
}

42
index.html Normal file
View File

@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
<title>GitHub Markdown CSS demo</title>
<link rel="stylesheet" href="github-markdown.css">
<style>
body {
min-width: 200px !important;
max-width: 790px !important;
margin: 0 auto !important;
padding: 20px !important;
}
</style>
</head>
<body>
<article class="markdown-body">
<h1>GitHub Markdown CSS demo</h1>
<blockquote>
<p>Bacon ipsum dolor sit amet filet mignon ribeye swine jerky porchetta beef ribs.</p>
</blockquote>
<p>Bacon pastrami ham hock tongue t-bone, <code>ham shankle</code> capicola biltong fatback shoulder pork tenderloin boudin. Pastrami sausage short ribs, pig bacon shoulder biltong ham. Sausage shankle meatball pork loin, pancetta flank pork frankfurter pig pork chop ham hock chicken ribeye capicola.</p>
<ul>
<li>Foo</li>
<li>Bar</li>
</ul>
<h2>Header 2</h2>
<p>Swine short ribs turkey short loin doner pastrami biltong cow boudin. Kielbasa kevin turkey, landjaeger andouille chicken swine flank fatback frankfurter filet mignon spare ribs sausage porchetta shankle. Beef ribs tri-tip landjaeger turducken corned beef. Jerky meatloaf salami beef, beef ribs drumstick pork ribeye shankle strip steak pork chop. Meatloaf short ribs chicken strip steak bresaola ground round short loin ham leberkas turducken ball tip biltong turkey cow. Venison porchetta tail short ribs pastrami. Bresaola tail fatback drumstick kevin meatball pork loin.</p>
<div class="highlight highlight-js"><pre><span class="kd">var</span> <span class="nx">gulp</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'gulp'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">myth</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'gulp-myth'</span><span class="p">);</span>
<span class="nx">gulp</span><span class="p">.</span><span class="nx">task</span><span class="p">(</span><span class="s1">'default'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">gulp</span><span class="p">.</span><span class="nx">src</span><span class="p">(</span><span class="s1">'src/app.css'</span><span class="p">)</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span><span class="nx">myth</span><span class="p">())</span>
<span class="p">.</span><span class="nx">pipe</span><span class="p">(</span><span class="nx">gulp</span><span class="p">.</span><span class="nx">dest</span><span class="p">(</span><span class="s1">'dist'</span><span class="p">));</span>
<span class="p">});</span>
</pre></div>
</article>
</body>
</html>

82
index.js Normal file
View File

@ -0,0 +1,82 @@
'use strict';
var got = require('got');
var cheerio = require('cheerio');
var uncss = require('uncss');
var tempWrite = require('temp-write');
function getCss(cb) {
got('https://github.com', function (err, data) {
if (err) {
return cb(err);
}
var ret = [];
var $ = cheerio.load(data);
$('link[href*="assets/github"]').each(function (i, el) {
ret.push(el.attribs.href);
});
if (ret.length === 0) {
return cb(new Error('Could not find GitHub stylesheets'));
}
cb(null, ret);
});
}
function getRenderedFixture(cb) {
got('https://github.com/sindresorhus/github-markdown-css/blob/gh-pages/fixture.md', function (err, data) {
if (err) {
return cb(err);
}
var $ = cheerio.load(data);
cb(null, tempWrite.sync($('.markdown-body').parent().html()));
});
}
function cleanupCss(str) {
var css = require('css');
var style = css.parse(str);
style.stylesheet.rules = style.stylesheet.rules.filter(function (el) {
if (el.type === 'keyframes' || el.type === 'comment') {
return false;
}
if (el.type === 'rule' && /::-webkit-validation|:-moz-placeholder|^\.integrations-slide-content|^\.prose-diff|@font-face|^\.octicon|^button::|^\.markdown-body .+(:hover|\.octicon)/.test(el.selectors[0])) {
return false;
}
return true;
});
return css.stringify(style);
}
module.exports = function (cb) {
getRenderedFixture(function (err, fixture) {
if (err) {
return cb(err);
}
getCss(function (err, stylesheets) {
if (err) {
return cb(err);
}
uncss([fixture], {
stylesheets: stylesheets,
ignore: [/^\.highlight/]
}, function (err, css) {
if (err) {
throw err;
}
cb(null, cleanupCss(css));
});
});
});
};

21
license Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

46
package.json Normal file
View File

@ -0,0 +1,46 @@
{
"name": "github-markdown-css",
"version": "0.0.0",
"description": "The minimal amount of CSS to replicate the GitHub Markdown style",
"license": "MIT",
"repository": "sindresorhus/github-markdown-css",
"bin": {
"github-markdown-css": "cli.js"
},
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"files": [
"index.js",
"cli.js",
"github-markdown.css"
],
"keywords": [
"cli",
"bin",
"github",
"markdown",
"md",
"css",
"style",
"stylesheet"
],
"dependencies": {
"cheerio": "^0.15.0",
"css": "^1.6.0",
"got": "^0.2.0",
"temp-write": "^0.3.0",
"uncss": "^0.8.1"
},
"devDependencies": {
"mocha": "*"
}
}

84
readme.md Normal file
View File

@ -0,0 +1,84 @@
# github-markdown-css [![Build Status](https://travis-ci.org/sindresorhus/github-markdown-css.svg?branch=master)](https://travis-ci.org/sindresorhus/github-markdown-css)
> The minimal amount of CSS to replicate the GitHub Markdown style
[<img src="screenshot.png" width="400">](http://sindresorhus.com/github-markdown-css)
## [Demo](http://sindresorhus.com/github-markdown-css)
## How
First a [rendered Markdown](fixture.md) with all possible syntax is fetched from GitHub. Then the GitHub.com CSS is fetched and both are run through [UnCSS](https://github.com/giakki/uncss), which extracts only the used styles, and then through a custom cleanup.
## Install
Download [manually](https://raw.githubusercontent.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css) or with a package-manager.
```sh
$ npm install --save github-markdown-css
```
```sh
$ bower install --save github-markdown-css
```
```sh
$ component install sindresorhus/github-markdown-css
```
## Usage
Import the `github-markdown.css` file and add a `markdown-body` class to the container of your rendered Markdown and set a width for it. GitHub uses `720px` as width.
```html
<link rel="stylesheet" href="github-markdown.css">
<style>
.markdown-body {
width: 720px;
}
</style>
<article class="markdown-body">
<h1>Unicorns</h1>
<p>All the things</p>
</div>
```
## Programmatic usage
I will try to keep it up to date, but you're free to fetch the CSS yourself either through the API or CLI.
```js
var githubMarkdownCss = require('github-markdown-css');
githubMarkdownCss(function (err, css) {
if (err) {
throw err;
}
console.log(css);
//=> article { display: block; } ...
});
```
## CLI
```sh
$ npm install --global github-markdown-css
```
```sh
$ github-markdown-css --help
Usage
$ github-markdown-css > <filename>
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

13
test.js Normal file
View File

@ -0,0 +1,13 @@
'use strict';
var assert = require('assert');
var githubMarkdownCss = require('./index');
it('should get the GitHub Markdown CSS', function (cb) {
this.timeout(20000);
githubMarkdownCss(function (err, css) {
assert(!err, err);
assert(/markdown-body/.test(css));
cb();
});
});