diff --git a/README.md b/README.md index d9c08a22..d8714a9d 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,9 @@ implements the following extensions: becomes `4⁄5`, which renders as 4⁄5. +* **Ignore Underscore** is similar to intra-word emphasis supression. However, + it goes to the next level and ignores underscores completely. + Underscores will not be processed, wherever they may occur. Other renderers --------------- diff --git a/go.mod b/go.mod index 620b74e0..d2d1312b 100644 --- a/go.mod +++ b/go.mod @@ -1 +1 @@ -module github.com/russross/blackfriday/v2 +module github.com/dmitrytorba/blackfriday/v2 diff --git a/inline_test.go b/inline_test.go index 5a91d8aa..4904c2ff 100644 --- a/inline_test.go +++ b/inline_test.go @@ -1214,3 +1214,33 @@ func BenchmarkSmartDoubleQuotes(b *testing.B) { runMarkdown("this should be normal \"quoted\" text.\n", params) } } + +func TestIgnoreUnderscore(t *testing.T) { + t.Parallel() + var tests = []string{ + "simple _inline_ test\n", + "
simple _inline_ test
\n", + + "_at the_ beginning\n", + "_at the_ beginning
\n", + + "at the _end_\n", + "at the _end_
\n", + + "_try two_ in _one line_\n", + "_try two_ in _one line_
\n", + + "over _two\nlines_ test\n", + "over _two\nlines_ test
\n", + + "odd _number of_ markers_ here\n", + "odd _number of_ markers_ here
\n", + + "odd _number\nof_ markers_ here\n", + "odd _number\nof_ markers_ here
\n", + + "mix of *markers_\n", + "mix of *markers_
\n", + } + doTestsInlineParam(t, tests, TestParams{extensions: IgnoreUnderscore}) +} diff --git a/markdown.go b/markdown.go index 58d2e453..f502e1d6 100644 --- a/markdown.go +++ b/markdown.go @@ -47,6 +47,7 @@ const ( AutoHeadingIDs // Create the heading ID from the text BackslashLineBreak // Translate trailing backslashes into line breaks DefinitionLists // Render definition lists + IgnoreUnderscore // Ignore all underscores CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants | SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes @@ -285,7 +286,9 @@ func New(opts ...Option) *Markdown { // register inline parsers p.inlineCallback[' '] = maybeLineBreak p.inlineCallback['*'] = emphasis - p.inlineCallback['_'] = emphasis + if p.extensions&IgnoreUnderscore == 0 { + p.inlineCallback['_'] = emphasis + } if p.extensions&Strikethrough != 0 { p.inlineCallback['~'] = emphasis }