88

I want to create a long "-", normally used between adjacent (sub)sentences, in Markdown.

Here I've copied the particular character from another site: –.

How can I create such "–" in Markdown?

Shuzheng
  • 11,288
  • 20
  • 88
  • 186
  • 1
    I don't know. But Google might....https://daringfireball.net/projects/markdown/ – Matt Runion Sep 17 '18 at 16:05
  • 2
    @mrunion: I'm not sure Google would turn up that page for how to make an em or en dash in Markdown when it doesn't have a single mention of either punctuation mark. At *best* it says you can use HTML entities, but then that just means "Markdown doesn't have any special syntax for this", *and* that's assuming the asker even knows you can encode one using a character reference. – BoltClock Sep 17 '18 at 16:30
  • 2
    It looks like you're actually using the wrong dash there. That's an _en_ dash, used for ranges (e.g. "1–2 pinches of salt"), not an _em_ dash—used very much like parentheses. – ChrisGPT was on strike Sep 17 '18 at 22:43

6 Answers6

76

You have three options:

  1. Insert the Unicode character

  2. Use the HTML entity for the character.

  3. 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.

Waylan
  • 37,164
  • 12
  • 83
  • 109
  • For example, the "tag" of — is the #151. Quoting one of the links given in the answer above, [Character entity references in HTML](https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML): "To use one of these character entity references in an HTML or XML document, enter an ampersand followed by the entity name and a semicolon, e.g., enter © for the copyright symbol (©)." – questionto42 Jun 01 '21 at 13:30
22

Characters are characters—neither markup nor markdown.

Em dash —, in Windows, with the number keypad: Alt(hold)+0151

Tom Blodget
  • 20,260
  • 3
  • 39
  • 72
  • If you prefer, you can configure your keyboard in Windows to accept Unicode codepoint numbers, instead of "traditional". Of course, some may prefer the HTML markup method, where they can use it. (If you do, up vote that answer.) – Tom Blodget Sep 26 '19 at 15:51
  • While @TomBlodget is technically correct, the entire point of markdown is to create fully-styled output, but also to enhance legibility in a fixed-width format. The various dash types look nearly identical in most fixed width fonts. It seems like turning two hyphens into an en dash and three into an em would be an upgrade. One could also argue that both en and em dashes also carry semantic meaning (range and conjunction) and, therefore, would be acceptable (and perhaps even preferable) markdown under the most orthodox definition. – brnt Jan 02 '23 at 01:23
12

You could try the HTML entity if it allows you — or —.

https://daringfireball.net/projects/markdown/syntax

Oliver
  • 154
  • 5
7

As I known, Option(alt) + - is for Mac.

inferno
  • 684
  • 6
  • 21
  • 2
    And, option+`_` (underscore, so press shift) for an em dash (`—`), though this seems to not work on certain keyboard layouts. – golvok Oct 31 '19 at 18:45
2

You may also be able to input this as a Unicode character using your keyboard. Most Markdown processors that I've used handle this just fine.

For example, I have a compose key configured. With my fairly standard configuration, Compose--- gives an em dash and Compose--. give an en dash.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
2

I'm using Python-Markdown with extension markdown-emdash 0.1.0.

.  .  .
from mdx_emdash import EmDashExtension
.  .  .
MARKDOWN_CONVERTER = markdown.Markdown(extensions=["extra",
        "toc", "markdown_del_ins", EmDashExtension()])
.  .  .
with open(input_file, 'r') as md_file:
    md_lines = md_file.read()
html_lines = MARKDOWN_CONVERTER.convert(source=md_lines)
out.write(html_lines)

It replaces three dashes (---) with an em-dash (—).

Nick Legend
  • 789
  • 1
  • 7
  • 21