Strikethrough draws a line through text, to mark it as deleted or no longer accurate. To strike text through, wrap it in one or two tildes (~).

Strikethrough originates in GitHub Flavored Markdown. This document describes Comrak’s strikethrough, which can differ from GitHub’s. GitLab uses Comrak’s strikethrough, so this document is also the canonical spec for GitLab Flavored Markdown strikethrough.

To enable strikethrough, pass -e strikethrough (or --gfm) on the command line, or set extension.strikethrough in the options struct.

Here’s a typical strikethrough:

Example 1
$ comrak -e strikethrough
Meet on ~~Tuesday~~ Wednesday.

Syntax

Strikethrough works like CommonMark’s emphasis, with tildes in place of asterisks.

A tilde run is a sequence of one or two tildes that isn’t preceded or followed by another tilde. A tilde run can open strikethrough if it’s a left-flanking delimiter run, and can close strikethrough if it’s a right-flanking delimiter run.

Strikethrough begins with a tilde run that can open it, and ends with a later tilde run of the same length that can close it. Comrak pairs tilde runs with CommonMark’s process emphasis procedure, the same procedure that pairs emphasis delimiters.

Tilde runs

A tilde run may have one tilde or two:

Example 2
$ comrak -e strikethrough
~one~ and ~~two~~

Three or more tildes are literal text:

Example 3
$ comrak -e strikethrough
a ~~~b~~~ c

The tilde runs at each end must be the same length. Otherwise, neither run forms strikethrough:

Example 4
$ comrak -e strikethrough
~a~~ b

~~a~ b

An unequal pair doesn’t prevent other tilde runs from pairing. Here, the inner ~ and ~~ don’t pair, so the outer runs do:

Example 5
$ comrak -e strikethrough
~~a ~b~~ c~~

Flanking

A tilde run followed by whitespace can’t open strikethrough, and one preceded by whitespace can’t close it:

Example 6
$ comrak -e strikethrough
~~ a~~

~~a ~~

Unlike _ emphasis, strikethrough may begin and end inside a word:

Example 7
$ comrak -e strikethrough
a~~b~~c

Punctuation affects flanking as it does for emphasis. Strikethrough may have punctuation just inside its tilde runs. But a tilde run after a letter and before punctuation can’t open strikethrough, and one after punctuation and before a letter can’t close it:

Example 8
$ comrak -e strikethrough
~~(a)~~

a~~(b)~~c

Nesting

Strikethrough may contain strikethrough, with either length of tilde run:

Example 9
$ comrak -e strikethrough
~~a ~b~ c~~

Strikethrough and emphasis may contain each other:

Example 10
$ comrak -e strikethrough
~~*a*~~ and *~~b~~*

When strikethrough and emphasis overlap, the first to close wins, and the other’s delimiters are literal:

Example 11
$ comrak -e strikethrough
~~a *b~~ c*

*a ~~b* c~~

Precedence

Block structure comes first. Three tildes at the start of a line begin a fenced code block:

Example 12
$ comrak -e strikethrough
~~~a~~~

Code spans and links take precedence over strikethrough, so tilde runs pair only within or around them:

Example 13
$ comrak -e strikethrough
~~a `b~~` c~~
Example 14
$ comrak -e strikethrough
~~[a~~]/u

[~~a~~]/u

Strikethrough may span lines, but not paragraphs:

Example 15
$ comrak -e strikethrough
~~a
b~~
Example 16
$ comrak -e strikethrough
This ~~has a

new paragraph~~.

A backslash escape or an entity reference is literal text, not a tilde run:

Example 17
$ comrak -e strikethrough
\~~a~~

~~a~~

Output

HTML output renders strikethrough as a <del> element.

CommonMark output writes strikethrough with two tildes on each side, whatever its length in the source. It escapes other tildes (\~), to prevent reading them back as tilde runs:

Example 18
$ comrak -e strikethrough
~a~ and x~~~y

In XML output, strikethrough is a strikethrough element.

In the AST, strikethrough is a NodeValue::Strikethrough, with its content as children.

Strikethrough’s source position covers its tilde runs:

Example 19
$ comrak -e strikethrough --sourcepos
x ~~a~~ ~b~

Interactions

--gfm enables strikethrough, along with the other GitHub Flavored Markdown extensions:

Example 20
$ comrak --gfm
~~a~~

With subscript, a tilde run of one tilde forms subscript instead, and a tilde run of two tildes forms strikethrough:

Example 21
$ comrak -e strikethrough -e subscript
H~2~O is ~~not~~ water.
Example 22
$ comrak -e strikethrough -e subscript
~~H~2~O~~

With CJK-friendly emphasis, the flanking rules change for tilde runs next to CJK characters, as they do for emphasis. Without it, these aren’t strikethrough:

Example 23
$ comrak -e strikethrough
a~~a()~~あ

「~~a」~~a

With it, they are:

Example 24
$ comrak -e strikethrough -e cjk-friendly-emphasis
a~~a()~~あ

「~~a」~~a

With autolinks, the tildes around an autolink aren’t part of it:

Example 25
$ comrak -e strikethrough -e autolink
~~www.example.com~~

With description lists, a line beginning with a tilde and a space marks details, not a tilde run:

Example 26
$ comrak -e strikethrough -e description-lists
Term

~ ~~details~~

Differences from cmark-gfm

cmark-gfm, the reference implementation of GitHub Flavored Markdown, uses the same strikethrough design as Comrak. It doesn’t support the subscript, CJK-friendly emphasis, or description lists extensions, so those examples aren’t comparable. On every other example above, the two implementations agree on HTML output, except that cmark-gfm gives strikethrough no source position (example 19).

cmark-gfm also has a --strikethrough-double-tilde option, with which a tilde run of one tilde is literal. Comrak has no equivalent.

Regressions

The following examples guard against regressions.

Tilde runs of four are literal, even between a pair that forms strikethrough (#635):

Example 27
$ comrak -e strikethrough
This is ~strikethrough~.

As is ~~this, okay~~?

This ~text~~~~ is ~~~~curious~.

An unequal pair doesn’t stop later delimiters from pairing:

Example 28
$ comrak -e strikethrough
~~a~ *b*

~a~~ and *b* and ~c~