diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go index dceb4848..66ba64cb 100644 --- a/bridge/helper/helper.go +++ b/bridge/helper/helper.go @@ -14,8 +14,9 @@ import ( "golang.org/x/image/webp" "github.com/42wim/matterbridge/bridge/config" + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/parser" "github.com/sirupsen/logrus" - "gitlab.com/golang-commonmark/markdown" ) // DownloadFile downloads the given non-authenticated URL. @@ -176,9 +177,12 @@ func ClipMessage(text string, length int) string { return text } +// ParseMarkdown takes in an input string as markdown and parses it to html func ParseMarkdown(input string) string { - md := markdown.New(markdown.XHTMLOutput(true), markdown.Breaks(true)) - res := md.RenderToString([]byte(input)) + extensions := parser.HardLineBreak + markdownParser := parser.NewWithExtensions(extensions) + parsedMarkdown := markdown.ToHTML([]byte(input), markdownParser, nil) + res := string(parsedMarkdown) res = strings.TrimPrefix(res, "
") res = strings.TrimSuffix(res, "
\n") return res diff --git a/go.mod b/go.mod index 76f41c16..8bcab865 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/dfordsoft/golib v0.0.0-20180902042739-76ee6ab99bec github.com/fsnotify/fsnotify v1.4.7 github.com/go-telegram-bot-api/telegram-bot-api v4.6.5-0.20181225215658-ec221ba9ea45+incompatible + github.com/gomarkdown/markdown v0.0.0-20190912180731-281270bc6d83 github.com/google/gops v0.3.6 github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4 // indirect github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f // indirect @@ -46,7 +47,6 @@ require ( github.com/russross/blackfriday v1.5.2 github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca github.com/shazow/ssh-chat v0.0.0-20190125184227-81d7e1686296 - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/sirupsen/logrus v1.4.2 github.com/smartystreets/assertions v0.0.0-20180803164922-886ec427f6b9 // indirect github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect @@ -55,19 +55,12 @@ require ( github.com/technoweenie/multipartstreamer v1.0.1 // indirect github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect github.com/zfjagann/golang-ring v0.0.0-20190304061218-d34796e0a6c2 - gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a // indirect - gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82 // indirect - gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f - gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2 // indirect - gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe // indirect - gitlab.com/opennota/wd v0.0.0-20180912061657-c5d65f63c638 // indirect golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 // indirect golang.org/x/image v0.0.0-20190902063713-cb417be4ba39 golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect golang.org/x/text v0.3.2 // indirect gopkg.in/fsnotify.v1 v1.4.7 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect - gopkg.in/russross/blackfriday.v2 v2.0.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect ) diff --git a/go.sum b/go.sum index 460ae891..a6ea6c32 100644 --- a/go.sum +++ b/go.sum @@ -63,6 +63,8 @@ github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/gomarkdown/markdown v0.0.0-20190912180731-281270bc6d83 h1:w5VNUHB0SP2tr1+boQJWKvnyn3P61UFErZ2e2ih6x0A= +github.com/gomarkdown/markdown v0.0.0-20190912180731-281270bc6d83/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/gops v0.3.6 h1:6akvbMlpZrEYOuoebn2kR+ZJekbZqJ28fJXTs84+8to= @@ -203,8 +205,6 @@ github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7 h1:80VN+vGkqM773Br github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -247,18 +247,6 @@ github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6Ut github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/zfjagann/golang-ring v0.0.0-20190304061218-d34796e0a6c2 h1:UQwvu7FjUEdVYofx0U6bsc5odNE7wa5TSA0fl559GcA= github.com/zfjagann/golang-ring v0.0.0-20190304061218-d34796e0a6c2/go.mod h1:0MsIttMJIF/8Y7x0XjonJP7K99t3sR6bjj4m5S4JmqU= -gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a h1:Ax7kdHNICZiIeFpmevmaEWb0Ae3BUj3zCTKhZHZ+zd0= -gitlab.com/golang-commonmark/html v0.0.0-20180917080848-cfaf75183c4a/go.mod h1:JT4uoTz0tfPoyVH88GZoWDNm5NHJI2VbUW+eyPClueI= -gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82 h1:oYrL81N608MLZhma3ruL8qTM4xcpYECGut8KSxRY59g= -gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82/go.mod h1:Gn+LZmCrhPECMD3SOKlE+BOHwhOYD9j7WT9NUtkCrC8= -gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f h1:jwXy/CsM4xS2aoiF2fHAlukmInWhd2TlWB+HDCyvzKc= -gitlab.com/golang-commonmark/markdown v0.0.0-20181102083822-772775880e1f/go.mod h1:SIHlEr9462fpIfTrVWf3GqQDxnA65Vm3BMMsUtuA6W0= -gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2 h1:wD/sPUgx2QJFPTyXZpJnLaROolfeKuruh06U4pRV0WY= -gitlab.com/golang-commonmark/mdurl v0.0.0-20180912090424-e5bce34c34f2/go.mod h1:wQk4rLkWrdOPjUAtqJRJ10hIlseLSVYWP95PLrjDF9s= -gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe h1:5kUPFAF52umOUPH12MuNUmyVTseJRNBftDl/KfsvX3I= -gitlab.com/golang-commonmark/puny v0.0.0-20180912090636-2cd490539afe/go.mod h1:P9LSM1KVzrIstFgUaveuwiAm8PK5VTB3yJEU8kqlbrU= -gitlab.com/opennota/wd v0.0.0-20180912061657-c5d65f63c638 h1:uPZaMiz6Sz0PZs3IZJWpU5qHKGNy///1pacZC9txiUI= -gitlab.com/opennota/wd v0.0.0-20180912061657-c5d65f63c638/go.mod h1:EGRJaqe2eO9XGmFtQCvV3Lm9NLico3UhFwUpCG/+mVU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -266,6 +254,7 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -326,8 +315,6 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/russross/blackfriday.v2 v2.0.0 h1:+FlnIV8DSQnT7NZ43hcVKcdJdzZoeCmJj4Ql8gq5keA= -gopkg.in/russross/blackfriday.v2 v2.0.0/go.mod h1:6sSBNz/GtOm/pJTuh5UmBK2ZHfmnxGbl2NZg1UliSOI= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= diff --git a/vendor/github.com/gomarkdown/markdown/.gitignore b/vendor/github.com/gomarkdown/markdown/.gitignore new file mode 100644 index 00000000..8f15b677 --- /dev/null +++ b/vendor/github.com/gomarkdown/markdown/.gitignore @@ -0,0 +1,13 @@ +*.out +*.swp +*.8 +*.6 +_obj +_test* +markdown +tags +fuzz-workdir/ +markdown-fuzz.zip +coverage.txt +testdata/*_got.md +testdata/*_ast.txt diff --git a/vendor/github.com/gomarkdown/markdown/.gitpod b/vendor/github.com/gomarkdown/markdown/.gitpod new file mode 100644 index 00000000..ad5feff6 --- /dev/null +++ b/vendor/github.com/gomarkdown/markdown/.gitpod @@ -0,0 +1,7 @@ +checkoutLocation: "src/github.com/gomarkdown/markdown" +workspaceLocation: "." +tasks: + - command: > + cd /workspace/src/github.com/gomarkdown/markdown && + go get -v ./... && + go test -c diff --git a/vendor/github.com/gomarkdown/markdown/.travis.yml b/vendor/github.com/gomarkdown/markdown/.travis.yml new file mode 100644 index 00000000..4ec5d7b0 --- /dev/null +++ b/vendor/github.com/gomarkdown/markdown/.travis.yml @@ -0,0 +1,17 @@ +dist: bionic +language: go + +go: + - "1.12.x" + +install: + - go build -v ./... + +script: + - go test -v ./... + - go test -run=^$ -bench=BenchmarkReference -benchmem + - ./s/test_with_codecoverage.sh + - ./s/ci_fuzzit.sh + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/gomarkdown/markdown/LICENSE.txt b/vendor/github.com/gomarkdown/markdown/LICENSE.txt new file mode 100644 index 00000000..68804610 --- /dev/null +++ b/vendor/github.com/gomarkdown/markdown/LICENSE.txt @@ -0,0 +1,31 @@ +Markdown is distributed under the Simplified BSD License: + +Copyright © 2011 Russ Ross +Copyright © 2018 Krzysztof Kowalczyk +Copyright © 2018 Authors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided with + the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/gomarkdown/markdown/README.md b/vendor/github.com/gomarkdown/markdown/README.md new file mode 100644 index 00000000..3bca71db --- /dev/null +++ b/vendor/github.com/gomarkdown/markdown/README.md @@ -0,0 +1,325 @@ +# Markdown Parser and HTML Renderer for Go + +[![GoDoc](https://godoc.org/github.com/gomarkdown/markdown?status.svg)](https://godoc.org/github.com/gomarkdown/markdown) [![codecov](https://codecov.io/gh/gomarkdown/markdown/branch/master/graph/badge.svg)](https://codecov.io/gh/gomarkdown/markdown) + +Package `github.com/gomarkdown/markdown` is a very fast Go library for parsing [Markdown](https://daringfireball.net/projects/markdown/) documents and rendering them to HTML. + +It's fast and supports common extensions. + +## Installation + + go get -u github.com/gomarkdown/markdown + +API Docs: + +- https://godoc.org/github.com/gomarkdown/markdown : top level package +- https://godoc.org/github.com/gomarkdown/markdown/ast : defines abstract syntax tree of parsed markdown document +- https://godoc.org/github.com/gomarkdown/markdown/parser : parser +- https://godoc.org/github.com/gomarkdown/markdown/html : html renderer + +## Usage + +To convert markdown text to HTML using reasonable defaults: + +```go +md := []byte("## markdown document") +output := markdown.ToHTML(md, nil, nil) +``` + +## Customizing markdown parser + +Markdown format is loosely specified and there are multiple extensions invented after original specification was created. + +The parser supports several [extensions](https://godoc.org/github.com/gomarkdown/markdown/parser#Extensions). + +Default parser uses most common `parser.CommonExtensions` but you can easily use parser with custom extension: + +```go +import ( + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/parser" +) + +extensions := parser.CommonExtensions | parser.AutoHeadingIDs +parser := parser.NewWithExtensions(extensions) + +md := []byte("markdown text") +html := markdown.ToHTML(md, parser, nil) +``` + +## Customizing HTML renderer + +Similarly, HTML renderer can be configured with different [options](https://godoc.org/github.com/gomarkdown/markdown/html#RendererOptions) + +Here's how to use a custom renderer: + +```go +import ( + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/html" +) + +htmlFlags := html.CommonFlags | html.HrefTargetBlank +opts := html.RendererOptions{Flags: htmlFlags} +renderer := html.NewRenderer(opts) + +md := []byte("markdown text") +html := markdown.ToHTML(md, nil, renderer) +``` + +HTML renderer also supports reusing most of the logic and overriding rendering of only specifc nodes. + +You can provide [RenderNodeFunc](https://godoc.org/github.com/gomarkdown/markdown/html#RenderNodeFunc) in [RendererOptions](https://godoc.org/github.com/gomarkdown/markdown/html#RendererOptions). + +The function is called for each node in AST, you can implement custom rendering logic and tell HTML renderer to skip rendering this node. + +Here's the simplest example that drops all code blocks from the output: + +````go +import ( + "github.com/gomarkdown/markdown" + "github.com/gomarkdown/markdown/ast" + "github.com/gomarkdown/markdown/html" +) + +// return (ast.GoToNext, true) to tell html renderer to skip rendering this node +// (because you've rendered it) +func renderHookDropCodeBlock(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) { + // skip all nodes that are not CodeBlock nodes + if _, ok := node.(*ast.CodeBlock); !ok { + return ast.GoToNext, false + } + // custom rendering logic for ast.CodeBlock. By doing nothing it won't be + // present in the output + return ast.GoToNext, true +} + +opts := html.RendererOptions{ + Flags: html.CommonFlags, + RenderNodeHook: renderHookDropCodeBlock, +} +renderer := html.NewRenderer(opts) +md := "test\n```\nthis code block will be dropped from output\n```\ntext" +html := markdown.ToHTML([]byte(s), nil, renderer) +```` + +## Sanitize untrusted content + +We don't protect against malicious content. When dealing with user-provided +markdown, run renderer HTML through HTML sanitizer such as [Bluemonday](https://github.com/microcosm-cc/bluemonday). + +Here's an example of simple usage with Bluemonday: + +```go +import ( + "github.com/microcosm-cc/bluemonday" + "github.com/gomarkdown/markdown" +) + +// ... +maybeUnsafeHTML := markdown.ToHTML(md, nil, nil) +html := bluemonday.UGCPolicy().SanitizeBytes(maybeUnsafeHTML) +``` + +## mdtohtml command-line tool + +https://github.com/gomarkdown/mdtohtml is a command-line markdown to html +converter built using this library. + +You can also use it as an example of how to use the library. + +You can install it with: + + go get -u github.com/gomarkdown/mdtohtml + +To run: `mdtohtml input-file [output-file]` + +## Features + +- **Compatibility**. The Markdown v1.0.3 test suite passes with + the `--tidy` option. Without `--tidy`, the differences are + mostly in whitespace and entity escaping, where this package is + more consistent and cleaner. + +- **Common extensions**, including table support, fenced code + blocks, autolinks, strikethroughs, non-strict emphasis, etc. + +- **Safety**. Markdown is paranoid when parsing, making it safe + to feed untrusted user input without fear of bad things + happening. The test suite stress tests this and there are no + known inputs that make it crash. If you find one, please let me + know and send me the input that does it. + + NOTE: "safety" in this context means _runtime safety only_. In order to + protect yourself against JavaScript injection in untrusted content, see + [this example](https://github.com/gomarkdown/markdown#sanitize-untrusted-content). + +- **Fast**. It is fast enough to render on-demand in + most web applications without having to cache the output. + +- **Thread safety**. You can run multiple parsers in different + goroutines without ill effect. There is no dependence on global + shared state. + +- **Minimal dependencies**. Only depends on standard library packages in Go. + +- **Standards compliant**. Output successfully validates using the + W3C validation tool for HTML 4.01 and XHTML 1.0 Transitional. + +## Extensions + +In addition to the standard markdown syntax, this package +implements the following extensions: + +- **Intra-word emphasis supression**. The `_` character is + commonly used inside words when discussing code, so having + markdown interpret it as an emphasis command is usually the + wrong thing. We let you treat all emphasis markers as + normal characters when they occur inside a word. + +- **Tables**. Tables can be created by drawing them in the input + using a simple syntax: + + ``` + Name | Age + --------|------ + Bob | 27 + Alice | 23 + ``` + + Table footers are supported as well and can be added with equal signs (`=`): + + ``` + Name | Age + --------|------ + Bob | 27 + Alice | 23 + ========|====== + Total | 50 + ``` + +- **Fenced code blocks**. In addition to the normal 4-space + indentation to mark code blocks, you can explicitly mark them + and supply a language (to make syntax highlighting simple). Just + mark it like this: + + ```go + func getTrue() bool { + return true + } + ``` + + You can use 3 or more backticks to mark the beginning of the + block, and the same number to mark the end of the block. + +- **Definition lists**. A simple definition list is made of a single-line + term followed by a colon and the definition for that term. + + Cat + : Fluffy animal everyone likes + + Internet + : Vector of transmission for pictures of cats + + Terms must be separated from the previous definition by a blank line. + +- **Footnotes**. A marker in the text that will become a superscript number; + a footnote definition that will be placed in a list of footnotes at the + end of the document. A footnote looks like this: + + This is a footnote.[^1] + + [^1]: the footnote text. + +- **Autolinking**. We can find URLs that have not been + explicitly marked as links and turn them into links. + +- **Strikethrough**. Use two tildes (`~~`) to mark text that + should be crossed out. + +- **Hard line breaks**. With this extension enabled newlines in the input + translate into line breaks in the output. This extension is off by default. + +- **Non blocking space**. With this extension enabled spaces preceeded by an backslash n the input + translate non-blocking spaces in the output. This extension is off by default. + +- **Smart quotes**. Smartypants-style punctuation substitution is + supported, turning normal double- and single-quote marks into + curly quotes, etc. + +- **LaTeX-style dash parsing** is an additional option, where `--` + is translated into `–`, and `---` is translated into + `—`. This differs from most smartypants processors, which + turn a single hyphen into an ndash and a double hyphen into an + mdash. + +- **Smart fractions**, where anything that looks like a fraction + is translated into suitable HTML (instead of just a few special + cases like most smartypant processors). For example, `4/5` + becomes `4⁄5`, which renders as + 4⁄5. + +- **MathJaX Support** is an additional feature which is supported by + many markdown editor. It translate inline math equation quoted by `$` + and display math block quoted by `$$` into MathJax compatible format. + hyphen `_` won't break LaTeX render within a math element any more. + + ``` + $$ + \left[ \begin{array}{a} a^l_1 \\ ⋮ \\ a^l_{d_l} \end{array}\right] + = \sigma( + \left[ \begin{matrix} + w^l_{1,1} & ⋯ & w^l_{1,d_{l-1}} \\ + ⋮ & ⋱ & ⋮ \\ + w^l_{d_l,1} & ⋯ & w^l_{d_l,d_{l-1}} \\ + \end{matrix}\right] · + \left[ \begin{array}{x} a^{l-1}_1 \\ ⋮ \\ ⋮ \\ a^{l-1}_{d_{l-1}} \end{array}\right] + + \left[ \begin{array}{b} b^l_1 \\ ⋮ \\ b^l_{d_l} \end{array}\right]) + $$ + ``` + +- **Ordered list start number**. With this extension enabled an ordered list will start with the + the number that was used to start it. + +- **Super and subscript**. With this extension enabled sequences between ^ will indicate + superscript and ~ will become a subscript. For example: H~2~O is a liquid, 2^10^ is 1024. + +- **Block level attributes**, allow setting attributes (ID, classes and key/value pairs) on block + level elements. The attribute must be enclosed with braces and be put on a line before the + element. + + ``` + {#id3 .myclass fontsize="tiny"} + # Header 1 + ``` + + Will convert into `s around list item data if true + BulletChar byte // '*', '+' or '-' in bullet lists + Delimiter byte // '.' or ')' after the number in ordered lists + Start int // for ordered lists this indicates the starting number if > 0 + RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering + IsFootnotesList bool // This is a list of footnotes +} + +// ListItem represents markdown list item node +type ListItem struct { + Container + + ListFlags ListType + Tight bool // Skip
s around list item data if true
+ BulletChar byte // '*', '+' or '-' in bullet lists
+ Delimiter byte // '.' or ')' after the number in ordered lists
+ RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering
+ IsFootnotesList bool // This is a list of footnotes
+}
+
+// Paragraph represents markdown paragraph node
+type Paragraph struct {
+ Container
+}
+
+// Math represents markdown MathAjax inline node
+type Math struct {
+ Leaf
+}
+
+// MathBlock represents markdown MathAjax block node
+type MathBlock struct {
+ Container
+}
+
+// Heading represents markdown heading node
+type Heading struct {
+ Container
+
+ Level int // This holds the heading level number
+ HeadingID string // This might hold heading ID, if present
+ IsTitleblock bool // Specifies whether it's a title block
+ IsSpecial bool // We are a special heading (starts with .#)
+}
+
+// HorizontalRule represents markdown horizontal rule node
+type HorizontalRule struct {
+ Leaf
+}
+
+// Emph represents markdown emphasis node
+type Emph struct {
+ Container
+}
+
+// Strong represents markdown strong node
+type Strong struct {
+ Container
+}
+
+// Del represents markdown del node
+type Del struct {
+ Container
+}
+
+// Link represents markdown link node
+type Link struct {
+ Container
+
+ Destination []byte // Destination is what goes into a href
+ Title []byte // Title is the tooltip thing that goes in a title attribute
+ NoteID int // NoteID contains a serial number of a footnote, zero if it's not a footnote
+ Footnote Node // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil.
+ DeferredID []byte // If a deferred link this holds the original ID.
+}
+
+// CrossReference is a reference node.
+type CrossReference struct {
+ Container
+
+ Destination []byte // Destination is where the reference points to
+}
+
+// Citation is a citation node.
+type Citation struct {
+ Leaf
+
+ Destination [][]byte // Destination is where the citation points to. Multiple ones are allowed.
+ Type []CitationTypes // 1:1 mapping of destination and citation type
+ Suffix [][]byte // Potential citation suffix, i.e. [@!RFC1035, p. 144]
+}
+
+// Image represents markdown image node
+type Image struct {
+ Container
+
+ Destination []byte // Destination is what goes into a href
+ Title []byte // Title is the tooltip thing that goes in a title attribute
+}
+
+// Text represents markdown text node
+type Text struct {
+ Leaf
+}
+
+// HTMLBlock represents markdown html node
+type HTMLBlock struct {
+ Leaf
+}
+
+// CodeBlock represents markdown code block node
+type CodeBlock struct {
+ Leaf
+
+ IsFenced bool // Specifies whether it's a fenced code block or an indented one
+ Info []byte // This holds the info string
+ FenceChar byte
+ FenceLength int
+ FenceOffset int
+}
+
+// Softbreak represents markdown softbreak node
+// Note: not used currently
+type Softbreak struct {
+ Leaf
+}
+
+// Hardbreak represents markdown hard break node
+type Hardbreak struct {
+ Leaf
+}
+
+// NonBlockingSpace represents markdown non-blocking space node
+type NonBlockingSpace struct {
+ Leaf
+}
+
+// Code represents markdown code node
+type Code struct {
+ Leaf
+}
+
+// HTMLSpan represents markdown html span node
+type HTMLSpan struct {
+ Leaf
+}
+
+// Table represents markdown table node
+type Table struct {
+ Container
+}
+
+// TableCell represents markdown table cell node
+type TableCell struct {
+ Container
+
+ IsHeader bool // This tells if it's under the header row
+ Align CellAlignFlags // This holds the value for align attribute
+}
+
+// TableHeader represents markdown table head node
+type TableHeader struct {
+ Container
+}
+
+// TableBody represents markdown table body node
+type TableBody struct {
+ Container
+}
+
+// TableRow represents markdown table row node
+type TableRow struct {
+ Container
+}
+
+// TableFooter represents markdown table foot node
+type TableFooter struct {
+ Container
+}
+
+// Caption represents a figure, code or quote caption
+type Caption struct {
+ Container
+}
+
+// CaptionFigure is a node (blockquote or codeblock) that has a caption
+type CaptionFigure struct {
+ Container
+
+ HeadingID string // This might hold heading ID, if present
+}
+
+// Callout is a node that can exist both in text (where it is an actual node) and in a code block.
+type Callout struct {
+ Leaf
+
+ ID []byte // number of this callout
+}
+
+// Index is a node that contains an Index item and an optional, subitem.
+type Index struct {
+ Leaf
+
+ Primary bool
+ Item []byte
+ Subitem []byte
+ ID string // ID of the index
+}
+
+// Subscript is a subscript node
+type Subscript struct {
+ Leaf
+}
+
+// Subscript is a superscript node
+type Superscript struct {
+ Leaf
+}
+
+// Footnotes is a node that contains all footnotes
+type Footnotes struct {
+ Container
+}
+
+func removeNodeFromArray(a []Node, node Node) []Node {
+ n := len(a)
+ for i := 0; i < n; i++ {
+ if a[i] == node {
+ return append(a[:i], a[i+1:]...)
+ }
+ }
+ return nil
+}
+
+// AppendChild appends child to children of parent
+// It panics if either node is nil.
+func AppendChild(parent Node, child Node) {
+ RemoveFromTree(child)
+ child.SetParent(parent)
+ newChildren := append(parent.GetChildren(), child)
+ parent.SetChildren(newChildren)
+}
+
+// RemoveFromTree removes this node from tree
+func RemoveFromTree(n Node) {
+ if n.GetParent() == nil {
+ return
+ }
+ // important: don't clear n.Children if n has no parent
+ // we're called from AppendChild and that might happen on a node
+ // that accumulated Children but hasn't been inserted into the tree
+ n.SetChildren(nil)
+ p := n.GetParent()
+ newChildren := removeNodeFromArray(p.GetChildren(), n)
+ if newChildren != nil {
+ p.SetChildren(newChildren)
+ }
+}
+
+// GetLastChild returns last child of node n
+// It's implemented as stand-alone function to keep Node interface small
+func GetLastChild(n Node) Node {
+ a := n.GetChildren()
+ if len(a) > 0 {
+ return a[len(a)-1]
+ }
+ return nil
+}
+
+// GetFirstChild returns first child of node n
+// It's implemented as stand-alone function to keep Node interface small
+func GetFirstChild(n Node) Node {
+ a := n.GetChildren()
+ if len(a) > 0 {
+ return a[0]
+ }
+ return nil
+}
+
+// GetNextNode returns next sibling of node n (node after n)
+// We can't make it part of Container or Leaf because we loose Node identity
+func GetNextNode(n Node) Node {
+ parent := n.GetParent()
+ if parent == nil {
+ return nil
+ }
+ a := parent.GetChildren()
+ len := len(a) - 1
+ for i := 0; i < len; i++ {
+ if a[i] == n {
+ return a[i+1]
+ }
+ }
+ return nil
+}
+
+// GetPrevNode returns previous sibling of node n (node before n)
+// We can't make it part of Container or Leaf because we loose Node identity
+func GetPrevNode(n Node) Node {
+ parent := n.GetParent()
+ if parent == nil {
+ return nil
+ }
+ a := parent.GetChildren()
+ len := len(a)
+ for i := 1; i < len; i++ {
+ if a[i] == n {
+ return a[i-1]
+ }
+ }
+ return nil
+}
+
+// WalkStatus allows NodeVisitor to have some control over the tree traversal.
+// It is returned from NodeVisitor and different values allow Node.Walk to
+// decide which node to go to next.
+type WalkStatus int
+
+const (
+ // GoToNext is the default traversal of every node.
+ GoToNext WalkStatus = iota
+ // SkipChildren tells walker to skip all children of current node.
+ SkipChildren
+ // Terminate tells walker to terminate the traversal.
+ Terminate
+)
+
+// NodeVisitor is a callback to be called when traversing the syntax tree.
+// Called twice for every node: once with entering=true when the branch is
+// first visited, then with entering=false after all the children are done.
+type NodeVisitor interface {
+ Visit(node Node, entering bool) WalkStatus
+}
+
+// NodeVisitorFunc casts a function to match NodeVisitor interface
+type NodeVisitorFunc func(node Node, entering bool) WalkStatus
+
+// Walk traverses tree recursively
+func Walk(n Node, visitor NodeVisitor) WalkStatus {
+ isContainer := n.AsContainer() != nil
+ status := visitor.Visit(n, true) // entering
+ if status == Terminate {
+ // even if terminating, close container node
+ if isContainer {
+ visitor.Visit(n, false)
+ }
+ return status
+ }
+ if isContainer && status != SkipChildren {
+ children := n.GetChildren()
+ for _, n := range children {
+ status = Walk(n, visitor)
+ if status == Terminate {
+ return status
+ }
+ }
+ }
+ if isContainer {
+ status = visitor.Visit(n, false) // exiting
+ if status == Terminate {
+ return status
+ }
+ }
+ return GoToNext
+}
+
+// Visit calls visitor function
+func (f NodeVisitorFunc) Visit(node Node, entering bool) WalkStatus {
+ return f(node, entering)
+}
+
+// WalkFunc is like Walk but accepts just a callback function
+func WalkFunc(n Node, f NodeVisitorFunc) {
+ visitor := NodeVisitorFunc(f)
+ Walk(n, visitor)
+}
diff --git a/vendor/github.com/gomarkdown/markdown/ast/print.go b/vendor/github.com/gomarkdown/markdown/ast/print.go
new file mode 100644
index 00000000..75daf911
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/ast/print.go
@@ -0,0 +1,165 @@
+package ast
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "strings"
+)
+
+// Print is for debugging. It prints a string representation of parsed
+// markdown doc (result of parser.Parse()) to dst.
+//
+// To make output readable, it shortens text output.
+func Print(dst io.Writer, doc Node) {
+ PrintWithPrefix(dst, doc, " ")
+}
+
+// PrintWithPrefix is like Print but allows customizing prefix used for
+// indentation. By default it's 2 spaces. You can change it to e.g. tab
+// by passing "\t"
+func PrintWithPrefix(w io.Writer, doc Node, prefix string) {
+ // for more compact output, don't print outer Document
+ if _, ok := doc.(*Document); ok {
+ for _, c := range doc.GetChildren() {
+ printRecur(w, c, prefix, 0)
+ }
+ } else {
+ printRecur(w, doc, prefix, 0)
+ }
+}
+
+// ToString is like Dump but returns result as a string
+func ToString(doc Node) string {
+ var buf bytes.Buffer
+ Print(&buf, doc)
+ return buf.String()
+}
+
+func contentToString(d1 []byte, d2 []byte) string {
+ if d1 != nil {
+ return string(d1)
+ }
+ if d2 != nil {
+ return string(d2)
+ }
+ return ""
+}
+
+func getContent(node Node) string {
+ if c := node.AsContainer(); c != nil {
+ return contentToString(c.Literal, c.Content)
+ }
+ leaf := node.AsLeaf()
+ return contentToString(leaf.Literal, leaf.Content)
+}
+
+func shortenString(s string, maxLen int) string {
+ // for cleaner, one-line ouput, replace some white-space chars
+ // with their escaped version
+ s = strings.Replace(s, "\n", `\n`, -1)
+ s = strings.Replace(s, "\r", `\r`, -1)
+ s = strings.Replace(s, "\t", `\t`, -1)
+ if maxLen < 0 {
+ return s
+ }
+ if len(s) < maxLen {
+ return s
+ }
+ // add "..." to indicate truncation
+ return s[:maxLen-3] + "..."
+}
+
+// get a short name of the type of v which excludes package name
+// and strips "()" from the end
+func getNodeType(node Node) string {
+ s := fmt.Sprintf("%T", node)
+ s = strings.TrimSuffix(s, "()")
+ if idx := strings.Index(s, "."); idx != -1 {
+ return s[idx+1:]
+ }
+ return s
+}
+
+func printDefault(w io.Writer, indent string, typeName string, content string) {
+ content = strings.TrimSpace(content)
+ if len(content) > 0 {
+ fmt.Fprintf(w, "%s%s '%s'\n", indent, typeName, content)
+ } else {
+ fmt.Fprintf(w, "%s%s\n", indent, typeName)
+ }
+}
+
+func getListFlags(f ListType) string {
+ var s string
+ if f&ListTypeOrdered != 0 {
+ s += "ordered "
+ }
+ if f&ListTypeDefinition != 0 {
+ s += "definition "
+ }
+ if f&ListTypeTerm != 0 {
+ s += "term "
+ }
+ if f&ListItemContainsBlock != 0 {
+ s += "has_block "
+ }
+ if f&ListItemBeginningOfList != 0 {
+ s += "start "
+ }
+ if f&ListItemEndOfList != 0 {
+ s += "end "
+ }
+ s = strings.TrimSpace(s)
+ return s
+}
+
+func printRecur(w io.Writer, node Node, prefix string, depth int) {
+ if node == nil {
+ return
+ }
+ indent := strings.Repeat(prefix, depth)
+
+ content := shortenString(getContent(node), 40)
+ typeName := getNodeType(node)
+ switch v := node.(type) {
+ case *Link:
+ content := "url=" + string(v.Destination)
+ printDefault(w, indent, typeName, content)
+ case *Image:
+ content := "url=" + string(v.Destination)
+ printDefault(w, indent, typeName, content)
+ case *List:
+ if v.Start > 1 {
+ content += fmt.Sprintf("start=%d ", v.Start)
+ }
+ if v.Tight {
+ content += "tight "
+ }
+ if v.IsFootnotesList {
+ content += "footnotes "
+ }
+ flags := getListFlags(v.ListFlags)
+ if len(flags) > 0 {
+ content += "flags=" + flags + " "
+ }
+ printDefault(w, indent, typeName, content)
+ case *ListItem:
+ if v.Tight {
+ content += "tight "
+ }
+ if v.IsFootnotesList {
+ content += "footnotes "
+ }
+ flags := getListFlags(v.ListFlags)
+ if len(flags) > 0 {
+ content += "flags=" + flags + " "
+ }
+ printDefault(w, indent, typeName, content)
+ default:
+ printDefault(w, indent, typeName, content)
+ }
+ for _, child := range node.GetChildren() {
+ printRecur(w, child, prefix, depth+1)
+ }
+}
diff --git a/vendor/github.com/gomarkdown/markdown/changes-from-blackfriday.md b/vendor/github.com/gomarkdown/markdown/changes-from-blackfriday.md
new file mode 100644
index 00000000..b618dfef
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/changes-from-blackfriday.md
@@ -0,0 +1,27 @@
+## Changes from blackfriday
+
+This library is derived from blackfriday library. Here's a list of changes.
+
+**Redesigned API**
+
+- split into 3 separate packages: ast, parser and html (for html renderer). This makes the API more manageable. It also separates e.g. parser option from renderer options
+- changed how AST node is represented from union-like representation (manually keeping track of the type of the node) to using interface{} (which is a Go way to combine an arbitrary value with its type)
+
+**Allow re-using most of html renderer logic**
+
+You can implement your own renderer by implementing `Renderer` interface.
+
+Implementing a full renderer is a lot of work and often you just want to tweak html rendering of few node typs.
+
+I've added a way to hook `Renderer.Render` function in html renderer with a custom function that can take over rendering of specific nodes.
+
+I use it myself to do syntax-highlighting of code snippets.
+
+**Speed up go test**
+
+Running `go test` was really slow (17 secs) because it did a poor man's version of fuzzing by feeding the parser all subsets of test strings in order to find panics
+due to incorrect parsing logic.
+
+I've moved that logic to `cmd/crashtest`, so that it can be run on CI but not slow down regular development.
+
+Now `go test` is blazing fast.
diff --git a/vendor/github.com/gomarkdown/markdown/codecov.yml b/vendor/github.com/gomarkdown/markdown/codecov.yml
new file mode 100644
index 00000000..f681ff11
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/codecov.yml
@@ -0,0 +1,8 @@
+coverage:
+ status:
+ project:
+ default:
+ # basic
+ target: 60%
+ threshold: 2%
+ base: auto
diff --git a/vendor/github.com/gomarkdown/markdown/doc.go b/vendor/github.com/gomarkdown/markdown/doc.go
new file mode 100644
index 00000000..9fb77e02
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/doc.go
@@ -0,0 +1,35 @@
+/*
+Package markdown implements markdown parser and HTML renderer.
+
+It parses markdown into AST format which can be serialized to HTML
+(using html.Renderer) or possibly other formats (using alternate renderers).
+
+Convert markdown to HTML
+
+The simplest way to convert markdown document to HTML
+
+ md := []byte("## markdown document")
+ html := markdown.ToHTML(md, nil, nil)
+
+Customizing parsing and HTML rendering
+
+You can customize parser and HTML renderer:
+
+ import (
+ "github.com/gomarkdown/markdown/parser"
+ "github.com/gomarkdown/markdown/renderer"
+ "github.com/gomarkdown/markdown"
+ )
+ extensions := parser.CommonExtensions | parser.AutoHeadingIDs
+ p := parser.NewWithExensions(extensions)
+
+ htmlFlags := html.CommonFlags | html.HrefTargetBlank
+ opts := html.RendererOptions{Flags: htmlFlags}
+ renderer := html.NewRenderer(opts)
+
+ md := []byte("markdown text")
+ html := markdown.ToHTML(md, p, renderer)
+
+For a cmd-line tool see https://github.com/gomarkdown/mdtohtml
+*/
+package markdown
diff --git a/vendor/github.com/gomarkdown/markdown/fuzz.go b/vendor/github.com/gomarkdown/markdown/fuzz.go
new file mode 100644
index 00000000..704182b8
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/fuzz.go
@@ -0,0 +1,9 @@
+// +build gofuzz
+
+package markdown
+
+// Fuzz is to be used by https://github.com/dvyukov/go-fuzz
+func Fuzz(data []byte) int {
+ Parse(data, nil)
+ return 0
+}
diff --git a/vendor/github.com/gomarkdown/markdown/go.mod b/vendor/github.com/gomarkdown/markdown/go.mod
new file mode 100644
index 00000000..899e3237
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/go.mod
@@ -0,0 +1,5 @@
+module github.com/gomarkdown/markdown
+
+go 1.12
+
+require golang.org/dl v0.0.0-20190829154251-82a15e2f2ead // indirect
diff --git a/vendor/github.com/gomarkdown/markdown/html/callouts.go b/vendor/github.com/gomarkdown/markdown/html/callouts.go
new file mode 100644
index 00000000..e377af22
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/html/callouts.go
@@ -0,0 +1,42 @@
+package html
+
+import (
+ "bytes"
+ "io"
+
+ "github.com/gomarkdown/markdown/ast"
+ "github.com/gomarkdown/markdown/parser"
+)
+
+// EscapeHTMLCallouts writes html-escaped d to w. It escapes &, <, > and " characters, *but*
+// expands callouts < ")
+ if !(isListItem(para.Parent) && ast.GetNextNode(para) == nil) {
+ r.cr(w)
+ }
+}
+
+func (r *Renderer) paragraph(w io.Writer, para *ast.Paragraph, entering bool) {
+ if skipParagraphTags(para) {
+ return
+ }
+ if entering {
+ r.paragraphEnter(w, para)
+ } else {
+ r.paragraphExit(w, para)
+ }
+}
+func (r *Renderer) image(w io.Writer, node *ast.Image, entering bool) {
+ if entering {
+ r.imageEnter(w, node)
+ } else {
+ r.imageExit(w, node)
+ }
+}
+
+func (r *Renderer) code(w io.Writer, node *ast.Code) {
+ r.outs(w, "${content}
emitted by html.Renderer
+ func renderHookCodeBlock(w io.Writer, node *ast.Node, entering bool) (ast.WalkStatus, bool) {
+ _, ok := node.Data.(*ast.CodeBlockData)
+ if !ok {
+ return ast.GoToNext, false
+ }
+ io.WriteString(w, "code_replacement")
+ return ast.GoToNext, true
+ }
+
+ opts := html.RendererOptions{
+ RenderNodeHook: renderHookCodeBlock,
+ }
+ renderer := html.NewRenderer(opts)
+*/
+package html
diff --git a/vendor/github.com/gomarkdown/markdown/html/esc.go b/vendor/github.com/gomarkdown/markdown/html/esc.go
new file mode 100644
index 00000000..89ec9a27
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/html/esc.go
@@ -0,0 +1,50 @@
+package html
+
+import (
+ "html"
+ "io"
+)
+
+var Escaper = [256][]byte{
+ '&': []byte("&"),
+ '<': []byte("<"),
+ '>': []byte(">"),
+ '"': []byte("""),
+}
+
+// EscapeHTML writes html-escaped d to w. It escapes &, <, > and " characters.
+func EscapeHTML(w io.Writer, d []byte) {
+ var start, end int
+ n := len(d)
+ for end < n {
+ escSeq := Escaper[d[end]]
+ if escSeq != nil {
+ w.Write(d[start:end])
+ w.Write(escSeq)
+ start = end + 1
+ }
+ end++
+ }
+ if start < n && end <= n {
+ w.Write(d[start:end])
+ }
+}
+
+func escLink(w io.Writer, text []byte) {
+ unesc := html.UnescapeString(string(text))
+ EscapeHTML(w, []byte(unesc))
+}
+
+// Escape writes the text to w, but skips the escape character.
+func Escape(w io.Writer, text []byte) {
+ esc := false
+ for i := 0; i < len(text); i++ {
+ if text[i] == '\\' {
+ esc = !esc
+ }
+ if esc && text[i] == '\\' {
+ continue
+ }
+ w.Write([]byte{text[i]})
+ }
+}
diff --git a/vendor/github.com/gomarkdown/markdown/html/renderer.go b/vendor/github.com/gomarkdown/markdown/html/renderer.go
new file mode 100644
index 00000000..367f7dfa
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/html/renderer.go
@@ -0,0 +1,1318 @@
+package html
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "regexp"
+ "sort"
+ "strconv"
+ "strings"
+
+ "github.com/gomarkdown/markdown/ast"
+)
+
+// Flags control optional behavior of HTML renderer.
+type Flags int
+
+// IDTag is the tag used for tag identification, it defaults to "id", some renderers
+// may wish to override this and use e.g. "anchor".
+var IDTag = "id"
+
+// HTML renderer configuration options.
+const (
+ FlagsNone Flags = 0
+ SkipHTML Flags = 1 << iota // Skip preformatted HTML blocks
+ SkipImages // Skip embedded images
+ SkipLinks // Skip all links
+ Safelink // Only link to trusted protocols
+ NofollowLinks // Only link with rel="nofollow"
+ NoreferrerLinks // Only link with rel="noreferrer"
+ HrefTargetBlank // Add a blank target
+ CompletePage // Generate a complete HTML page
+ UseXHTML // Generate XHTML output instead of HTML
+ FootnoteReturnLinks // Generate a link at the end of a footnote to return to the source
+ FootnoteNoHRTag // Do not output an HR after starting a footnote list.
+ Smartypants // Enable smart punctuation substitutions
+ SmartypantsFractions // Enable smart fractions (with Smartypants)
+ SmartypantsDashes // Enable smart dashes (with Smartypants)
+ SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants)
+ SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering
+ SmartypantsQuotesNBSP // Enable « French guillemets » (with Smartypants)
+ TOC // Generate a table of contents
+
+ CommonFlags Flags = Smartypants | SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes
+)
+
+var (
+ htmlTagRe = regexp.MustCompile("(?i)^" + htmlTag)
+)
+
+const (
+ htmlTag = "(?:" + openTag + "|" + closeTag + "|" + htmlComment + "|" +
+ processingInstruction + "|" + declaration + "|" + cdata + ")"
+ closeTag = "" + tagName + "\\s*[>]"
+ openTag = "<" + tagName + attribute + "*" + "\\s*/?>"
+ attribute = "(?:" + "\\s+" + attributeName + attributeValueSpec + "?)"
+ attributeValue = "(?:" + unquotedValue + "|" + singleQuotedValue + "|" + doubleQuotedValue + ")"
+ attributeValueSpec = "(?:" + "\\s*=" + "\\s*" + attributeValue + ")"
+ attributeName = "[a-zA-Z_:][a-zA-Z0-9:._-]*"
+ cdata = ""
+ declaration = "]*>"
+ doubleQuotedValue = "\"[^\"]*\""
+ htmlComment = "|"
+ processingInstruction = "[<][?].*?[?][>]"
+ singleQuotedValue = "'[^']*'"
+ tagName = "[A-Za-z][A-Za-z0-9-]*"
+ unquotedValue = "[^\"'=<>`\\x00-\\x20]+"
+)
+
+// RenderNodeFunc allows reusing most of Renderer logic and replacing
+// rendering of some nodes. If it returns false, Renderer.RenderNode
+// will execute its logic. If it returns true, Renderer.RenderNode will
+// skip rendering this node and will return WalkStatus
+type RenderNodeFunc func(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool)
+
+// RendererOptions is a collection of supplementary parameters tweaking
+// the behavior of various parts of HTML renderer.
+type RendererOptions struct {
+ // Prepend this text to each relative URL.
+ AbsolutePrefix string
+ // Add this text to each footnote anchor, to ensure uniqueness.
+ FootnoteAnchorPrefix string
+ // Show this text inside the tag for a footnote return link, if the
+ // FootnoteReturnLinks flag is enabled. If blank, the string
+ // [return] is used.
+ FootnoteReturnLinkContents string
+ // CitationFormatString defines how a citation is rendered. If blnck, the string
+ // [%s] is used. Where %s will be substituted with the citation target.
+ CitationFormatString string
+ // If set, add this text to the front of each Heading ID, to ensure uniqueness.
+ HeadingIDPrefix string
+ // If set, add this text to the back of each Heading ID, to ensure uniqueness.
+ HeadingIDSuffix string
+
+ Title string // Document title (used if CompletePage is set)
+ CSS string // Optional CSS file URL (used if CompletePage is set)
+ Icon string // Optional icon file URL (used if CompletePage is set)
+ Head []byte // Optional head data injected in the section (used if CompletePage is set)
+
+ Flags Flags // Flags allow customizing this renderer's behavior
+
+ // if set, called at the start of RenderNode(). Allows replacing
+ // rendering of some nodes
+ RenderNodeHook RenderNodeFunc
+
+ // Comments is a list of comments the renderer should detect when
+ // parsing code blocks and detecting callouts.
+ Comments [][]byte
+
+ // Generator is a meta tag that is inserted in the generated HTML so show what rendered it. It should not include the closing tag.
+ // Defaults (note content quote is not closed) to ` " or ">"
+
+ // Track heading IDs to prevent ID collision in a single generation.
+ headingIDs map[string]int
+
+ lastOutputLen int
+ disableTags int
+
+ sr *SPRenderer
+
+ documentMatter ast.DocumentMatters // keep track of front/main/back matter.
+}
+
+// NewRenderer creates and configures an Renderer object, which
+// satisfies the Renderer interface.
+func NewRenderer(opts RendererOptions) *Renderer {
+ // configure the rendering engine
+ closeTag := ">"
+ if opts.Flags&UseXHTML != 0 {
+ closeTag = " />"
+ }
+
+ if opts.FootnoteReturnLinkContents == "" {
+ opts.FootnoteReturnLinkContents = `[return]`
+ }
+ if opts.CitationFormatString == "" {
+ opts.CitationFormatString = `[%s]`
+ }
+ if opts.Generator == "" {
+ opts.Generator = ` = len(tagname) {
+ break
+ }
+
+ if strings.ToLower(string(tag[i]))[0] != tagname[j] {
+ return false, -1
+ }
+ }
+
+ if i == len(tag) {
+ return false, -1
+ }
+
+ rightAngle := skipUntilCharIgnoreQuotes(tag, i, '>')
+ if rightAngle >= i {
+ return true, rightAngle
+ }
+
+ return false, -1
+}
+
+func isRelativeLink(link []byte) (yes bool) {
+ // a tag begin with '#'
+ if link[0] == '#' {
+ return true
+ }
+
+ // link begin with '/' but not '//', the second maybe a protocol relative link
+ if len(link) >= 2 && link[0] == '/' && link[1] != '/' {
+ return true
+ }
+
+ // only the root '/'
+ if len(link) == 1 && link[0] == '/' {
+ return true
+ }
+
+ // current directory : begin with "./"
+ if bytes.HasPrefix(link, []byte("./")) {
+ return true
+ }
+
+ // parent directory : begin with "../"
+ if bytes.HasPrefix(link, []byte("../")) {
+ return true
+ }
+
+ return false
+}
+
+func (r *Renderer) ensureUniqueHeadingID(id string) string {
+ for count, found := r.headingIDs[id]; found; count, found = r.headingIDs[id] {
+ tmp := fmt.Sprintf("%s-%d", id, count+1)
+
+ if _, tmpFound := r.headingIDs[tmp]; !tmpFound {
+ r.headingIDs[id] = count + 1
+ id = tmp
+ } else {
+ id = id + "-1"
+ }
+ }
+
+ if _, found := r.headingIDs[id]; !found {
+ r.headingIDs[id] = 0
+ }
+
+ return id
+}
+
+func (r *Renderer) addAbsPrefix(link []byte) []byte {
+ if r.opts.AbsolutePrefix != "" && isRelativeLink(link) && link[0] != '.' {
+ newDest := r.opts.AbsolutePrefix
+ if link[0] != '/' {
+ newDest += "/"
+ }
+ newDest += string(link)
+ return []byte(newDest)
+ }
+ return link
+}
+
+func appendLinkAttrs(attrs []string, flags Flags, link []byte) []string {
+ if isRelativeLink(link) {
+ return attrs
+ }
+ var val []string
+ if flags&NofollowLinks != 0 {
+ val = append(val, "nofollow")
+ }
+ if flags&NoreferrerLinks != 0 {
+ val = append(val, "noreferrer")
+ }
+ if flags&HrefTargetBlank != 0 {
+ attrs = append(attrs, `target="_blank"`)
+ }
+ if len(val) == 0 {
+ return attrs
+ }
+ attr := fmt.Sprintf("rel=%q", strings.Join(val, " "))
+ return append(attrs, attr)
+}
+
+func isMailto(link []byte) bool {
+ return bytes.HasPrefix(link, []byte("mailto:"))
+}
+
+func needSkipLink(flags Flags, dest []byte) bool {
+ if flags&SkipLinks != 0 {
+ return true
+ }
+ return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest)
+}
+
+func isSmartypantable(node ast.Node) bool {
+ switch node.GetParent().(type) {
+ case *ast.Link, *ast.CodeBlock, *ast.Code:
+ return false
+ }
+ return true
+}
+
+func appendLanguageAttr(attrs []string, info []byte) []string {
+ if len(info) == 0 {
+ return attrs
+ }
+ endOfLang := bytes.IndexAny(info, "\t ")
+ if endOfLang < 0 {
+ endOfLang = len(info)
+ }
+ s := `class="language-` + string(info[:endOfLang]) + `"`
+ return append(attrs, s)
+}
+
+func (r *Renderer) outTag(w io.Writer, name string, attrs []string) {
+ s := name
+ if len(attrs) > 0 {
+ s += " " + strings.Join(attrs, " ")
+ }
+ io.WriteString(w, s+">")
+ r.lastOutputLen = 1
+}
+
+func footnoteRef(prefix string, node *ast.Link) string {
+ urlFrag := prefix + string(slugify(node.Destination))
+ nStr := strconv.Itoa(node.NoteID)
+ anchor := `` + nStr + ``
+ return `` + anchor + ``
+}
+
+func footnoteItem(prefix string, slug []byte) string {
+ return `", "", "", "", ""}
+)
+
+func headingOpenTagFromLevel(level int) string {
+ if level < 1 || level > 5 {
+ return "
5 {
+ return "
"
+ }
+ return closeHTags[level-1]
+}
+
+func (r *Renderer) outHRTag(w io.Writer, attrs []string) {
+ hr := tagWithAttributes("
")
+}
+
+func (r *Renderer) text(w io.Writer, text *ast.Text) {
+ if r.opts.Flags&Smartypants != 0 {
+ var tmp bytes.Buffer
+ EscapeHTML(&tmp, text.Literal)
+ r.sr.Process(w, tmp.Bytes())
+ } else {
+ _, parentIsLink := text.Parent.(*ast.Link)
+ if parentIsLink {
+ escLink(w, text.Literal)
+ } else {
+ EscapeHTML(w, text.Literal)
+ }
+ }
+}
+
+func (r *Renderer) hardBreak(w io.Writer, node *ast.Hardbreak) {
+ r.outOneOf(w, r.opts.Flags&UseXHTML == 0, "
", "
")
+ r.cr(w)
+}
+
+func (r *Renderer) nonBlockingSpace(w io.Writer, node *ast.NonBlockingSpace) {
+ r.outs(w, " ")
+}
+
+func (r *Renderer) outOneOf(w io.Writer, outFirst bool, first string, second string) {
+ if outFirst {
+ r.outs(w, first)
+ } else {
+ r.outs(w, second)
+ }
+}
+
+func (r *Renderer) outOneOfCr(w io.Writer, outFirst bool, first string, second string) {
+ if outFirst {
+ r.cr(w)
+ r.outs(w, first)
+ } else {
+ r.outs(w, second)
+ r.cr(w)
+ }
+}
+
+func (r *Renderer) htmlSpan(w io.Writer, span *ast.HTMLSpan) {
+ if r.opts.Flags&SkipHTML == 0 {
+ r.out(w, span.Literal)
+ }
+}
+
+func (r *Renderer) linkEnter(w io.Writer, link *ast.Link) {
+ var attrs []string
+ dest := link.Destination
+ dest = r.addAbsPrefix(dest)
+ var hrefBuf bytes.Buffer
+ hrefBuf.WriteString("href=\"")
+ escLink(&hrefBuf, dest)
+ hrefBuf.WriteByte('"')
+ attrs = append(attrs, hrefBuf.String())
+ if link.NoteID != 0 {
+ r.outs(w, footnoteRef(r.opts.FootnoteAnchorPrefix, link))
+ return
+ }
+
+ attrs = appendLinkAttrs(attrs, r.opts.Flags, dest)
+ if len(link.Title) > 0 {
+ var titleBuff bytes.Buffer
+ titleBuff.WriteString("title=\"")
+ EscapeHTML(&titleBuff, link.Title)
+ titleBuff.WriteByte('"')
+ attrs = append(attrs, titleBuff.String())
+ }
+ r.outTag(w, "")
+ }
+}
+
+func (r *Renderer) link(w io.Writer, link *ast.Link, entering bool) {
+ // mark it but don't link it if it is not a safe link: no smartypants
+ if needSkipLink(r.opts.Flags, link.Destination) {
+ r.outOneOf(w, entering, "", "")
+ return
+ }
+
+ if entering {
+ r.linkEnter(w, link)
+ } else {
+ r.linkExit(w, link)
+ }
+}
+
+func (r *Renderer) imageEnter(w io.Writer, image *ast.Image) {
+ dest := image.Destination
+ dest = r.addAbsPrefix(dest)
+ if r.disableTags == 0 {
+ //if options.safe && potentiallyUnsafe(dest) {
+ //out(w, ``)
+ }
+}
+
+func (r *Renderer) paragraphEnter(w io.Writer, para *ast.Paragraph) {
+ // TODO: untangle this clusterfuck about when the newlines need
+ // to be added and when not.
+ prev := ast.GetPrevNode(para)
+ if prev != nil {
+ switch prev.(type) {
+ case *ast.HTMLBlock, *ast.List, *ast.Paragraph, *ast.Heading, *ast.CaptionFigure, *ast.CodeBlock, *ast.BlockQuote, *ast.Aside, *ast.HorizontalRule:
+ r.cr(w)
+ }
+ }
+
+ if prev == nil {
+ _, isParentBlockQuote := para.Parent.(*ast.BlockQuote)
+ if isParentBlockQuote {
+ r.cr(w)
+ }
+ _, isParentAside := para.Parent.(*ast.Aside)
+ if isParentAside {
+ r.cr(w)
+ }
+ }
+
+ tag := tagWithAttributes("")
+ EscapeHTML(w, node.Literal)
+ r.outs(w, "
")
+}
+
+func (r *Renderer) htmlBlock(w io.Writer, node *ast.HTMLBlock) {
+ if r.opts.Flags&SkipHTML != 0 {
+ return
+ }
+ r.cr(w)
+ r.out(w, node.Literal)
+ r.cr(w)
+}
+
+func (r *Renderer) headingEnter(w io.Writer, nodeData *ast.Heading) {
+ var attrs []string
+ var class string
+ // TODO(miek): add helper functions for coalescing these classes.
+ if nodeData.IsTitleblock {
+ class = "title"
+ }
+ if nodeData.IsSpecial {
+ if class != "" {
+ class += " special"
+ } else {
+ class = "special"
+ }
+ }
+ if class != "" {
+ attrs = []string{`class="` + class + `"`}
+ }
+ if nodeData.HeadingID != "" {
+ id := r.ensureUniqueHeadingID(nodeData.HeadingID)
+ if r.opts.HeadingIDPrefix != "" {
+ id = r.opts.HeadingIDPrefix + id
+ }
+ if r.opts.HeadingIDSuffix != "" {
+ id = id + r.opts.HeadingIDSuffix
+ }
+ attrID := `id="` + id + `"`
+ attrs = append(attrs, attrID)
+ }
+ attrs = append(attrs, BlockAttrs(nodeData)...)
+ r.cr(w)
+ r.outTag(w, headingOpenTagFromLevel(nodeData.Level), attrs)
+}
+
+func (r *Renderer) headingExit(w io.Writer, heading *ast.Heading) {
+ r.outs(w, headingCloseTagFromLevel(heading.Level))
+ if !(isListItem(heading.Parent) && ast.GetNextNode(heading) == nil) {
+ r.cr(w)
+ }
+}
+
+func (r *Renderer) heading(w io.Writer, node *ast.Heading, entering bool) {
+ if entering {
+ r.headingEnter(w, node)
+ } else {
+ r.headingExit(w, node)
+ }
+}
+
+func (r *Renderer) horizontalRule(w io.Writer, node *ast.HorizontalRule) {
+ r.cr(w)
+ r.outHRTag(w, BlockAttrs(node))
+ r.cr(w)
+}
+
+func (r *Renderer) listEnter(w io.Writer, nodeData *ast.List) {
+ // TODO: attrs don't seem to be set
+ var attrs []string
+
+ if nodeData.IsFootnotesList {
+ r.outs(w, "\n 0 {
+ attrs = append(attrs, fmt.Sprintf(`start="%d"`, nodeData.Start))
+ }
+ openTag = "
\n")
+ }
+}
+
+func (r *Renderer) list(w io.Writer, list *ast.List, entering bool) {
+ if entering {
+ r.listEnter(w, list)
+ } else {
+ r.listExit(w, list)
+ }
+}
+
+func (r *Renderer) listItemEnter(w io.Writer, listItem *ast.ListItem) {
+ if listItemOpenCR(listItem) {
+ r.cr(w)
+ }
+ if listItem.RefLink != nil {
+ slug := slugify(listItem.RefLink)
+ r.outs(w, footnoteItem(r.opts.FootnoteAnchorPrefix, slug))
+ return
+ }
+
+ openTag := "
")
+ code := tagWithAttributes("
")
+ if !isListItem(codeBlock.Parent) {
+ r.cr(w)
+ }
+}
+
+func (r *Renderer) caption(w io.Writer, caption *ast.Caption, entering bool) {
+ if entering {
+ r.outs(w, "")
+ r.outs(w, "
")
+ // XXX: this is to adhere to a rather silly test. Should fix test.
+ if ast.GetFirstChild(node) == nil {
+ r.cr(w)
+ }
+ } else {
+ r.outs(w, "")
+ r.cr(w)
+ }
+}
+
+func (r *Renderer) matter(w io.Writer, node *ast.DocumentMatter, entering bool) {
+ if !entering {
+ return
+ }
+ if r.documentMatter != ast.DocumentMatterNone {
+ r.outs(w, "\n")
+ }
+ switch node.Matter {
+ case ast.DocumentMatterFront:
+ r.outs(w, ` ", "")
+ case *ast.BlockQuote:
+ tag := tagWithAttributes("")
+ case *ast.Aside:
+ tag := tagWithAttributes("