Skip to content
项目

sindresorhus/github-markdown-css

在 GitHub 查看

关于

用最少的 CSS 复现 GitHub Markdown 样式

网站与应用开发

这些数字如何统计

实测星标增长

24小时
+2
7天
+5
15天
+8
1个月
+11

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

github-markdown-css

The minimal amount of CSS to replicate the GitHub Markdown style

The CSS is generated. Contributions should go to this repo.

Demo

Install

Download manually, from CDNJS, or with npm:

npm install 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 980px width and 45px padding, and 15px padding for mobile.

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="github-markdown.css">
<style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}

	@media (prefers-color-scheme: dark) {
		body {
			background-color: #0d1117;
		}
	}
</style>
<article class="markdown-body">
	<h1>Unicorns</h1>
	<p>All the things</p>
</article>

You can use GitHub's /markdown API to turn Markdown into the HTML that GitHub generates, which works well with the CSS in this repo. Other Markdown parsers will mostly work with these styles too. To mimic how GitHub highlights code, you can use starry-night with your Markdown parser of choice.

There are 7 themes provided in this package:

  • github-markdown.css: (default) Automatically switches between light and dark through @media (prefers-color-scheme).
  • github-markdown-light.css: Light-only.
  • github-markdown-dark.css: Dark-only.
  • github-markdown-dark-dimmed.css: Dark dimmed.
  • github-markdown-dark-high-contrast.css: Dark high contrast.
  • github-markdown-dark-colorblind.css: Dark Protanopia & Deuteranopia.
  • github-markdown-light-colorblind.css: Light Protanopia & Deuteranopia.

How

See generate-github-markdown-css for how it's generated and ability to generate your own.

Troubleshooting

If you encounter styling issues, like tables in dark mode rendering their fonts in black, the browser might uses quirks mode by accident.

To avoid quirks mode, always include a doctype at the top of your page.

<!doctype html>
<html lang="en"><head></head><body></body></html>

Dev

Run npm run make to update the CSS.

探索相关项目

加载中…