在 github.com 上使用 README.md

我不太熟悉 github 在更新 README 文件时使用的轻量级标记语言。

哪里有我可以阅读的关于如何为我的开源库的 README/wiki 文件编写适当的标记语法的资源?

有没有一个工具,我可以“检查我的文档本地在我的浏览器”之前推更新的 README 到我的 github 存储库?

77242 次浏览

The markup in question is coincidentally called Markdown, created by John Gruber, author of the Daring Fireball blog. The original source of Markdown can be found at Daring Fireball - Markdown.

There are many Markdown dialects, the documentation for Github's can be found on the Github Flavored Markdown page.

nice tip from that page:

press M on any Github page with a Markdown editor to reveal the cheatsheet.

You can also use the Github Markdown Live Preview page to test your Markdown documents.

Update 2012-11-08: Efforts are underway to standardize the Markdown syntax. See The Future of Markdown - Jeff Atwood, Coding Horror and W3C Markdown Community Group.

Update 2014-09-09: CommonMark a markdown standard and spec has been released.

Note that since February 2014, with "Rendered Prose Diffs", you also can see the rendered version of a diff on a markdown file:

Commits and pull requests including prose files now feature source and rendered views.

https://f.cloud.github.com/assets/17715/1999080/7f0c15a2-853e-11e3-95dc-1d7737e1ec20.png

Non-text changes appear with a low-key dotted underline. Hover over the text to see what has changed:

https://f.cloud.github.com/assets/17715/2005588/714cb5ea-86ef-11e3-9e92-a0d11ba6084f.png

I didn't find that the other tools were good enough - I wanted:

  1. Ability to edit offline
  2. Not just regular markdown, but the actual Github flavored markdown

This is what I ultimately settled on: https://github.com/ypocat/gfms

> gfms


Github Flavored Markdown Server.
Run in your project's root directory.
Usage: gfms


Options:
-p, --port              Port number to listen at.        [required]
-h, --host              Host address to bind to.         [default: "localhost"]
--proxy                 if behind a proxy, proxy url.
-a, --api               Render using Github API.
-n, --no-api-on-reload  Disable usage of Github API when the doc is manually reloaded.

So I've aliased:

alias gm='gfms -a -p 8070'

Using the -p option hits the Github API and uses the actual, current Github CSS so there aren't any surprises.

Another option - Github's new text editor, Atom, will render github-flavoured markdown as you edit it. See https://atom.io/

I'm not sure whether it will be free (as in beer) in the long term.

There's a nice online/live editor here:

http://jbt.github.io/markdown-editor/

There's also a Preview button at GitHub.

See in the following screenshot that this button appears when I clicked Edit on README.md.

enter image description here

IMHO the live editor is better than the current one available at GitHub.

UPDATE

Just now I found after searching for Markdown and Visual Studio that if you're using VS, you can install Web Essentials and have Markdown support right from within Visual Studio. That's cool!

It has:

  • Syntax highlighting => Full colorization for Markdown syntax
  • Intellisense for embedded languages (W00T) => GitHub's embedded language feature is fully support by support for the ```language syntax.

enter image description here

  • Preview window => See a side-by-side preview window of the rendered HTML
  • Compile to HTML => Right-click any Markdown file and select Compile Markdown to HTML. This will generate a .html file nested under the Markdown file and it will stay in sync as the Markdown file changes.
  • Custom Stylesheet => You can add a solution specific Stylesheet to control the styles of the preview window.

Details about it here.

(Re-posting this answer with some edits.)

A little late to the game, but I wrote a small CLI in Python. It's called Grip (Github Readme Instant Preview). Adding on to Patrick's answer, this will let you "review my docs locally in my browser."

Install it with:

$ pip install grip

And to use it, simply:

$ grip

Then visit localhost:5000 to view the readme.md file at that location.

You can also specify your own file:

$ grip CHANGES.md

And change the port:

$ grip 8080

Or combine the previous two:

$ grip CHANGES.md 8080

You can even render GitHub-Flavored Markdown (i.e. how comments and issues are rendered), optionally with repo context to auto-hyperlink references to other issues:

$ grip --gfm --context=username/repo issue.md

For brevity, see the rest of the options and their details using the CLI help:

$ grip -h

Notable features:

  • Renders pages to appear exactly like on GitHub
  • Fenced blocks
  • Python API
  • Navigate between linked files
  • Export a rendered document to a file

Hope this helps. Check it out.

As of today, you can preview, as you edit the file.

enter image description here