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:
$ comrak -e strikethrough -t commonmark -t xml
Meet on Tuesday Wednesday.
Meet on Tuesday Wednesday.
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:
$ comrak -e strikethrough -t commonmark -t xml
one and two
one and two
one
and
two
Three or more tildes are literal text:
$ comrak -e strikethrough -t commonmark -t xml
a ~~~b~~~ c
a ~~~b~~~ c
a ~~~b~~~ c
The tilde runs at each end must be the same length. Otherwise, neither run forms strikethrough:
$ comrak -e strikethrough -t commonmark -t xml
~a~~ b
~~a~ b
~a~~ b
~~a~ b
~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:
$ comrak -e strikethrough -t commonmark -t xml
a ~b~~ c
a ~b~~ c
a ~b~~ c
Flanking
A tilde run followed by whitespace can’t open strikethrough, and one preceded by whitespace can’t close it:
$ comrak -e strikethrough -t commonmark -t xml
~~ a~~
~~a ~~
~~ a~~
~~a ~~
~~ a~~
~~a ~~
Unlike _ emphasis, strikethrough may begin and end inside a word:
$ comrak -e strikethrough -t commonmark -t xml
abc
abc
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:
$ comrak -e strikethrough -t commonmark -t xml
(a)
a~~(b)~~c
(a)
a~~(b)~~c
(a)
a~~(b)~~c
Nesting
Strikethrough may contain strikethrough, with either length of tilde run:
$ comrak -e strikethrough -t commonmark -t xml
a b c
a b c
a
b
c
Strikethrough and emphasis may contain each other:
$ comrak -e strikethrough -t commonmark -t xml
a and b
a and b
a
and
b
When strikethrough and emphasis overlap, the first to close wins, and the other’s delimiters are literal:
$ comrak -e strikethrough -t commonmark -t xml
a *b c*
a ~~b c~~
a *b c*
a ~~b c~~
a *b
c*
a ~~b
c~~
Precedence
Block structure comes first. Three tildes at the start of a line begin a fenced code block:
$ comrak -e strikethrough -t commonmark -t xml
Code spans and links take precedence over strikethrough, so tilde runs pair only within or around them:
$ comrak -e strikethrough -t commonmark -t xml
a b~~ c
a b~~ c
a
b~~
c
$ comrak -e strikethrough -t commonmark -t xml
Strikethrough may span lines, but not paragraphs:
$ comrak -e strikethrough -t commonmark -t xml
a
b
a
b
a
b
$ comrak -e strikethrough -t commonmark -t xml
This ~~has a
new paragraph~~.
This ~~has a
new paragraph~~.
This ~~has a
new paragraph~~.
A backslash escape or an entity reference is literal text, not a tilde run:
$ comrak -e strikethrough -t commonmark -t xml
~~a~~
~~a~~
~~a~~
~~a~~
~~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:
$ comrak -e strikethrough -t commonmark -t xml
a and x~~~y
a and x~~~y
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:
$ comrak -e strikethrough --sourcepos -t commonmark -t xml
x a b
x a b
x
a
b
Interactions
--gfm enables strikethrough, along with the other GitHub Flavored Markdown extensions:
$ comrak --gfm -t commonmark -t xml
a
a
a
With subscript, a tilde run of one tilde forms subscript instead, and a tilde run of two tildes forms strikethrough:
$ comrak -e strikethrough -e subscript -t commonmark -t xml
H2O is not water.
H2O is not water.
H
2
O is
not
water.
$ comrak -e strikethrough -e subscript -t commonmark -t xml
H2O
H2O
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:
$ comrak -e strikethrough -t commonmark -t xml
a~~a()~~あ
「~~a」~~a
a~~a()~~あ
「~~a」~~a
a~~a()~~あ
「~~a」~~a
With it, they are:
$ comrak -e strikethrough -e cjk-friendly-emphasis -t commonmark -t xml
aa()あ
「a」a
aa()あ
「a」a
a
a()
あ
「
a」
a
With autolinks, the tildes around an autolink aren’t part of it:
$ comrak -e strikethrough -e autolink -t commonmark -t xml
With description lists, a line beginning with a tilde and a space marks details, not a tilde run:
$ comrak -e strikethrough -e description-lists -t commonmark -t xml
- Term
-
details
Term
details
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):
$ comrak -e strikethrough -t commonmark -t xml
This is strikethrough.
As is this, okay?
This text~~~~ is ~~~~curious.
This is strikethrough.
As is this, okay?
This text~~~~ is ~~~~curious.
This is
strikethrough
.
As is
this, okay
?
This
text~~~~ is ~~~~curious
.
An unequal pair doesn’t stop later delimiters from pairing:
$ comrak -e strikethrough -t commonmark -t xml
~~a~ b
~a~~ and b and c
~~a~ b
~a~~ and b and c
~~a~
b
~a~~ and
b
and
c