Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. Blackfriday [![Build Status](https://travis-ci.org/russross/blackfriday.svg?branch=master)](https://travis-ci.org/russross/blackfriday)
  2. ===========
  3. Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It
  4. is paranoid about its input (so you can safely feed it user-supplied
  5. data), it is fast, it supports common extensions (tables, smart
  6. punctuation substitutions, etc.), and it is safe for all utf-8
  7. (unicode) input.
  8. HTML output is currently supported, along with Smartypants
  9. extensions. An experimental LaTeX output engine is also included.
  10. It started as a translation from C of [Sundown][3].
  11. Installation
  12. ------------
  13. Blackfriday is compatible with Go 1. If you are using an older
  14. release of Go, consider using v1.1 of blackfriday, which was based
  15. on the last stable release of Go prior to Go 1. You can find it as a
  16. tagged commit on github.
  17. With Go 1 and git installed:
  18. go get github.com/russross/blackfriday
  19. will download, compile, and install the package into your `$GOPATH`
  20. directory hierarchy. Alternatively, you can achieve the same if you
  21. import it into a project:
  22. import "github.com/russross/blackfriday"
  23. and `go get` without parameters.
  24. Usage
  25. -----
  26. For basic usage, it is as simple as getting your input into a byte
  27. slice and calling:
  28. output := blackfriday.MarkdownBasic(input)
  29. This renders it with no extensions enabled. To get a more useful
  30. feature set, use this instead:
  31. output := blackfriday.MarkdownCommon(input)
  32. ### Sanitize untrusted content
  33. Blackfriday itself does nothing to protect against malicious content. If you are
  34. dealing with user-supplied markdown, we recommend running blackfriday's output
  35. through HTML sanitizer such as
  36. [Bluemonday](https://github.com/microcosm-cc/bluemonday).
  37. Here's an example of simple usage of blackfriday together with bluemonday:
  38. ``` go
  39. import (
  40. "github.com/microcosm-cc/bluemonday"
  41. "github.com/russross/blackfriday"
  42. )
  43. // ...
  44. unsafe := blackfriday.MarkdownCommon(input)
  45. html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
  46. ```
  47. ### Custom options
  48. If you want to customize the set of options, first get a renderer
  49. (currently either the HTML or LaTeX output engines), then use it to
  50. call the more general `Markdown` function. For examples, see the
  51. implementations of `MarkdownBasic` and `MarkdownCommon` in
  52. `markdown.go`.
  53. You can also check out `blackfriday-tool` for a more complete example
  54. of how to use it. Download and install it using:
  55. go get github.com/russross/blackfriday-tool
  56. This is a simple command-line tool that allows you to process a
  57. markdown file using a standalone program. You can also browse the
  58. source directly on github if you are just looking for some example
  59. code:
  60. * <http://github.com/russross/blackfriday-tool>
  61. Note that if you have not already done so, installing
  62. `blackfriday-tool` will be sufficient to download and install
  63. blackfriday in addition to the tool itself. The tool binary will be
  64. installed in `$GOPATH/bin`. This is a statically-linked binary that
  65. can be copied to wherever you need it without worrying about
  66. dependencies and library versions.
  67. Features
  68. --------
  69. All features of Sundown are supported, including:
  70. * **Compatibility**. The Markdown v1.0.3 test suite passes with
  71. the `--tidy` option. Without `--tidy`, the differences are
  72. mostly in whitespace and entity escaping, where blackfriday is
  73. more consistent and cleaner.
  74. * **Common extensions**, including table support, fenced code
  75. blocks, autolinks, strikethroughs, non-strict emphasis, etc.
  76. * **Safety**. Blackfriday is paranoid when parsing, making it safe
  77. to feed untrusted user input without fear of bad things
  78. happening. The test suite stress tests this and there are no
  79. known inputs that make it crash. If you find one, please let me
  80. know and send me the input that does it.
  81. NOTE: "safety" in this context means *runtime safety only*. In order to
  82. protect yourself agains JavaScript injection in untrusted content, see
  83. [this example](https://github.com/russross/blackfriday#sanitize-untrusted-content).
  84. * **Fast processing**. It is fast enough to render on-demand in
  85. most web applications without having to cache the output.
  86. * **Thread safety**. You can run multiple parsers in different
  87. goroutines without ill effect. There is no dependence on global
  88. shared state.
  89. * **Minimal dependencies**. Blackfriday only depends on standard
  90. library packages in Go. The source code is pretty
  91. self-contained, so it is easy to add to any project, including
  92. Google App Engine projects.
  93. * **Standards compliant**. Output successfully validates using the
  94. W3C validation tool for HTML 4.01 and XHTML 1.0 Transitional.
  95. Extensions
  96. ----------
  97. In addition to the standard markdown syntax, this package
  98. implements the following extensions:
  99. * **Intra-word emphasis supression**. The `_` character is
  100. commonly used inside words when discussing code, so having
  101. markdown interpret it as an emphasis command is usually the
  102. wrong thing. Blackfriday lets you treat all emphasis markers as
  103. normal characters when they occur inside a word.
  104. * **Tables**. Tables can be created by drawing them in the input
  105. using a simple syntax:
  106. ```
  107. Name | Age
  108. --------|------
  109. Bob | 27
  110. Alice | 23
  111. ```
  112. * **Fenced code blocks**. In addition to the normal 4-space
  113. indentation to mark code blocks, you can explicitly mark them
  114. and supply a language (to make syntax highlighting simple). Just
  115. mark it like this:
  116. ``` go
  117. func getTrue() bool {
  118. return true
  119. }
  120. ```
  121. You can use 3 or more backticks to mark the beginning of the
  122. block, and the same number to mark the end of the block.
  123. * **Definition lists**. A simple definition list is made of a single-line
  124. term followed by a colon and the definition for that term.
  125. Cat
  126. : Fluffy animal everyone likes
  127. Internet
  128. : Vector of transmission for pictures of cats
  129. Terms must be separated from the previous definition by a blank line.
  130. * **Footnotes**. A marker in the text that will become a superscript number;
  131. a footnote definition that will be placed in a list of footnotes at the
  132. end of the document. A footnote looks like this:
  133. This is a footnote.[^1]
  134. [^1]: the footnote text.
  135. * **Autolinking**. Blackfriday can find URLs that have not been
  136. explicitly marked as links and turn them into links.
  137. * **Strikethrough**. Use two tildes (`~~`) to mark text that
  138. should be crossed out.
  139. * **Hard line breaks**. With this extension enabled (it is off by
  140. default in the `MarkdownBasic` and `MarkdownCommon` convenience
  141. functions), newlines in the input translate into line breaks in
  142. the output.
  143. * **Smart quotes**. Smartypants-style punctuation substitution is
  144. supported, turning normal double- and single-quote marks into
  145. curly quotes, etc.
  146. * **LaTeX-style dash parsing** is an additional option, where `--`
  147. is translated into `&ndash;`, and `---` is translated into
  148. `&mdash;`. This differs from most smartypants processors, which
  149. turn a single hyphen into an ndash and a double hyphen into an
  150. mdash.
  151. * **Smart fractions**, where anything that looks like a fraction
  152. is translated into suitable HTML (instead of just a few special
  153. cases like most smartypant processors). For example, `4/5`
  154. becomes `<sup>4</sup>&frasl;<sub>5</sub>`, which renders as
  155. <sup>4</sup>&frasl;<sub>5</sub>.
  156. Other renderers
  157. ---------------
  158. Blackfriday is structured to allow alternative rendering engines. Here
  159. are a few of note:
  160. * [github_flavored_markdown](https://godoc.org/github.com/shurcooL/github_flavored_markdown):
  161. provides a GitHub Flavored Markdown renderer with fenced code block
  162. highlighting, clickable header anchor links.
  163. It's not customizable, and its goal is to produce HTML output
  164. equivalent to the [GitHub Markdown API endpoint](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode),
  165. except the rendering is performed locally.
  166. * [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt,
  167. but for markdown.
  168. * LaTeX output: renders output as LaTeX. This is currently part of the
  169. main Blackfriday repository, but may be split into its own project
  170. in the future. If you are interested in owning and maintaining the
  171. LaTeX output component, please be in touch.
  172. It renders some basic documents, but is only experimental at this
  173. point. In particular, it does not do any inline escaping, so input
  174. that happens to look like LaTeX code will be passed through without
  175. modification.
  176. Todo
  177. ----
  178. * More unit testing
  179. * Improve unicode support. It does not understand all unicode
  180. rules (about what constitutes a letter, a punctuation symbol,
  181. etc.), so it may fail to detect word boundaries correctly in
  182. some instances. It is safe on all utf-8 input.
  183. License
  184. -------
  185. [Blackfriday is distributed under the Simplified BSD License](LICENSE.txt)
  186. [1]: http://daringfireball.net/projects/markdown/ "Markdown"
  187. [2]: http://golang.org/ "Go Language"
  188. [3]: https://github.com/vmg/sundown "Sundown"