How to make a long "-" in Markdown, i.e. the character "–"?

Markdown

Markdown Problem Overview


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?

Markdown Solutions


Solution 1 - Markdown

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.

Solution 2 - Markdown

Characters are characters—neither markup nor markdown.

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

Solution 3 - Markdown

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

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

Solution 4 - Markdown

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

Solution 5 - Markdown

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.

Solution 6 - Markdown

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 (—).

Categories

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShuzhengView Question on Stackoverflow
Solution 1 - MarkdownWaylanView Answer on Stackoverflow
Solution 2 - MarkdownTom BlodgetView Answer on Stackoverflow
Solution 3 - MarkdownoliverView Answer on Stackoverflow
Solution 4 - MarkdowninfernoView Answer on Stackoverflow
Solution 5 - MarkdownChrisView Answer on Stackoverflow
Solution 6 - MarkdownNick LegendView Answer on Stackoverflow