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

Add support for _italics_ using underscores to the Markdown parser #25564

Merged
merged 1 commit into from
Jan 16, 2018
Merged
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ Language changes
* `=>` now has its own precedence level, giving it strictly higher precedence than
`=` and `,` ([#25391]).

* Underscores for `_italics_` and `__bold__` are now supported by the Base Markdown
parser. ([#25564])

Breaking changes
----------------

Expand Down
2 changes: 1 addition & 1 deletion base/markdown/Common/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ include("inline.jl")
paragraph,

linebreak, escapes, inline_code,
asterisk_bold, asterisk_italic, image, footnote_link, link, autolink]
asterisk_bold, underscore_bold, asterisk_italic, underscore_italic, image, footnote_link, link, autolink]

12 changes: 12 additions & 0 deletions base/markdown/Common/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ function asterisk_italic(stream::IO, md::MD)
return result === nothing ? nothing : Italic(parseinline(result, md))
end

@trigger '_' ->
function underscore_italic(stream::IO, md::MD)
result = parse_inline_wrapper(stream, "_")
return result === nothing ? nothing : Italic(parseinline(result, md))
end

mutable struct Bold
text
end
Expand All @@ -24,6 +30,12 @@ function asterisk_bold(stream::IO, md::MD)
return result === nothing ? nothing : Bold(parseinline(result, md))
end

@trigger '_' ->
function underscore_bold(stream::IO, md::MD)
result = parse_inline_wrapper(stream, "__")
return result === nothing ? nothing : Bold(parseinline(result, md))
end

# ––––
# Code
# ––––
Expand Down
2 changes: 1 addition & 1 deletion base/markdown/GitHub/GitHub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ end
github_table, github_paragraph,

linebreak, escapes, en_dash, inline_code, asterisk_bold,
asterisk_italic, image, footnote_link, link, autolink]
underscore_bold, asterisk_italic, underscore_italic, image, footnote_link, link, autolink]

2 changes: 1 addition & 1 deletion base/markdown/Julia/Julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ include("interp.jl")
blockquote, admonition, footnote, github_table, horizontalrule, setextheader, paragraph,

linebreak, escapes, tex, interp, en_dash, inline_code,
asterisk_bold, asterisk_italic, image, footnote_link, link, autolink]
asterisk_bold, underscore_bold, asterisk_italic, underscore_italic, image, footnote_link, link, autolink]

3 changes: 3 additions & 0 deletions test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Base: show

@test md"foo" == MD(Paragraph("foo"))
@test md"foo *bar* baz" == MD(Paragraph(["foo ", Italic("bar"), " baz"]))
@test md"foo _bar_ baz" == MD(Paragraph(["foo ", Italic("bar"), " baz"]))
@test md"foo **bar** baz" == MD(Paragraph(["foo ", Bold("bar"), " baz"]))
@test md"foo __bar__ baz" == MD(Paragraph(["foo ", Bold("bar"), " baz"]))
@test md"""foo
bar""" == MD(Paragraph(["foo bar"]))
@test md"""foo\
Expand Down