Skip to content

Instantly share code, notes, and snippets.

@masutaka
Last active March 20, 2017 10:02
Show Gist options
  • Select an option

  • Save masutaka/514514773a07fda1d221 to your computer and use it in GitHub Desktop.

Select an option

Save masutaka/514514773a07fda1d221 to your computer and use it in GitHub Desktop.
雑なQiita markdown previewer
#!/bin/sh
# Prepare: gem install qiita-markdown-cli
# Usage: qiitadown.sh hoge.md
set -eu
INPUT=$1
OUTPUT=/tmp/qiitadown.html
CSS=/tmp/qiitadown.css
CSS_URL=https://raw.githubusercontent.com/temperman/Qiitadown/master/qiitadown.css
SHA256=1393c2ac9f53c13a064a5056a58e462da88640ccfce854054b508932f71a9d39
sha256() {
shasum -a 256 $1 2> /dev/null | awk '{print $1}'
}
if [ ! -f "$CSS" -o "$(sha256 $CSS)" != "$SHA256" ];then
curl -s -o $CSS $CSS_URL
fi
cat <<EOF > $OUTPUT
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Qiitadown Preview</title>
<link rel="shortcut icon" href="https://qiita.com/icons/favicons/team/production.ico?v=1" type="image/x-icon" />
<style>
$(cat $CSS)
</style>
</head>
<body>
<article class="markdownContent">
$(qmc $INPUT)
</article>
</body>
</html>
EOF
open $OUTPUT
@masutaka
Copy link
Author

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