Pasting Markdown into Substack: A Command-Line Workflow
If you’ve ever tried to paste Markdown directly into the Substack editor, you’ve likely encountered frustration as it treats everything as plain text, completely ignoring the formatting. While Substack supports HTML, it lacks native Markdown support. Fortunately, you can bypass this limitation entirely by converting Markdown to HTML and copying it directly to your clipboard using pandoc
and xclip
.
This guide explains a streamlined, technical workflow that gets your Markdown into Substack seamlessly.
Prerequisites
You’ll need pandoc
for Markdown-to-HTML conversion and xclip
for clipboard management. On Arch Linux, both are available via the official repositories.
Install pandoc
and xclip
:
sudo pacman -S pandoc xclip
The Command
The following command reads a Markdown file, converts it to HTML, and places the HTML directly into your clipboard as text/html
, ensuring it is formatted correctly when pasted into Substack:
cat input.md | pandoc -f markdown -t html | xclip -selection clipboard -t text/html
How It Works:
cat input.md
: Reads the content of the Markdown file.pandoc -f markdown -t html
: Converts the Markdown input (-f markdown
) to HTML (-t html
).xclip -selection clipboard -t text/html
: Copies the converted HTML into the clipboard, explicitly tagging it astext/html
so Substack recognizes it as formatted content.
Verifying the Clipboard Content
If you want to confirm that the HTML was successfully copied, you can use the following command to inspect the clipboard:
xclip -selection clipboard -o
This will output the raw HTML currently in your clipboard. If you see the expected HTML structure, it’s ready to be pasted.
Automating the Workflow
To simplify the process, you can create a shell alias. Add the following line to your shell configuration file (e.g., ~/.bashrc
or ~/.zshrc
):
alias md2substack='pandoc -f markdown -t html | xclip -selection clipboard -t text/html'
Reload your shell configuration:
source ~/.bashrc # or ~/.zshrc
Now, you can use the alias to convert and copy Markdown in one step:
md2substack < input.md
Alternatively, if you want to type the Markdown directly into the terminal (e.g., for quick notes), you can use:
echo -e "# Title\n\nContent here." | pandoc -f markdown -t html | xclip -selection clipboard -t text/html
Why This Works
Substack supports HTML formatting but lacks native Markdown support. By leveraging pandoc
to convert Markdown to clean HTML and xclip
to tag it as text/html
, this method ensures your content is rendered correctly in the Substack editor without manual reformatting. This approach is faster, more reliable, and highly scriptable for repetitive tasks.
Troubleshooting
If the output isn’t correctly formatted in Substack:
Verify Clipboard Content: Use
xclip -selection clipboard -o
to inspect what’s in your clipboard.Check Pandoc Version: Older versions may handle Markdown differently. Update via:
sudo pacman -Syu pandoc
Validate Input: Ensure your Markdown file doesn’t contain syntax errors that might confuse
pandoc
.
Final Thoughts
This workflow offers a clean, reproducible way to paste Markdown into Substack without sacrificing formatting. By combining pandoc
and xclip
, you can avoid manual reformatting and focus entirely on your content. For those who regularly write in Markdown but publish on platforms like Substack, this is a minimal yet powerful solution.
I wonder if HTML works in <em>the</em> <b>comments?</b>
<ol>
<li>This would be nice</li>
<li>if it worked</li>
</ol>