Skip to content

Instantly share code, notes, and snippets.

@cuellarfr
Last active January 30, 2026 18:45
Show Gist options
  • Select an option

  • Save cuellarfr/15ae4d74c02514472f25bcd1fb74bec9 to your computer and use it in GitHub Desktop.

Select an option

Save cuellarfr/15ae4d74c02514472f25bcd1fb74bec9 to your computer and use it in GitHub Desktop.
A script for CotEditor that launches a Markdown preview in your default browser
#!/bin/bash
#%%%{CotEditorXInput=AllText}%%%
#%%%{CotEditorXOutput=None}%%%
INPUT=$(/opt/homebrew/bin/cmark)
TMPFILE="/tmp/md-preview-$$.html"
cat > "$TMPFILE" << 'EOF'
<html><head>
<style>
body {
font-family: Helvetica, Arial, sans-serif;
max-width: 720px;
margin: 2rem auto;
padding: 0 1rem;
line-height: 1.6;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #1e1e1e;
color: #e0e0e0;
}
a { color: #6cb6ff; }
code, pre {
background-color: #2d2d2d;
}
}
code, pre {
background-color: #f4f4f4;
padding: 0.2em 0.4em;
border-radius: 4px;
}
pre { padding: 1em; overflow-x: auto; }
</style></head><body>
EOF
echo "$INPUT" >> "$TMPFILE"
echo "</body></html>" >> "$TMPFILE"
open "$TMPFILE"
@cuellarfr
Copy link
Copy Markdown
Author

INSTALLATION

  1. brew install cmark
  2. Copy this script into ~/Library/Application Scripts/com.coteditor.CotEditor/
  3. chmod u+x ~/Library/Application Scripts/com.coteditor.CotEditor/Markdown Preview.@M.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment