+0
Daily
5,598
stars
599
forks
85
watchers
271
prs
379
issues
7
releases
README
Blackfriday
[![Build Status][BuildV2SVG]][BuildV2URL]
[![PkgGoDev][PkgGoDevV2SVG]][PkgGoDevV2URL]
===========
Blackfriday is a [Markdown][1] processor implemented in [Go][2]. It
is paranoid about its input (so you can safely feed it user-supplied
data), it is fast, it supports common extensions (tables, smart
punctuation substitutions, etc.), and it is safe for all utf-8
(unicode) input.
HTML output is currently supported, along with Smartypants
extensions.
It started as a translation from C of [Sundown][3].
Installation
------------
Blackfriday is compatible with modern Go releases in module mode.
With Go installed:
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:
import "github.com/russross/blackfriday"
and go get without parameters.
Old versions of Go and legacy GOPATH mode might work,
but no effort is made to keep them working.
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 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
-----
v1
For basic usage, it is as simple as getting your input into a byte
slice and calling:
go
output := blackfriday.MarkdownBasic(input)
This renders it with no extensions enabled. To get a more useful
feature set, use this instead:
go
output := blackfriday.MarkdownCommon(input)
v2
For the most sensible markdown processing, it is as simple as getting your input
into a byte slice and calling:
go
output := blackfriday.Run(input)
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:
go
output := blackfriday.Run(input, blackfriday.WithNoExtensions())
Sanitize untrusted content
Blackfriday itself does nothing to protect against maliTop issues
#329Deep nested lists don't output correctly21 comments · 2017-02-06#500Code no longer builds due to broken URL github.com/russross/blackfriday/v217 comments · 2018-10-29#181Customising the output HTML / adding classes to tags17 comments · 2015-07-05#114Add tests from Standard Markdown (renamed to CommonMark now)17 comments · 2014-09-03#244List block cannot have a second line13 comments · 2016-03-07#404Wrap Markdown text in HTML tags12 comments · 2017-10-31#396Documentation on flexible extensions ?12 comments · 2017-10-05#394Tables not rendering after upgrade to 2.0.012 comments · 2017-09-23
Latest release
v2.1.0 v2.1.0 2020-11-07A minor release, mainly aimed at resolving ambiguity about the import path for blackfriday v2 and delivering minor fixes since last release: - Committed to github.com/russross/blackfriday/v2 as the canonical import path for blackfriday v2. (Issue 587) - Reduced the amount of dependencies. (PRs 509 and 515) - Added a SanitizedAnchorName function. (PR 509) - Added Node.IsContainer and Node.IsLeaf methods. (PR 540) - Fixed parsing of links that end with a double backslashes. (Issue 510) - Fixed an issue where fence length wasn't computed. (PR 505) - Improved the default value for the HTM