Created
December 12, 2015 03:45
-
-
Save oyakodon/22f293b193a4de3c1162 to your computer and use it in GitHub Desktop.
HTMLをMarkdown形式に変換するシェルスクリプト(適当)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author : Oyakodon | |
# Summary : HTMLをMARKDOWNに変換する | |
# Expected Dir Tree : |-hoge.html | |
# |-html2md.sh | |
# |-md[dir] | |
# Usage : html2md.sh [HTML-FILENAME] | |
# 引数チェック | |
if [ $# -ne 1 ]; then | |
echo "Usage : $0 FILENAME" 1>&2 | |
exit 1 | |
fi | |
# MDフォルダが存在するかチェック | |
if [ ! -e "md" ]; then | |
echo "DIR\"md\" is Not Found." | |
exit 1 | |
fi | |
# 変数の定義 | |
filepath=$1 | |
output=`echo $filepath | sed -e "s/\.html/.md/"` | |
tmp=`echo $filepath | sed -e 's/$/~/g'` | |
# PANDOCによるMARKDOWN変換処理 | |
pandoc -f html -t markdown_strict -o ${tmp} ${filepath} | |
# 日付部分を抽出し、末尾に連結。出力 | |
date=`grep -oP '[0-9]{4}年[0-9]{2}月[0-9]{2}日 [0-9]{2}時[0-9]{2}分[0-9]{2}秒' $tmp` | |
echo -e "${date}\n" > md/$output | |
tail -n +6 $tmp >> md/$output | |
# 一時ファイルを削除 | |
rm $tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment