all repos — grayfriday @ 793fee5451fe853b7bd45ef35eb06c04522eafad

blackfriday fork with a few changes

README.md (view raw)

  1Blackfriday
  2===========
  3
  4Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It
  5is paranoid about its input (so you can safely feed it user-supplied
  6data), it is fast, it supports common extensions (tables, smart
  7punctuation substitutions, etc.), and it is safe for all utf-8
  8(unicode) input.
  9
 10HTML output is currently supported, along with Smartypants
 11extensions. An experimental LaTeX output engine is also included.
 12
 13It started as a translation from C of [upskirt][3].
 14
 15
 16Installation
 17------------
 18
 19Assuming you have recent version of Go installed, along with git:
 20
 21    goinstall github.com/russross/blackfriday
 22
 23will download, compile, and install the package into
 24`$GOROOT/src/pkg/github.com/russross/blackfriday`.
 25
 26For basic usage, it is as simple as getting your input into a byte
 27slice and calling:
 28
 29    output := blackfriday.MarkdownBasic(input)
 30
 31This renders it with no extensions enabled. To get a more useful
 32feature set, use this instead:
 33
 34    output := blackfriday.MarkdownCommon(input)
 35
 36If you want to customize the set of options, first get a renderer
 37(currently either the HTML or LaTeX output engines), then use it to
 38call the more general `Markdown` function. For examples, see the
 39implementations of `MarkdownBasic` and `MarkdownCommon` in
 40`markdown.go`.
 41
 42You can also check out `example/main.go` for a more complete example
 43of how to use it. Run `gomake` in that directory to build a simple
 44command-line markdown tool:
 45
 46    cd $GOROOT/src/pkg/github.com/russross/blackfriday/example
 47    gomake
 48
 49will build the binary `markdown` in the `example` directory.
 50
 51
 52Features
 53--------
 54
 55All features of upskirt are supported, including:
 56
 57*   The Markdown v1.0.3 test suite passes with the `--tidy` option.
 58    Without `--tidy`, the differences appear to be bugs/dubious
 59    features in the original, mostly related to whitespace.
 60
 61*   Common extensions, including table support, fenced code blocks,
 62    autolinks, strikethroughs, non-strict emphasis, etc.
 63
 64*   Paranoid parsing, making it safe to feed untrusted used input
 65    without fear of bad things happening. There are still some
 66    corner cases that are untested, but it is already more strict
 67    than upskirt (bounds checking in Go uncovered a few off-by-one
 68    errors that were present in upskirt).
 69
 70*   Good performance. I have not done rigorous benchmarking, but
 71    informal testing suggests it is around 3--4x slower than upskirt
 72    for general input. It blows away most other markdown processors.
 73
 74*   Minimal dependencies. Blackfriday only depends on standard
 75    library packages in Go. The source code is pretty
 76    self-contained, so it is easy to add to any project.
 77
 78*   Output successfully validates using the W3C validation tool for
 79    HTML 4.01 and XHTML 1.0 Transitional.
 80
 81
 82Extensions
 83----------
 84
 85In addition to the extensions offered by upskirt, this package
 86implements two additional Smartypants options:
 87
 88*   LaTeX-style dash parsing, where `--` is translated into
 89    `–`, and `---` is translated into `—`
 90*   Generic fractions, where anything that looks like a fraction is
 91    translated into suitable HTML (instead of just a few special
 92    cases).  For example, `4/5` becomes
 93    `<sup>4</sup>&frasl;<sub>5</sub>`, which renders as
 94    <sup>4</sup>&frasl;<sub>5</sub>.
 95
 96
 97LaTeX Output
 98------------
 99
100A rudimentary LaTeX rendering backend is also included. To see an
101example of its usage, see `main.go`:
102
103It renders some basic documents, but is only experimental at this
104point. In particular, it does not do any inline escaping, so input
105that happens to look like LaTeX code will be passed through without
106modification.
107
108
109Todo
110----
111
112*   More unit testing
113*   Code cleanup
114*   Better code documentation
115*   Markdown pretty-printer output engine
116*   Improve unicode support. It does not understand all unicode
117    rules (about what constitutes a letter, a punctuation symbol,
118    etc.), so it may fail to detect word boundaries correctly in
119    some instances. It is safe on all utf-8 input.
120
121
122License
123-------
124
125Blackfriday is distributed under the Simplified BSD License:
126
127> Copyright © 2011 Russ Ross. All rights reserved.
128> 
129> Redistribution and use in source and binary forms, with or without modification, are
130> permitted provided that the following conditions are met:
131> 
132>    1. Redistributions of source code must retain the above copyright notice, this list of
133>       conditions and the following disclaimer.
134> 
135>    2. Redistributions in binary form must reproduce the above copyright notice, this list
136>       of conditions and the following disclaimer in the documentation and/or other materials
137>       provided with the distribution.
138> 
139> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED
140> WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
141> FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
142> CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
143> CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
144> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
145> ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
146> NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
147> ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
148> 
149> The views and conclusions contained in the software and documentation are those of the
150> authors and should not be interpreted as representing official policies, either expressed
151> or implied, of the copyright holder.
152
153
154   [1]: http://daringfireball.net/projects/markdown/ "Markdown"
155   [2]: http://golang.org/ "Go Language"
156   [3]: http://github.com/tanoku/upskirt "Upskirt"