Blame test/import-with-vendor-app/app/vendor/github.com/russross/blackfriday/README.md

1d434f7
Blackfriday [![Build Status](https://travis-ci.org/russross/blackfriday.svg?branch=master)](https://travis-ci.org/russross/blackfriday) [![GoDoc](https://godoc.org/github.com/russross/blackfriday?status.svg)](https://godoc.org/github.com/russross/blackfriday)
1d434f7
===========
1d434f7
1d434f7
Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It
1d434f7
is paranoid about its input (so you can safely feed it user-supplied
1d434f7
data), it is fast, it supports common extensions (tables, smart
1d434f7
punctuation substitutions, etc.), and it is safe for all utf-8
1d434f7
(unicode) input.
1d434f7
1d434f7
HTML output is currently supported, along with Smartypants
1d434f7
extensions. An experimental LaTeX output engine is also included.
1d434f7
1d434f7
It started as a translation from C of [Sundown][3].
1d434f7
1d434f7
1d434f7
Installation
1d434f7
------------
1d434f7
1d434f7
Blackfriday is compatible with Go 1. If you are using an older
1d434f7
release of Go, consider using v1.1 of blackfriday, which was based
1d434f7
on the last stable release of Go prior to Go 1. You can find it as a
1d434f7
tagged commit on github.
1d434f7
1d434f7
With Go 1 and git installed:
1d434f7
1d434f7
    go get github.com/russross/blackfriday
1d434f7
1d434f7
will download, compile, and install the package into your `$GOPATH`
1d434f7
directory hierarchy. Alternatively, you can achieve the same if you
1d434f7
import it into a project:
1d434f7
1d434f7
    import "github.com/russross/blackfriday"
1d434f7
1d434f7
and `go get` without parameters.
1d434f7
1d434f7
Usage
1d434f7
-----
1d434f7
1d434f7
For basic usage, it is as simple as getting your input into a byte
1d434f7
slice and calling:
1d434f7
1d434f7
    output := blackfriday.MarkdownBasic(input)
1d434f7
1d434f7
This renders it with no extensions enabled. To get a more useful
1d434f7
feature set, use this instead:
1d434f7
1d434f7
    output := blackfriday.MarkdownCommon(input)
1d434f7
1d434f7
### Sanitize untrusted content
1d434f7
1d434f7
Blackfriday itself does nothing to protect against malicious content. If you are
1d434f7
dealing with user-supplied markdown, we recommend running blackfriday's output
1d434f7
through HTML sanitizer such as
1d434f7
[Bluemonday](https://github.com/microcosm-cc/bluemonday).
1d434f7
1d434f7
Here's an example of simple usage of blackfriday together with bluemonday:
1d434f7
1d434f7
``` go
1d434f7
import (
1d434f7
    "github.com/microcosm-cc/bluemonday"
1d434f7
    "github.com/russross/blackfriday"
1d434f7
)
1d434f7
1d434f7
// ...
1d434f7
unsafe := blackfriday.MarkdownCommon(input)
1d434f7
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
1d434f7
```
1d434f7
1d434f7
### Custom options
1d434f7
1d434f7
If you want to customize the set of options, first get a renderer
1d434f7
(currently either the HTML or LaTeX output engines), then use it to
1d434f7
call the more general `Markdown` function. For examples, see the
1d434f7
implementations of `MarkdownBasic` and `MarkdownCommon` in
1d434f7
`markdown.go`.
1d434f7
1d434f7
You can also check out `blackfriday-tool` for a more complete example
1d434f7
of how to use it. Download and install it using:
1d434f7
1d434f7
    go get github.com/russross/blackfriday-tool
1d434f7
1d434f7
This is a simple command-line tool that allows you to process a
1d434f7
markdown file using a standalone program.  You can also browse the
1d434f7
source directly on github if you are just looking for some example
1d434f7
code:
1d434f7
1d434f7
* <http://github.com/russross/blackfriday-tool>
1d434f7
1d434f7
Note that if you have not already done so, installing
1d434f7
`blackfriday-tool` will be sufficient to download and install
1d434f7
blackfriday in addition to the tool itself. The tool binary will be
1d434f7
installed in `$GOPATH/bin`.  This is a statically-linked binary that
1d434f7
can be copied to wherever you need it without worrying about
1d434f7
dependencies and library versions.
1d434f7
1d434f7
### Sanitized anchor names
1d434f7
1d434f7
Blackfriday includes an algorithm for creating sanitized anchor names
1d434f7
corresponding to a given input text. This algorithm is used to create
1d434f7
anchors for headings when `EXTENSION_AUTO_HEADER_IDS` is enabled. The
1d434f7
algorithm has a specification, so that other packages can create
1d434f7
compatible anchor names and links to those anchors.
1d434f7
1d434f7
The specification is located at https://godoc.org/github.com/russross/blackfriday#hdr-Sanitized_Anchor_Names.
1d434f7
1d434f7
[`SanitizedAnchorName`](https://godoc.org/github.com/russross/blackfriday#SanitizedAnchorName) exposes this functionality, and can be used to
1d434f7
create compatible links to the anchor names generated by blackfriday.
1d434f7
This algorithm is also implemented in a small standalone package at
1d434f7
[`github.com/shurcooL/sanitized_anchor_name`](https://godoc.org/github.com/shurcooL/sanitized_anchor_name). It can be useful for clients
1d434f7
that want a small package and don't need full functionality of blackfriday.
1d434f7
1d434f7
1d434f7
Features
1d434f7
--------
1d434f7
1d434f7
All features of Sundown are supported, including:
1d434f7
1d434f7
*   **Compatibility**. The Markdown v1.0.3 test suite passes with
1d434f7
    the `--tidy` option.  Without `--tidy`, the differences are
1d434f7
    mostly in whitespace and entity escaping, where blackfriday is
1d434f7
    more consistent and cleaner.
1d434f7
1d434f7
*   **Common extensions**, including table support, fenced code
1d434f7
    blocks, autolinks, strikethroughs, non-strict emphasis, etc.
1d434f7
1d434f7
*   **Safety**. Blackfriday is paranoid when parsing, making it safe
1d434f7
    to feed untrusted user input without fear of bad things
1d434f7
    happening. The test suite stress tests this and there are no
1d434f7
    known inputs that make it crash.  If you find one, please let me
1d434f7
    know and send me the input that does it.
1d434f7
1d434f7
    NOTE: "safety" in this context means *runtime safety only*. In order to
1d434f7
    protect yourself against JavaScript injection in untrusted content, see
1d434f7
    [this example](https://github.com/russross/blackfriday#sanitize-untrusted-content).
1d434f7
1d434f7
*   **Fast processing**. It is fast enough to render on-demand in
1d434f7
    most web applications without having to cache the output.
1d434f7
1d434f7
*   **Thread safety**. You can run multiple parsers in different
1d434f7
    goroutines without ill effect. There is no dependence on global
1d434f7
    shared state.
1d434f7
1d434f7
*   **Minimal dependencies**. Blackfriday only depends on standard
1d434f7
    library packages in Go. The source code is pretty
1d434f7
    self-contained, so it is easy to add to any project, including
1d434f7
    Google App Engine projects.
1d434f7
1d434f7
*   **Standards compliant**. Output successfully validates using the
1d434f7
    W3C validation tool for HTML 4.01 and XHTML 1.0 Transitional.
1d434f7
1d434f7
1d434f7
Extensions
1d434f7
----------
1d434f7
1d434f7
In addition to the standard markdown syntax, this package
1d434f7
implements the following extensions:
1d434f7
1d434f7
*   **Intra-word emphasis supression**. The `_` character is
1d434f7
    commonly used inside words when discussing code, so having
1d434f7
    markdown interpret it as an emphasis command is usually the
1d434f7
    wrong thing. Blackfriday lets you treat all emphasis markers as
1d434f7
    normal characters when they occur inside a word.
1d434f7
1d434f7
*   **Tables**. Tables can be created by drawing them in the input
1d434f7
    using a simple syntax:
1d434f7
1d434f7
    ```
1d434f7
    Name    | Age
1d434f7
    --------|------
1d434f7
    Bob     | 27
1d434f7
    Alice   | 23
1d434f7
    ```
1d434f7
1d434f7
*   **Fenced code blocks**. In addition to the normal 4-space
1d434f7
    indentation to mark code blocks, you can explicitly mark them
1d434f7
    and supply a language (to make syntax highlighting simple). Just
1d434f7
    mark it like this:
1d434f7
1d434f7
        ``` go
1d434f7
        func getTrue() bool {
1d434f7
            return true
1d434f7
        }
1d434f7
        ```
1d434f7
1d434f7
    You can use 3 or more backticks to mark the beginning of the
1d434f7
    block, and the same number to mark the end of the block.
1d434f7
1d434f7
    To preserve classes of fenced code blocks while using the bluemonday
1d434f7
    HTML sanitizer, use the following policy:
1d434f7
1d434f7
    ``` go
1d434f7
    p := bluemonday.UGCPolicy()
1d434f7
    p.AllowAttrs("class").Matching(regexp.MustCompile("^language-[a-zA-Z0-9]+$")).OnElements("code")
1d434f7
    html := p.SanitizeBytes(unsafe)
1d434f7
    ```
1d434f7
1d434f7
*   **Definition lists**. A simple definition list is made of a single-line
1d434f7
    term followed by a colon and the definition for that term.
1d434f7
1d434f7
        Cat
1d434f7
        : Fluffy animal everyone likes
1d434f7
        
1d434f7
        Internet
1d434f7
        : Vector of transmission for pictures of cats
1d434f7
1d434f7
    Terms must be separated from the previous definition by a blank line.
1d434f7
1d434f7
*   **Footnotes**. A marker in the text that will become a superscript number;
1d434f7
    a footnote definition that will be placed in a list of footnotes at the
1d434f7
    end of the document. A footnote looks like this:
1d434f7
1d434f7
        This is a footnote.[^1]
1d434f7
        
1d434f7
        [^1]: the footnote text.
1d434f7
1d434f7
*   **Autolinking**. Blackfriday can find URLs that have not been
1d434f7
    explicitly marked as links and turn them into links.
1d434f7
1d434f7
*   **Strikethrough**. Use two tildes (`~~`) to mark text that
1d434f7
    should be crossed out.
1d434f7
1d434f7
*   **Hard line breaks**. With this extension enabled (it is off by
1d434f7
    default in the `MarkdownBasic` and `MarkdownCommon` convenience
1d434f7
    functions), newlines in the input translate into line breaks in
1d434f7
    the output.
1d434f7
1d434f7
*   **Smart quotes**. Smartypants-style punctuation substitution is
1d434f7
    supported, turning normal double- and single-quote marks into
1d434f7
    curly quotes, etc.
1d434f7
1d434f7
*   **LaTeX-style dash parsing** is an additional option, where `--`
1d434f7
    is translated into `–`, and `---` is translated into
1d434f7
    `—`. This differs from most smartypants processors, which
1d434f7
    turn a single hyphen into an ndash and a double hyphen into an
1d434f7
    mdash.
1d434f7
1d434f7
*   **Smart fractions**, where anything that looks like a fraction
1d434f7
    is translated into suitable HTML (instead of just a few special
1d434f7
    cases like most smartypant processors). For example, `4/5`
1d434f7
    becomes `<sup>4</sup>⁄<sub>5</sub>`, which renders as
1d434f7
    <sup>4</sup>⁄<sub>5</sub>.
1d434f7
1d434f7
1d434f7
Other renderers
1d434f7
---------------
1d434f7
1d434f7
Blackfriday is structured to allow alternative rendering engines. Here
1d434f7
are a few of note:
1d434f7
1d434f7
*   [github_flavored_markdown](https://godoc.org/github.com/shurcooL/github_flavored_markdown):
1d434f7
    provides a GitHub Flavored Markdown renderer with fenced code block
1d434f7
    highlighting, clickable header anchor links.
1d434f7
1d434f7
    It's not customizable, and its goal is to produce HTML output
1d434f7
    equivalent to the [GitHub Markdown API endpoint](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode),
1d434f7
    except the rendering is performed locally.
1d434f7
1d434f7
*   [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt,
1d434f7
    but for markdown.
1d434f7
1d434f7
*   LaTeX output: renders output as LaTeX. This is currently part of the
1d434f7
    main Blackfriday repository, but may be split into its own project
1d434f7
    in the future. If you are interested in owning and maintaining the
1d434f7
    LaTeX output component, please be in touch.
1d434f7
1d434f7
    It renders some basic documents, but is only experimental at this
1d434f7
    point. In particular, it does not do any inline escaping, so input
1d434f7
    that happens to look like LaTeX code will be passed through without
1d434f7
    modification.
1d434f7
    
1d434f7
*   [Md2Vim](https://github.com/FooSoft/md2vim): transforms markdown files into vimdoc format.
1d434f7
1d434f7
1d434f7
Todo
1d434f7
----
1d434f7
1d434f7
*   More unit testing
1d434f7
*   Improve unicode support. It does not understand all unicode
1d434f7
    rules (about what constitutes a letter, a punctuation symbol,
1d434f7
    etc.), so it may fail to detect word boundaries correctly in
1d434f7
    some instances. It is safe on all utf-8 input.
1d434f7
1d434f7
1d434f7
License
1d434f7
-------
1d434f7
1d434f7
[Blackfriday is distributed under the Simplified BSD License](LICENSE.txt)
1d434f7
1d434f7
1d434f7
   [1]: http://daringfireball.net/projects/markdown/ "Markdown"
1d434f7
   [2]: http://golang.org/ "Go Language"
1d434f7
   [3]: https://github.com/vmg/sundown "Sundown"