...
 
Commits (2)
  • ALO's avatar
    Fix issue #1 · ca5dc33f
    ALO authored
    dirname command is useless when using source to get project code.
    Instead, create 2 scripts
    ca5dc33f
  • ALO's avatar
    Repo config · 091099a1
    ALO authored
    091099a1
......@@ -18,10 +18,11 @@ sudo gem install gimli
### Configuration
You need to source markdown-utils.sh in your `~/.bash_aliases` :
You can add aliases to the scripts in your ~/.bash_aliases:
```bash
source <path to markdown-utils>/markdown-utils.sh
alias mdtest='<path to markdown-utils>/mdtest.sh'
alias md2pdf='<path to markdown-utils>/md2pdf.sh'
```
### Convert a file
......
#! /bin/bash
# markdown-utils.sh
# utilities to convert markdown files
SCRIPT_PATH=$(dirname $0)
function md2pdf() {
USAGE="usage: $0 mdFilePath [outDirectory]"
[[ -z ${1} ]] && echo ${USAGE} >&2 && exit 1
MD_FILE=${1}
OUT_DIR_OPTION=""
[[ -n ${2} ]] && OUT_DIR_OPTION="-o ${2}"
gimli -f ${MD_FILE} -s ${SCRIPT_PATH}/style.css -w '-t ' ${OUT_DIR_OPTION}
}
function mdtest() {
USAGE="usage: $0 mdFilePath"
[[ -z ${1} ]] && echo ${USAGE} >&2 && exit 1
MD_FILE=${1}
OUT_DIR=$(mktemp -d)
OUT_FILENAME=${MD_FILE/%.md/.pdf}
md2pdf ${MD_FILE} ${OUT_DIR}
evince ${OUT_DIR}/${OUT_FILENAME}
# Clean temp files
rm ${OUT_DIR}/${OUT_FILENAME}
rmdir ${OUT_DIR}
}
#! /bin/bash
# md2pdf.sh
# Convert Markdown file to PDF
MARKDOWN_PROJECT_PATH=$(dirname $0)
USAGE="usage: $0 mdFilePath [outDirectory]"
[[ -z ${1} ]] && echo ${USAGE} >&2 && exit 1
MD_FILE=${1}
OUT_DIR_OPTION=""
[[ -n ${2} ]] && OUT_DIR_OPTION="-o ${2}"
gimli -f ${MD_FILE} -s ${MARKDOWN_PROJECT_PATH}/style.css -w '-t ' ${OUT_DIR_OPTION}
exit 0
#! /bin/bash
# mdtest.sh
# Convert Markdown file to PDF and remove it immediately after
MARKDOWN_PROJECT_PATH=$(dirname $0)
USAGE="usage: $0 mdFilePath"
[[ -z ${1} ]] && echo ${USAGE} >&2 && exit 1
MD_FILE=${1}
OUT_DIR=$(mktemp -d)
OUT_FILENAME=${MD_FILE/%.md/.pdf}
${MARKDOWN_PROJECT_PATH}/md2pdf.sh ${MD_FILE} ${OUT_DIR}
evince ${OUT_DIR}/${OUT_FILENAME}
# Clean temp files
rm ${OUT_DIR}/${OUT_FILENAME}
rmdir ${OUT_DIR}
exit 0