Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade github.com/russross/blackfriday #8503

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ require (
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/procfs v0.0.4 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001 // indirect
github.com/russross/blackfriday v0.0.0-20180428102519-11635eb403ff
github.com/russross/blackfriday v1.5.2 // indirect
github.com/russross/blackfriday/v2 v2.0.1
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
github.com/satori/go.uuid v1.2.0
github.com/sergi/go-diff v1.0.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,10 @@ github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001/go.mod h1:qq
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v0.0.0-20180428102519-11635eb403ff h1:g9ZlAHmkc/h5So+OjNCkZWh+FjuKEOOOoyRkqlGA8+c=
github.com/russross/blackfriday v0.0.0-20180428102519-11635eb403ff/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI=
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
Expand Down
41 changes: 20 additions & 21 deletions modules/markup/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

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

// Renderer is a extended version of underlying render object.
Expand Down Expand Up @@ -58,9 +58,9 @@ func (r *Renderer) List(out *bytes.Buffer, text func() bool, flags int) {
out.WriteByte('\n')
}

if flags&blackfriday.LIST_TYPE_DEFINITION != 0 {
if flags&blackfriday.ListTypeDefinition != 0 {
out.WriteString("<dl>")
} else if flags&blackfriday.LIST_TYPE_ORDERED != 0 {
} else if flags&blackfriday.ListTypeOrdered != 0 {
out.WriteString("<ol class='ui list'>")
} else {
out.WriteString("<ul class='ui list'>")
Expand All @@ -69,9 +69,9 @@ func (r *Renderer) List(out *bytes.Buffer, text func() bool, flags int) {
out.Truncate(marker)
return
}
if flags&blackfriday.LIST_TYPE_DEFINITION != 0 {
if flags&blackfriday.ListTypeDefinition != 0 {
out.WriteString("</dl>\n")
} else if flags&blackfriday.LIST_TYPE_ORDERED != 0 {
} else if flags&blackfriday.ListTypeOrdered != 0 {
out.WriteString("</ol>\n")
} else {
out.WriteString("</ul>\n")
Expand Down Expand Up @@ -124,36 +124,35 @@ func (r *Renderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byt

const (
blackfridayExtensions = 0 |
blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
blackfriday.EXTENSION_TABLES |
blackfriday.EXTENSION_FENCED_CODE |
blackfriday.EXTENSION_STRIKETHROUGH |
blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK |
blackfriday.EXTENSION_DEFINITION_LISTS |
blackfriday.EXTENSION_FOOTNOTES |
blackfriday.EXTENSION_HEADER_IDS |
blackfriday.EXTENSION_AUTO_HEADER_IDS
blackfriday.NoIntraEmphasis |
blackfriday.Tables |
blackfriday.FencedCode |
blackfriday.Strikethrough |
blackfriday.NoEmptyLineBeforeBlock |
blackfriday.DefinitionLists |
blackfriday.Footnotes |
blackfriday.HeadingIDs |
blackfriday.AutoHeadingIDs
blackfridayHTMLFlags = 0 |
blackfriday.HTML_SKIP_STYLE |
blackfriday.HTML_OMIT_CONTENTS |
blackfriday.HTML_USE_SMARTYPANTS
blackfriday.SkipHTML |
blackfriday.Smartypants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OmitContents?

Copy link
Contributor Author

@carnott-snap carnott-snap Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears blackfriday.HTML_OMIT_CONTENTS was sunset without a direct replacement, see upstream, it may be that some other flag or option within the blackfriday.HTMLRenderer struct may replace this.

)

// RenderRaw renders Markdown to HTML without handling special links.
func RenderRaw(body []byte, urlPrefix string, wikiMarkdown bool) []byte {
renderer := &Renderer{
Renderer: blackfriday.HtmlRenderer(blackfridayHTMLFlags, "", ""),
Renderer: blackfriday.HTMLRenderer(blackfridayHTMLFlags, "", ""),
URLPrefix: urlPrefix,
IsWiki: wikiMarkdown,
}

exts := blackfridayExtensions
if setting.Markdown.EnableHardLineBreak {
exts |= blackfriday.EXTENSION_HARD_LINE_BREAK
exts |= blackfriday.HardLineBreak
}

body = blackfriday.Markdown(body, renderer, exts)
return markup.SanitizeBytes(body)
s := blackfriday.New(blackfriday.WithExtensions(exts), blackfriday.WithRenderer(renderer)).Parse(body).String()
return []byte(markup.Sanitize(s))
}

var (
Expand Down
30 changes: 15 additions & 15 deletions modules/markup/mdstripper/mdstripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package mdstripper
import (
"bytes"

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

// MarkdownStripper extends blackfriday.Renderer
Expand All @@ -19,18 +19,18 @@ type MarkdownStripper struct {

const (
blackfridayExtensions = 0 |
blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
blackfriday.EXTENSION_TABLES |
blackfriday.EXTENSION_FENCED_CODE |
blackfriday.EXTENSION_STRIKETHROUGH |
blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK |
blackfriday.EXTENSION_DEFINITION_LISTS |
blackfriday.EXTENSION_FOOTNOTES |
blackfriday.EXTENSION_HEADER_IDS |
blackfriday.EXTENSION_AUTO_HEADER_IDS |
blackfriday.NoIntraEmphasis |
blackfriday.Tables |
blackfriday.FencedCode |
blackfriday.Strikethrough |
blackfriday.NoEmptyLineBeforeBlock |
blackfriday.DefinitionLists |
blackfriday.Footnotes |
blackfriday.HeadingIDs |
blackfriday.AutoHeadingIDs |
// Not included in modules/markup/markdown/markdown.go;
// required here to process inline links
blackfriday.EXTENSION_AUTOLINK
blackfriday.Autolink
)

//revive:disable:var-naming Implementing the Rendering interface requires breaking some linting rules
Expand All @@ -41,8 +41,8 @@ func StripMarkdown(rawBytes []byte) (string, []string) {
stripper := &MarkdownStripper{
links: make([]string, 0, 10),
}
body := blackfriday.Markdown(rawBytes, stripper, blackfridayExtensions)
return string(body), stripper.GetLinks()
body := blackfriday.New(blackfriday.WithExtensions(blackfridayExtensions), blackfriday.WithRenderer(stripper)).Parse(rawBytes)
return body.String(), stripper.GetLinks()
}

// StripMarkdownBytes parses markdown content by removing all markup and code blocks
Expand All @@ -51,8 +51,8 @@ func StripMarkdownBytes(rawBytes []byte) ([]byte, []string) {
stripper := &MarkdownStripper{
links: make([]string, 0, 10),
}
body := blackfriday.Markdown(rawBytes, stripper, blackfridayExtensions)
return body, stripper.GetLinks()
body := blackfriday.New(blackfriday.WithExtensions(blackfridayExtensions), blackfriday.WithRenderer(stripper)).Parse(rawBytes)
return []byte(body.String()), stripper.GetLinks()
}

// block-level callbacks
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/orgmode/orgmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/modules/markup/markdown"

"github.com/chaseadamsio/goorgeous"
"github.com/russross/blackfriday"
blackfriday "github.com/russross/blackfriday/v2"
)

func init() {
Expand Down
40 changes: 14 additions & 26 deletions vendor/github.com/russross/blackfriday/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading