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

Ignore underscore conditionally with the IgnoreUnderscore extension #685

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from
Open
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: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ implements the following extensions:
becomes `<sup>4</sup>&frasl;<sub>5</sub>`, which renders as
<sup>4</sup>&frasl;<sub>5</sub>.

* **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
---------------
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module github.com/russross/blackfriday/v2
module github.com/dmitrytorba/blackfriday/v2
30 changes: 30 additions & 0 deletions inline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"<p>simple _inline_ test</p>\n",

"_at the_ beginning\n",
"<p>_at the_ beginning</p>\n",

"at the _end_\n",
"<p>at the _end_</p>\n",

"_try two_ in _one line_\n",
"<p>_try two_ in _one line_</p>\n",

"over _two\nlines_ test\n",
"<p>over _two\nlines_ test</p>\n",

"odd _number of_ markers_ here\n",
"<p>odd _number of_ markers_ here</p>\n",

"odd _number\nof_ markers_ here\n",
"<p>odd _number\nof_ markers_ here</p>\n",

"mix of *markers_\n",
"<p>mix of *markers_</p>\n",
}
doTestsInlineParam(t, tests, TestParams{extensions: IgnoreUnderscore})
}
5 changes: 4 additions & 1 deletion markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down