Skip to content

Instantly share code, notes, and snippets.

@italicize
Last active September 19, 2018 20:34
Show Gist options
  • Save italicize/92f0172c1dd097e94a6b4ed79c5c5e49 to your computer and use it in GitHub Desktop.
Save italicize/92f0172c1dd097e94a6b4ed79c5c5e49 to your computer and use it in GitHub Desktop.
Emphasis in GitHub Flavored Markdown

Emphasis in GitHub Flavored Markdown

Emphasis begins and ends according to 17 rules in the specification, but here is a summary in three rules:

  1. Use either asterisks or underscores to emphasize a character next to a space, punctuation, or the beginning or end of a line. Put an emphasis mark immediately next to a character, with no space between, as in _this!_ for this!

    • Exception. Special punctuation marks override this rule, including a backslash (\), backtick (`), and square brackets ([ ]) which cause an asterisk or underscore to be rendered as a character and ignored as an emphasis mark.
  2. Use an asterisk to emphasize letters and numbers next to letters and numbers, as in *as*terisk for asterisk. By contrast, an underscore is not an emphasis mark between letters and numbers, as in not_italic.

  3. To emphasize punctuation next to letters and numbers, use HTML tags, as in this<em>!</em> for this! By contrast, an asterisk and underscore cannot emphasize punctuation next to an unemphasized letter or number.

Test cases

Emphasized Next to Underscores Asterisks Raw underscores and asterisks
Letters Spaces r italic r r italic r r _italic_ r *italic* r
" Letters L_regular_L LitalicL L_regular_L L*italic*L
" Numbers 1_regular_1 1italic1 1_regular_1 1*italic*1
" Punctuation !italic! !italic! !_italic_! !*italic*!
Numbers Spaces r 11italic11 r r 11italic11 r r _11italic11_ r *11italic11* r
" Letters L_11regular11_L L11italic11L L_11regular11_L L*11italic11*L
" Numbers 1_11regular11_1 111italic111 1_11regular11_1 1*11italic11*1
" Punctuation !11italic11! !11italic11! !_11italic11_! !*11italic11*!
Punctuation Spaces r !!italic!! r r !!italic!! r r _!!italic!!_ r *!!italic!!* r
" Letters L_!!regular!!_L L*!!regular!!*L L_!!regular!!_L L*!!regular!!*L
" Numbers 1_!!regular!!_1 1*!!regular!!*1 1_!!regular!!_1 1*!!regular!!*1
" Punctuation !!!italic!!! !!!italic!!! !_!!italic!!_! !*!!italic!!*!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment