Sashmark / Blog

Markdown strikethrough not working: what pandoc wrote

Bobby Huang ·

Under Three one-line test files, the input lines and the six reader settings are set out. Output for a word between double tildes appears in Double tildes under the markdown reader. Runs that drop one extension are quoted in When strikeout is switched off. Spec searches beside one bare commonmark run are gathered in Commonmark output beside the spec. The section Adding strikeout to commonmark covers two runs with that extension turned on. Single-tilde output, with a link for subscript, is in One tilde on each side. A padded word's output is quoted in Spaces inside the tildes. Steps with grep, od and pandoc make up Check a struck word with grep and pandoc.

Key takeaways

  • Pandoc's sk.md result for that reader sits in Double tildes under the markdown reader.
  • Output with strikeout or subscript taken away is set out in When strikeout is switched off.
  • Grep totals from the spec file sit under Commonmark output beside the spec, next to their control.
  • Under One tilde on each side, one single-tilde run sits beside a link to the subscript post.
  • The section Check a struck word with grep and pandoc shows the steps.

If markdown strikethrough is not working, start with the reader setting that parsed the file. In this test, ~~drafted~~ came out as a del element under pandoc's markdown reader and stayed as plain text under its commonmark reader.

Each conversion ran once on a Mac, and pandoc --version named 3.8.3. This page quotes the HTML elements pandoc wrote and checks nothing past that output. A wider tour of Markdown marks lives in the syntax guide.

Three one-line test files

Running grep -n '~' sk.md sk1.md sk-space.md printed:

sk.md:1:Jane Doe ~~drafted~~ signed the plan.
sk1.md:1:Jane Doe ~drafted~ signed the plan.
sk-space.md:1:Jane Doe ~~ drafted ~~ signed the plan.

Each file holds one line. All three carry the same sentence about Jane Doe, so only the tildes and spaces change from file to file. sk.md wraps the word in two tildes per side, sk1.md uses one per side, and sk-space.md puts a space between each tilde pair and the word.

Every file went through six reader settings: markdown, markdown-strikeout, markdown-subscript, commonmark, commonmark+strikeout and commonmark+strikeout+subscript. Adding +strikeout to a reader name turned that extension on for one run, and -strikeout turned it off.

Double tildes under the markdown reader

The command:

pandoc -f markdown -t html sk.md

Output:

<p>Jane Doe <del>drafted</del> signed the plan.</p>

Pandoc put a del element around the word and dropped all four tildes.

To see which extensions were on, this test filtered the reader's extension list:

pandoc --list-extensions=markdown | grep -E 'strikeout|subscript|all_symbols_escapable'

That printed +all_symbols_escapable, +strikeout and +subscript, one per line. So strikeout and subscript were both active for the run above.

When strikeout is switched off

Now the same file, with strikeout removed:

pandoc -f markdown-strikeout -t html sk.md

Output:

<p>Jane Doe <sub></sub>drafted<sub></sub> signed the plan.</p>

With strikeout gone, the subscript extension still ran. It read each tilde pair as an empty subscript, so pandoc wrote two empty sub elements and left the word sitting between them.

Removing the other extension gave a different line. pandoc -f markdown-subscript -t html sk.md wrote <p>Jane Doe <del>drafted</del> signed the plan.</p>, which matches the full markdown reader. For this double-tilde file, strikeout by itself was enough to get a del element.

Commonmark output beside the spec

The command:

pandoc -f commonmark -t html sk.md

Output:

<p>Jane Doe ~~drafted~~ signed the plan.</p>

All four tildes came through as text, and no del element appeared. Filtering pandoc --list-extensions=commonmark for those names printed -strikeout and -subscript, so both were off.

Next, grep -ci -F looked for each term inside the spec file. The terms strikethrough, strikeout and subscript each matched 0 lines. As controls, code fence matched 17 and tilde matched 5. That spec, CommonMark at 0.31.2, uses lines 1808-1810 to list tildes as one of two characters that can open a code fence.

Adding strikeout to commonmark

Turn the extension on for the same reader:

pandoc -f commonmark+strikeout -t html sk.md

Output:

<p>Jane Doe <del>drafted</del> signed the plan.</p>

This reader's own list had shown -strikeout, and the plus sign flipped that switch for one conversion while sk.md stayed untouched. With subscript added as well, commonmark+strikeout+subscript wrote that same line. If your files go through the commonmark reader and you want a del element, +strikeout on the reader name is the switch this test used.

One tilde on each side

The file sk1.md holds Jane Doe ~drafted~ signed the plan. and nothing else. Under markdown, pandoc wrote <p>Jane Doe <sub>drafted</sub> signed the plan.</p>. Single-tilde subscript has its own walkthrough in the post on superscript and subscript.

If you meant to strike a word, two tildes per side gave a del element in the 3.8.3 run behind this post, under pandoc's markdown reader with its strikeout extension on.

Spaces inside the tildes

The file sk-space.md adds a space after the opening pair and another before the closing pair. None of the six settings wrote a del element for it. Both markdown and markdown-strikeout gave:

<p>Jane Doe <sub></sub> drafted <sub></sub> signed the plan.</p>

Here too, subscript read each tilde pair as an empty subscript, and the spaces stayed beside the word. The other four settings gave back the line unchanged: <p>Jane Doe ~~ drafted ~~ signed the plan.</p>. Those four were markdown-subscript, commonmark, commonmark+strikeout and commonmark+strikeout+subscript.

To fix a padded word, close the gaps so each tilde pair touches the word, as in sk.md. Then convert again and count del tags, as step 3 of Check a struck word with grep and pandoc shows.

Check a struck word with grep and pandoc

Run these steps on any file where a struck word came out wrong.

  1. Find the tilde lines. grep -n '~' sk.md sk1.md sk-space.md printed each matching line with its file name and line number, as quoted under Three one-line test files.
  2. Inspect the bytes near the word. od -c sk.md showed two ~ cells directly before the d of drafted, with no blank cell between them. A blank cell there points to the padded case in Spaces inside the tildes.
  3. Convert the file and count del tags. After pandoc -t html -f commonmark sk.md -o sk.html, the count from grep -c '<del>' sk.html was 0. The same pair printed 1 with -f commonmark+strikeout and 1 with -f markdown.
  4. Read the HTML for empty sub pairs. Output holding <sub></sub> means the subscript extension took the tildes, as the section When strikeout is switched off shows.
  5. Compare reader settings on one file. In this post, changing just the -f value changed the HTML while the source bytes stayed put, so a mismatch between two outputs points at the setting.
  6. Pick the reader setting. For two tildes per side, markdown and commonmark+strikeout each wrote a del element in this test.

Where Sashmark fits

Should Sashmark's first version come out as planned, a phrase could be changed where the page would show it rendered. The file would then go back on disk by way of a second planned piece, its clean Round-Trip, and lines skipped by the edit would keep the very bytes they carried before. Further down the plan, a Changes View would point to what shifted since your previous reading, with git left out.

It is in development and has not been released. The app itself has no AI features. See the planned features, the help pages and the roadmap for where each part stands.

More at sashmark.com.

Questions

My markdown strikethrough is not working. Why?
The section Commonmark output beside the spec quotes the commonmark run on sk.md and the spec searches.
Why did one tilde on each side not strike the word?
The section One tilde on each side quotes what pandoc wrote for sk1.md.
Can I put spaces inside the tildes?
Pandoc's output for sk-space.md is quoted in Spaces inside the tildes.
Can I test whether pandoc struck the word?
Steps using grep, od and pandoc fill the section Check a struck word with grep and pandoc.

What Sashmark plans for v1: Features · Roadmap

View as Markdown