Skip to content

Instantly share code, notes, and snippets.

@juev
Created March 20, 2025 09:07
Show Gist options
  • Select an option

  • Save juev/0e79d7e467840dc04db5fa0cc4b1e0f7 to your computer and use it in GitHub Desktop.

Select an option

Save juev/0e79d7e467840dc04db5fa0cc4b1e0f7 to your computer and use it in GitHub Desktop.

Dash in Markdown

Источник

You have three options:

  • Insert the Unicode character
  • Use the HTML entity for the character.
  • Use a tool like Smartypants to convert plain text to HTML entities.

Use Unicode Characters

You can copy the character from elsewhere and past it directly into your document. Of course this is tedious and not very convenient. However, as highlighted in other answers, you could learn the keyboard shortcuts for the system you use to insert the desired characters.

Use HTML Entities

Using HTML Entities is the officially supported method by Markdown. As the rules state:

For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags.

Therefore, simply insert the HTML entity directly into your document. You can find the various codes listed on many sites across the internet (such as here or here). A few related to dashes are:

En-Dash         –    –
Em-Dash         —    —
Minus Symbol    −    −

Use Smartypants

Of course, you may not want to memorize or look up the HTML entity codes every time you need to use them. It is easier to just use the basic characters on the keyboard. For this reason the creator of Markdown also created Smartpants, which is a Markdown postprocessor. It accepts the output of Markdown and converts plain character shortcuts to the appropriate HTML Entities for you.

As the documentation explains:

SmartyPants can perform the following transformations:

  • Straight quotes ( " and ' ) into "curly" quote HTML entities
  • Backticks-style quotes (``like this'') into "curly" quote HTML entities
  • Dashes ("--" and "--") into en- and em-dash entities
  • Three consecutive dots ("…") into an ellipsis entity
    This means you can write, edit, and save your posts using plain old ASCII straight quotes, plain dashes, and plain dots, but your published posts (and final HTML output) will appear with smart quotes, em-dashes, and proper ellipses.

Of course, to make use of Smartpants, you need to either be using one of the programs which supports a Smartypants plugin or run your Markdown output through the command line program. Therefore it doesn't work everywhere. But it works great when you're in an environment where it is supported. *[HTML]: HyperText Markup Language *[ASCII]: American Standard Code for Information Interchange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment