Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
234 commits
Select commit Hold shift + click to select a range
06515e9
Rename public constants to idiomatic Go
rtfb Oct 26, 2015
ee98bc0
Massive replacement of C_STYLE flags to typed ones
rtfb Oct 26, 2015
b16c9b3
Simplify callbacks in Renderer interface
rtfb Oct 26, 2015
82be6ca
Remove callback from Header renderer event
rtfb Oct 26, 2015
af1b26f
Remove callback from List renderer event
rtfb Oct 26, 2015
6d6be3d
Remove callback from Paragraph renderer event
rtfb Oct 26, 2015
bc4735b
Remove callback from Footnotes renderer event
rtfb Oct 26, 2015
29f02f7
Rename Renderer method receivers
rtfb Oct 26, 2015
ef08788
Remove a couple calls to Truncate() from parser
rtfb Oct 26, 2015
8e90e8b
Remove calls to Truncate() from linebreak parser
rtfb Oct 27, 2015
dd01088
Remove last call to Truncate() from parser
rtfb Oct 27, 2015
a783448
Fix smartypants smart dash processing
rtfb Oct 31, 2015
6e42506
Remove 'out' parameter from renderer interface
rtfb Nov 1, 2015
7ec5039
Remove 'out' parameter from parser funcs
rtfb Nov 1, 2015
352ffde
Remove a bunch of 'out' parameters from calls, WIP
rtfb Nov 1, 2015
dce6df9
Add infrastructure to collect output in a buffer
rtfb Nov 3, 2015
0823348
Fix Begin/EndHeader to use the new 'out'-less interface
rtfb Nov 4, 2015
91771dc
Redirect output to a capture buffer where necessary
rtfb Nov 4, 2015
7a97ffe
Remove almost all uses of 'out' in HTML renderer
rtfb Nov 4, 2015
0dfcd3b
Remove all uses of 'out' in Latex renderer
rtfb Nov 5, 2015
114d6b0
Eradicate 'out' parameter in top level code
rtfb Nov 5, 2015
9723518
Enable writing plain text straight to output
rtfb Nov 9, 2015
d1b544e
HACK: render TOC the old way, backup and truncate output
rtfb Nov 9, 2015
f837865
Fix rendering of tables
rtfb Nov 9, 2015
2bbed30
Add AST data structures
rtfb Mar 30, 2016
7846a31
Remove unused code
rtfb Mar 30, 2016
9489324
Add a new renderer from AST
rtfb Mar 30, 2016
7c95b7a
Construct AST WIP: add block-level nodes
rtfb Mar 30, 2016
eb70b23
Construct AST WIP: add inline-level nodes
rtfb Mar 30, 2016
70124f1
Enable full AST construction, use the new renderer
rtfb Mar 30, 2016
a32ecdb
Fix footnote tests
rtfb Mar 30, 2016
6fe811b
Fix TitleBlock test
rtfb Mar 30, 2016
886a140
Extract local funcs/vars into methods/members
rtfb Mar 30, 2016
0382dab
The single node renderer is a separate func now
rtfb Mar 30, 2016
dc7d4b6
Remove some cruft
rtfb Mar 30, 2016
4d74c6a
Make common flags and extensions public
rtfb Mar 30, 2016
c1011c8
Remove unneeded reference to Renderer from parser
rtfb Mar 30, 2016
4c11a2a
Expose Parse func that grabs input and returns AST
rtfb Mar 30, 2016
fd2d69d
Make renderer write to an explicit io.Writer
rtfb Mar 30, 2016
4a7ff56
Rename Html to HTML to adhere to Go style
rtfb Mar 31, 2016
7869a12
Combine two Smartypants structs into one
rtfb Mar 31, 2016
a55b261
Run Smartypants as a separate pass over the AST
rtfb Apr 1, 2016
71fe9a1
Remove dead code
rtfb Apr 1, 2016
2a07386
Rename HtmlFlags to HTMLFlags to adhere to Go style
rtfb Apr 1, 2016
60026cc
Make ListData a nested struct instead of pointer
rtfb Apr 1, 2016
c8eb733
Fix typos
rtfb Apr 1, 2016
67f85cf
Move code block fields to a nested struct
rtfb Apr 1, 2016
4ba9919
Store cell alignment in own type instead of int
rtfb Apr 1, 2016
bcd5b5b
Move table cell fields to a nested struct
rtfb Apr 1, 2016
8a4d4fa
Move Header-related fields to a nested struct
rtfb Apr 1, 2016
04673c9
Improve documentation for Node struct
rtfb Apr 1, 2016
f1361aa
Make ForEachNode func a Walk method on Node
rtfb Apr 1, 2016
32802db
Go style: rename Toc to TOC
rtfb Apr 1, 2016
02a5ce3
Go style: Html{Block|Span} -> HTML{Block|Span}
rtfb Apr 1, 2016
0b69796
Go style: more Html -> HTML renames
rtfb Apr 1, 2016
d7f1878
Implement TOC and OmitContents
rtfb Apr 4, 2016
15e052e
Move all testing helper funcs in one place
rtfb Apr 4, 2016
b069de6
Wrap inline test parameters in a struct
rtfb Apr 4, 2016
a658caa
Use TestParams in block tests
rtfb Apr 4, 2016
0c7120d
Fix old omission in doTestsBlockWithRunner
rtfb Apr 4, 2016
f1fd3a6
Do away with doTestsInlineParam
rtfb Apr 4, 2016
f35fae8
Extract panic recovery code
rtfb Apr 4, 2016
0774c06
Get rid of unnecessary test helpers
rtfb Apr 4, 2016
607478a
Implement SkipLinks, add test
rtfb Apr 4, 2016
106f1ec
Add test for CompletePage flag
rtfb Apr 4, 2016
6bd3120
Add test for UseXHTML
rtfb Apr 5, 2016
76062d4
Fixup broken test reporting
rtfb Apr 5, 2016
e7d4574
Give node visitor callback type a name and docs
rtfb Apr 5, 2016
9da90c5
Allow NodeVisitor to have some control over traversal
rtfb Apr 5, 2016
fecfec2
Implement SkipImages and add test
rtfb Apr 5, 2016
7e9a574
Implement SkipStyle, add test
rtfb Apr 5, 2016
83b4cb6
Implement SkipHTML, add test
rtfb Apr 5, 2016
123179b
Make Markdown the most general API call
rtfb Apr 5, 2016
4f8d288
Remove a bit of cruft from HTML renderer
rtfb Apr 5, 2016
1303ea1
Cleanup renderer constructors
rtfb Apr 5, 2016
9f5de86
Go style: take advantage of zero value init
rtfb Apr 5, 2016
24e146a
Make HTMLRendererParameters a substruct of HTML
rtfb Apr 5, 2016
98ddf98
Get rid of unneeded method in Renderer
rtfb Apr 11, 2016
c9ea588
Convert uint32 fields to ints
rtfb Apr 11, 2016
c207eca
Clean up Renderer interface: remove all callbacks
rtfb Apr 11, 2016
c26fdef
Move html entity regexp to where it's used
rtfb Apr 11, 2016
e95d230
Rename HTML to HTMLRenderer
rtfb Apr 11, 2016
76d8c71
Unduplicate attrEscape funcs
rtfb Apr 11, 2016
3575453
Move a couple helpers to parser where they're used
rtfb Apr 11, 2016
37ffc1c
Make Node satisfy the Stringer interface
Ambrevar Jul 1, 2016
2e53c20
Return a *HTMLRenderer from NewHTMLRenderer
Ambrevar Jul 1, 2016
20aa621
Fix empty path to CSS
Ambrevar Jul 1, 2016
a41899b
v2: Only include test helpers inside test package.
dmitshur Jul 1, 2016
7ee035e
Merge pull request #276 from russross/v2-move-test-helpers-to-test-pkg
rtfb Jul 2, 2016
ab20da6
Merge pull request #275 from Ambrevar/v2css
rtfb Jul 2, 2016
f90a576
Untangle some mess with attribute escaping
rtfb Jul 2, 2016
cb6bd67
Remove dead HTMLWriter code
rtfb Jul 4, 2016
2f1f0b6
Add RenderNode to Renderer interface
rtfb Jul 5, 2016
6291a00
Remove dead fields from HTMLRenderer
rtfb Jul 5, 2016
2560c5f
Fix issue in fenced code block pre-processing.
dmitshur Jul 15, 2016
fd97b7d
Merge pull request #282 from russross/v2-fix-279
rtfb Jul 16, 2016
89653c9
Merge pull request #274 from Ambrevar/v2misc
rtfb Jul 27, 2016
a4f1e5c
Limit Node.String() to print itself, no children
rtfb Jul 27, 2016
ce05617
Return *Latex from NewLatexRenderer
rtfb Jul 27, 2016
f7ec3b0
Fix a few lint errors, a.k.a. improve docs
rtfb Jul 27, 2016
72633fd
Lint node.go
rtfb Jul 27, 2016
e054c96
More lint: markdown.go and ripples to other files
rtfb Jul 27, 2016
cd2f079
More lint: inline.go
rtfb Jul 27, 2016
6d7f5e1
More lint: block.go
rtfb Jul 27, 2016
bd774a2
More lint: smartypants.go
rtfb Jul 27, 2016
46b7355
Fix bullet points in MarkdownCommon docs
rtfb Jul 28, 2016
a5270b6
Shorten method receivers in Smartypants
rtfb Jul 28, 2016
ca4bf01
Merge pull request #284 from russross/fix-lint
rtfb Jul 28, 2016
a9baf84
Unpublish and rename LinkType constants (#285)
rtfb Jul 29, 2016
c61b63f
Repeat a run of reference tests under benchmark
rtfb Jul 25, 2016
3fe4ad2
Enable common extensions for benchmark
rtfb Jul 30, 2016
bb31c53
Merge pull request #286 from russross/add-benchmark
rtfb Jul 31, 2016
2e23e31
Fix typo
rtfb Aug 1, 2016
ff2d79c
Fix walk so that it does not step outside the root node
Ambrevar Aug 3, 2016
0f3eafd
Merge pull request #287 from Ambrevar/v2walkfix
rtfb Aug 5, 2016
4d75600
Move TOC generation to the HTML Renderer
Ambrevar Aug 9, 2016
b5ff8e0
Break lines properly in TOC generation and omit content if required
Ambrevar Aug 9, 2016
925d99b
Add TOC generation tests
Ambrevar Aug 9, 2016
413328d
Add Icon parameter to the HTML renderer
Ambrevar Aug 9, 2016
c9f76b5
Merge pull request #294 from Ambrevar/v2TOC2Renderer
rtfb Aug 9, 2016
37141d5
Merge pull request #296 from Ambrevar/v2icon
rtfb Aug 9, 2016
fdbedcd
Export tree manipulation functions
Ambrevar Aug 9, 2016
02da1df
Factor Smartypants to HTML
Ambrevar Aug 10, 2016
9bff410
Merge pull request #293 from Ambrevar/v2ExportFuncs
rtfb Aug 10, 2016
9926922
Merge pull request #295 from Ambrevar/v2FactorSmarty
rtfb Aug 10, 2016
225250d
html.go: Lint RenderNode()
Ambrevar Aug 10, 2016
5760656
Merge pull request #299 from Ambrevar/v2lint
rtfb Aug 12, 2016
6fd47b3
v2: Only split when inline callbacks consume some bytes (#301)
Ambrevar Aug 19, 2016
771cf41
Get rid of secondPass function
rtfb Aug 28, 2016
efa77da
Fix omission in list item flags
rtfb Aug 28, 2016
ea8dfc4
Move reference extraction to paragraph parser
rtfb Aug 29, 2016
6947216
Move footnote rendering to the renderer
rtfb Sep 3, 2016
43ba539
Add some documentation to reference struct
rtfb Sep 3, 2016
3c2cb1f
Fix typo
rtfb Sep 3, 2016
d36199c
Rename firstPass -> preprocess
rtfb Sep 3, 2016
91753e8
v2: Extract package level documentation to doc.go (#303)
rtfb Sep 5, 2016
0a029cb
v2: Run the reference benchmark on Travis (#304)
rtfb Sep 5, 2016
b91b571
Merge pull request #302 from russross/v2-move-footnotest-to-html
rtfb Sep 10, 2016
da06641
Add Go 1.{6,7}, stop building on ancient versions
rtfb Sep 10, 2016
39b8ed1
Avoid general purpose ToLower in autolink detection
rtfb Sep 10, 2016
e0fc1a0
Don't bother removing trailing newlines in code blocks
rtfb Sep 10, 2016
31f2685
Remove lots of string literals
rtfb Sep 10, 2016
4688db5
Remove the LaTeX renderer stub and point to Ambrevar's implementation
Ambrevar Sep 10, 2016
993325d
Roll our own implementation of HTML escaper
rtfb Sep 10, 2016
d9ffdb7
Use bytes.IndexByte to skip til EOL
rtfb Sep 10, 2016
64d8e9e
Merge pull request #300 from Ambrevar/rmLaTeX
rtfb Sep 12, 2016
8a11177
Add direct link to a footnote from it's referer
rtfb Sep 17, 2016
1aa82c4
Make golint happy: fix method receiver
rtfb Sep 17, 2016
6141d5f
Merge pull request #306 from russross/v2-add-links-to-footnotes
rtfb Oct 3, 2016
14a0c48
Fix walk with non-container root nodes
Ambrevar Oct 5, 2016
4618036
Simplify escapeHTML and uncomment it's benchmark
rtfb Oct 8, 2016
c60ee1a
Avoid allocating []byte for every written newline
rtfb Oct 8, 2016
2b483a8
Merge pull request #310 from Ambrevar/v2FixWalkNoContainer
rtfb Oct 8, 2016
627dc87
Add missing type to TableAlignment* constants
Ambrevar Oct 9, 2016
52676fb
Merge pull request #314 from Ambrevar/v2consttype
rtfb Oct 9, 2016
6438ce6
Avoid some conditionals in inline parser
Oct 29, 2016
9357a8f
Simplify inline() even more
Oct 29, 2016
22a3e5b
Avoid calling bytes.Split() in appendLanguageAttr
Oct 29, 2016
120bb2f
Get rid of the preprocess stage
rtfb Nov 10, 2016
b61f73e
Ditch SkipStyle flag
rtfb Nov 24, 2016
9c4ef64
Move TOC and OmitContents to HTML flags
rtfb Nov 24, 2016
3d1baec
Merge pull request #323 from russross/ditch-skip-style
rtfb Dec 7, 2016
a4dd8ad
Merge pull request #324 from russross/move-toc-to-html
rtfb Dec 7, 2016
fb56a7e
Update README for v2
rtfb Jan 26, 2017
f805c77
HTTPS allthethings!
rtfb Jan 27, 2017
ea57e93
Several fixes after code review
rtfb Feb 2, 2017
d04a53c
Merge branch 'v2' into v2-perf-tweaks
rtfb Feb 2, 2017
e81d1d1
Change the public interface to use functional options
rtfb Feb 2, 2017
ad7f7c5
Merge pull request #322 from russross/v2-perf-tweaks
rtfb Feb 2, 2017
5e1065f
Fix blooper: remove dead code
rtfb Feb 2, 2017
7500a7e
Fix #180 again
rtfb Feb 12, 2017
747587a
Fix all headings wrongly referred to as headers
rtfb Feb 12, 2017
b98e306
Merge pull request #332 from russross/v2-rename-headers-to-headings
rtfb Feb 14, 2017
5ebfae5
Merge pull request #331 from russross/v2-fix-180-again
rtfb Feb 14, 2017
a8c45a7
Merge branch 'v2' into v2-functional-opts
rtfb Feb 14, 2017
41159b3
Fix bad merge
rtfb Feb 14, 2017
af57319
Merge pull request #328 from russross/v2-functional-opts
rtfb May 6, 2017
e7910a8
Merge pull request #327 from russross/readme-update
rtfb May 6, 2017
3cc9341
Merge Parser into Processor
Ambrevar May 29, 2017
a47518d
[SQUASH] Doc update
Ambrevar Jun 1, 2017
2501229
Rename Markdown()->Run() and Processor->Markdown
Ambrevar Jun 5, 2017
70c446a
Merge pull request #365 from Ambrevar/v2
rtfb Jun 9, 2017
479920a
Improve the Renderer interface
rtfb Jul 9, 2017
257ccba
Catch up README with the latest changes in code
rtfb Jul 9, 2017
427717f
Use io.WriteString instead of w.Write([]byte(str))
rtfb Jul 10, 2017
f86f06b
Merge pull request #376 from russross/v2-improve-renderer-368
rtfb Jul 26, 2017
f42ca5b
Merge pull request #377 from russross/v2-catch-up-readme
rtfb Jul 26, 2017
d548761
Several small documentation fixes
rtfb Jul 29, 2017
19913a1
Address feedback
rtfb Jul 30, 2017
e0df702
Merge pull request #382 from russross/v2-final-docs-fixes
rtfb Aug 1, 2017
4582051
Unexport a bunch of constants private to HTML renderer (#381)
rtfb Aug 2, 2017
3a1d515
Add Smartypants support for French Guillemets
bep Jul 31, 2017
cadec56
Merge pull request #384 from bep/v2
rtfb Aug 6, 2017
187c33f
README: Update URL of LaTeX renderer. (#389)
dmitshur Sep 5, 2017
119f356
Fix broken link to v2 in README
vassudanagunta Feb 7, 2018
ee09303
v2: Fix HTML5 by removing rel="footnote" which is invalid.
IainHaslam Feb 24, 2018
cfdcce5
Merge pull request #436 from IainHaslam/v2
rtfb Feb 25, 2018
c455fd4
Fix consecutive lists of different kinds (#443)
mitchchn Mar 20, 2018
6aeb241
Add a reference for confluence wiki renderer in the README.md. (#446)
kentaro-m Apr 26, 2018
3420fef
Add full info string in fenced code blocks (#449)
garfieldnate Apr 28, 2018
8c0d4cc
Fix for issue russross/blackfriday#239 (#372)
client9 May 24, 2018
1bb1d01
Fixed HTML entity regex (#453)
May 24, 2018
f048544
Add heading offset option to HTML renderer (#421)
emilmelnikov May 24, 2018
670777b
add NoopenerLinks (#437)
jinliming2 May 26, 2018
c5c549b
Fix html renderer escaping valid entities
ruqqq Jul 26, 2018
e97f103
Use the same .travis.yml on master and v2 (#462)
rtfb Aug 4, 2018
0e0e309
Fix travis builds on v2: gofmt harder (#470)
rtfb Aug 4, 2018
5a12bbc
Drop race detector from Travis builds (#474)
rtfb Aug 19, 2018
d85484c
Fix comment about inline footnotes (#473)
rtfb Aug 24, 2018
eebcfd6
Run tests against go 1.11 and drop 1.9 (#479)
michael-k Aug 29, 2018
2ab1ea3
Print diffs for reference tests (#481)
moorereason Sep 4, 2018
6762cd3
Only allow valid HTML entities to be unescaped. Do not escape HTML en…
ruqqq Sep 6, 2018
75a3bab
Add source URL for html entities.
ruqqq Sep 7, 2018
6463085
Run tests in parallel (#480)
moorereason Sep 7, 2018
d3b5b03
v2: Add go.mod (#487)
bep Sep 20, 2018
8bfdaf1
Run go mod tidy (#502)
SamWhited Nov 15, 2018
0a29761
block.go: set fenceLength (#505)
bobertlo Jan 20, 2019
55e5149
Update README.md (#508)
Munsio Jan 20, 2019
535ad76
Fix checking of backslash in link text (#510) (#511)
autopp Jan 20, 2019
919b1f5
Document SanitizedAnchorName algorithm, copy implementation. (#509)
dmitshur Jan 20, 2019
792d134
Remove dep on umaintained difflib (#515)
SamWhited Jan 21, 2019
b98aa06
Export Node.IsContainer
twpayne Apr 23, 2019
d969054
Add Node.IsLeaf
twpayne Apr 23, 2019
412ca19
Use ↩ as default params.FootnoteReturnLinkContents
adiabatic Jun 10, 2019
3e56bb6
Merge pull request #540 from twpayne/export-is-container
russross Jun 29, 2019
a178dd9
Update Markdown Documentation - Basics.text
bkmgit Oct 13, 2019
63f131c
Update Markdown Documentation - Basics.html
bkmgit Oct 13, 2019
5ba3beb
Update Markdown Documentation - Basics.html
bkmgit Oct 13, 2019
df341a4
Update Markdown Documentation - Basics.text
bkmgit Oct 13, 2019
a1ae674
Merge pull request #571 from bkmgit/v2
russross Feb 18, 2020
3b2b20c
Merge pull request #547 from adiabatic/v2
russross Feb 18, 2020
acedacf
Merge pull request #468 from ruqqq/v2
russross Jul 14, 2020
4c9bf95
v2/README: make a definitive decision on v2 import path
dmitshur Oct 27, 2020
f976c21
fix(quotes): fix unexpected multiple quotes joins
moisespsena Mar 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Travis CI (http://travis-ci.org/) is a continuous integration service for
# open source projects. This file configures it to run unit tests for
# blackfriday.

sudo: false
language: go

go:
- 1.2
- 1.3
- 1.4
- 1.5

- "1.10.x"
- "1.11.x"
- tip
matrix:
fast_finish: true
allow_failures:
- go: tip
install:
- go get -d -t -v ./...
- go build -v ./...

- # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step).
script:
- go test -v ./...
- go get -t -v ./...
- diff -u <(echo -n) <(gofmt -d -s .)
- go tool vet .
- go test -v ./...
180 changes: 125 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Blackfriday [![Build Status](https://travis-ci.org/russross/blackfriday.svg?branch=master)](https://travis-ci.org/russross/blackfriday)
Blackfriday
[![Build Status][BuildV2SVG]][BuildV2URL]
[![PkgGoDev][PkgGoDevV2SVG]][PkgGoDevV2URL]
===========

Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It
Expand All @@ -8,71 +10,106 @@ punctuation substitutions, etc.), and it is safe for all utf-8
(unicode) input.

HTML output is currently supported, along with Smartypants
extensions. An experimental LaTeX output engine is also included.
extensions.

It started as a translation from C of [Sundown][3].


Installation
------------

Blackfriday is compatible with Go 1. If you are using an older
release of Go, consider using v1.1 of blackfriday, which was based
on the last stable release of Go prior to Go 1. You can find it as a
tagged commit on github.
Blackfriday is compatible with modern Go releases in module mode.
With Go installed:

With Go 1 and git installed:
go get github.com/russross/blackfriday/v2

go get github.com/russross/blackfriday
will resolve and add the package to the current development module,
then build and install it. Alternatively, you can achieve the same
if you import it in a package:

will download, compile, and install the package into your `$GOPATH`
directory hierarchy. Alternatively, you can achieve the same if you
import it into a project:

import "github.com/russross/blackfriday"
import "github.com/russross/blackfriday/v2"

and `go get` without parameters.

Legacy GOPATH mode is unsupported.


Versions
--------

Currently maintained and recommended version of Blackfriday is `v2`. It's being
developed on its own branch: https://github.com/russross/blackfriday/tree/v2 and the
documentation is available at
https://pkg.go.dev/github.com/russross/blackfriday/v2.

It is `go get`-able in module mode at `github.com/russross/blackfriday/v2`.

Version 2 offers a number of improvements over v1:

* Cleaned up API
* A separate call to [`Parse`][4], which produces an abstract syntax tree for
the document
* Latest bug fixes
* Flexibility to easily add your own rendering extensions

Potential drawbacks:

* Our benchmarks show v2 to be slightly slower than v1. Currently in the
ballpark of around 15%.
* API breakage. If you can't afford modifying your code to adhere to the new API
and don't care too much about the new features, v2 is probably not for you.
* Several bug fixes are trailing behind and still need to be forward-ported to
v2. See issue [#348](https://github.com/russross/blackfriday/issues/348) for
tracking.

If you are still interested in the legacy `v1`, you can import it from
`github.com/russross/blackfriday`. Documentation for the legacy v1 can be found
here: https://pkg.go.dev/github.com/russross/blackfriday.


Usage
-----

For basic usage, it is as simple as getting your input into a byte
slice and calling:
For the most sensible markdown processing, it is as simple as getting your input
into a byte slice and calling:

output := blackfriday.MarkdownBasic(input)
```go
output := blackfriday.Run(input)
```

This renders it with no extensions enabled. To get a more useful
feature set, use this instead:
Your input will be parsed and the output rendered with a set of most popular
extensions enabled. If you want the most basic feature set, corresponding with
the bare Markdown specification, use:

output := blackfriday.MarkdownCommon(input)
```go
output := blackfriday.Run(input, blackfriday.WithNoExtensions())
```

### Sanitize untrusted content

Blackfriday itself does nothing to protect against malicious content. If you are
dealing with user-supplied markdown, we recommend running blackfriday's output
through HTML sanitizer such as
[Bluemonday](https://github.com/microcosm-cc/bluemonday).
dealing with user-supplied markdown, we recommend running Blackfriday's output
through HTML sanitizer such as [Bluemonday][5].

Here's an example of simple usage of blackfriday together with bluemonday:
Here's an example of simple usage of Blackfriday together with Bluemonday:

``` go
```go
import (
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday"
"github.com/russross/blackfriday/v2"
)

// ...
unsafe := blackfriday.MarkdownCommon(input)
unsafe := blackfriday.Run(input)
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
```

### Custom options

If you want to customize the set of options, first get a renderer
(currently either the HTML or LaTeX output engines), then use it to
call the more general `Markdown` function. For examples, see the
implementations of `MarkdownBasic` and `MarkdownCommon` in
`markdown.go`.
If you want to customize the set of options, use `blackfriday.WithExtensions`,
`blackfriday.WithRenderer` and `blackfriday.WithRefOverride`.

### `blackfriday-tool`

You can also check out `blackfriday-tool` for a more complete example
of how to use it. Download and install it using:
Expand All @@ -84,7 +121,7 @@ markdown file using a standalone program. You can also browse the
source directly on github if you are just looking for some example
code:

* <http://github.com/russross/blackfriday-tool>
* <https://github.com/russross/blackfriday-tool>

Note that if you have not already done so, installing
`blackfriday-tool` will be sufficient to download and install
Expand All @@ -93,6 +130,22 @@ installed in `$GOPATH/bin`. This is a statically-linked binary that
can be copied to wherever you need it without worrying about
dependencies and library versions.

### Sanitized anchor names

Blackfriday includes an algorithm for creating sanitized anchor names
corresponding to a given input text. This algorithm is used to create
anchors for headings when `AutoHeadingIDs` extension is enabled. The
algorithm has a specification, so that other packages can create
compatible anchor names and links to those anchors.

The specification is located at https://pkg.go.dev/github.com/russross/blackfriday/v2#hdr-Sanitized_Anchor_Names.

[`SanitizedAnchorName`](https://pkg.go.dev/github.com/russross/blackfriday/v2#SanitizedAnchorName) exposes this functionality, and can be used to
create compatible links to the anchor names generated by blackfriday.
This algorithm is also implemented in a small standalone package at
[`github.com/shurcooL/sanitized_anchor_name`](https://pkg.go.dev/github.com/shurcooL/sanitized_anchor_name). It can be useful for clients
that want a small package and don't need full functionality of blackfriday.


Features
--------
Expand All @@ -114,7 +167,7 @@ All features of Sundown are supported, including:
know and send me the input that does it.

NOTE: "safety" in this context means *runtime safety only*. In order to
protect yourself agains JavaScript injection in untrusted content, see
protect yourself against JavaScript injection in untrusted content, see
[this example](https://github.com/russross/blackfriday#sanitize-untrusted-content).

* **Fast processing**. It is fast enough to render on-demand in
Expand Down Expand Up @@ -160,7 +213,7 @@ implements the following extensions:
and supply a language (to make syntax highlighting simple). Just
mark it like this:

``` go
```go
func getTrue() bool {
return true
}
Expand All @@ -169,12 +222,21 @@ implements the following extensions:
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.

To preserve classes of fenced code blocks while using the bluemonday
HTML sanitizer, use the following policy:

```go
p := bluemonday.UGCPolicy()
p.AllowAttrs("class").Matching(regexp.MustCompile("^language-[a-zA-Z0-9]+$")).OnElements("code")
html := p.SanitizeBytes(unsafe)
```

* **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

Expand All @@ -185,7 +247,7 @@ implements the following extensions:
end of the document. A footnote looks like this:

This is a footnote.[^1]

[^1]: the footnote text.

* **Autolinking**. Blackfriday can find URLs that have not been
Expand All @@ -194,10 +256,8 @@ implements the following extensions:
* **Strikethrough**. Use two tildes (`~~`) to mark text that
should be crossed out.

* **Hard line breaks**. With this extension enabled (it is off by
default in the `MarkdownBasic` and `MarkdownCommon` convenience
functions), newlines in the input translate into line breaks in
the output.
* **Hard line breaks**. With this extension enabled newlines in the input
translate into line breaks 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
Expand All @@ -222,9 +282,9 @@ Other renderers
Blackfriday is structured to allow alternative rendering engines. Here
are a few of note:

* [github_flavored_markdown](https://godoc.org/github.com/shurcooL/github_flavored_markdown):
* [github_flavored_markdown](https://pkg.go.dev/github.com/shurcooL/github_flavored_markdown):
provides a GitHub Flavored Markdown renderer with fenced code block
highlighting, clickable header anchor links.
highlighting, clickable heading anchor links.

It's not customizable, and its goal is to produce HTML output
equivalent to the [GitHub Markdown API endpoint](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode),
Expand All @@ -233,25 +293,28 @@ are a few of note:
* [markdownfmt](https://github.com/shurcooL/markdownfmt): like gofmt,
but for markdown.

* LaTeX output: renders output as LaTeX. This is currently part of the
main Blackfriday repository, but may be split into its own project
in the future. If you are interested in owning and maintaining the
LaTeX output component, please be in touch.
* [LaTeX output](https://gitlab.com/ambrevar/blackfriday-latex):
renders output as LaTeX.

It renders some basic documents, but is only experimental at this
point. In particular, it does not do any inline escaping, so input
that happens to look like LaTeX code will be passed through without
modification.
* [bfchroma](https://github.com/Depado/bfchroma/): provides convenience
integration with the [Chroma](https://github.com/alecthomas/chroma) code
highlighting library. bfchroma is only compatible with v2 of Blackfriday and
provides a drop-in renderer ready to use with Blackfriday, as well as
options and means for further customization.

* [Blackfriday-Confluence](https://github.com/kentaro-m/blackfriday-confluence): provides a [Confluence Wiki Markup](https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html) renderer.

Todo
* [Blackfriday-Slack](https://github.com/karriereat/blackfriday-slack): converts markdown to slack message style


TODO
----

* More unit testing
* Improve unicode support. It does not understand all unicode
* Improve Unicode support. It does not understand all Unicode
rules (about what constitutes a letter, a punctuation symbol,
etc.), so it may fail to detect word boundaries correctly in
some instances. It is safe on all utf-8 input.
some instances. It is safe on all UTF-8 input.


License
Expand All @@ -260,6 +323,13 @@ License
[Blackfriday is distributed under the Simplified BSD License](LICENSE.txt)


[1]: http://daringfireball.net/projects/markdown/ "Markdown"
[2]: http://golang.org/ "Go Language"
[1]: https://daringfireball.net/projects/markdown/ "Markdown"
[2]: https://golang.org/ "Go Language"
[3]: https://github.com/vmg/sundown "Sundown"
[4]: https://pkg.go.dev/github.com/russross/blackfriday/v2#Parse "Parse func"
[5]: https://github.com/microcosm-cc/bluemonday "Bluemonday"

[BuildV2SVG]: https://travis-ci.org/russross/blackfriday.svg?branch=v2
[BuildV2URL]: https://travis-ci.org/russross/blackfriday
[PkgGoDevV2SVG]: https://pkg.go.dev/badge/github.com/russross/blackfriday/v2
[PkgGoDevV2URL]: https://pkg.go.dev/github.com/russross/blackfriday/v2
Loading