aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html2markdown31
-rw-r--r--latex2markdown12
-rw-r--r--markdown2html14
-rw-r--r--markdown2latex12
-rw-r--r--markdown2pdf26
5 files changed, 55 insertions, 40 deletions
diff --git a/html2markdown b/html2markdown
index fb5734f39..48232acbb 100644
--- a/html2markdown
+++ b/html2markdown
@@ -2,22 +2,22 @@
# converts html to markdown
# uses an available program to fetch URL and tidy to normalize it first
-[ -n "$(which pandoc)" ] || {
- echo >&2 "You need 'pandoc' to use this program!"
- exit 1
-}
-[ -n "$(which tidy)" ] || {
- echo >&2 "You need 'tidy' to use this program!"
- exit 1
-}
+for p in pandoc tidy; do
+ which $p >/dev/null 2>&1 || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
+done
-if [ -z "$1" ] || [ -f $1 ]; then
- tidy -utf8 $1 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
+if [ -z "$1" ] || [ -f $1 ]; then
+ tidy -utf8 $1 2>/dev/null | \
+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
+ iconv -f utf-8
else
# Treat given argument as an URL. Locate a
# sensible text based browser (note the order).
for p in wget lynx w3m curl links w3c; do
- if which $p >/dev/null; then
+ if which $p >/dev/null 2>&1; then
DUMPER=$p
break
fi
@@ -30,10 +30,13 @@ else
curl) OPT="" ;;
links) OPT="-source" ;;
w3c) OPT="-n -get" ;;
- "") echo -n >&2 "Needs a program to fetch the URL "
- echo -n >&2 "(e.g. wget, w3m, lynx, w3c, or curl)."
+ "") printf "Needs a program to fetch the URL " >&2
+ printf "(e.g. wget, w3m, lynx, w3c, or curl)." >&2
exit 1 ;;
esac
# Fetch and feed to pandoc.
- $DUMPER $OPT $1 2>/dev/null | tidy -utf8 2>/dev/null | pandoc $PANDOC_OPTS -r html -w markdown -s | iconv -f utf-8
+ $DUMPER $OPT $1 2>/dev/null | \
+ tidy -utf8 2>/dev/null | \
+ pandoc $PANDOC_OPTS -r html -w markdown -s | \
+ iconv -f utf-8
fi
diff --git a/latex2markdown b/latex2markdown
index eeffb9b1e..e5e276d62 100644
--- a/latex2markdown
+++ b/latex2markdown
@@ -1,7 +1,11 @@
#!/bin/sh -e
# runs pandoc to convert latex to markdown
-[ -n "$(which pandoc)" ] || {
- echo >&2 "You need 'pandoc' to use this program!"
- exit 1
-}
+
+for p in pandoc; do
+ which $p >/dev/null 2>&1 || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
+done
+
iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | iconv -f utf-8
diff --git a/markdown2html b/markdown2html
index 60dd78a6f..d71e434b4 100644
--- a/markdown2html
+++ b/markdown2html
@@ -1,7 +1,11 @@
#!/bin/sh -e
-# converts markdown to HTML
-[ -n "$(which pandoc)" ] || {
- echo >&2 "You need 'pandoc' to use this program!"
- exit 1
-}
+# converts markdown to HTML
+
+for p in pandoc; do
+ which $p >/dev/null 2>&1 || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
+done
+
iconv -t utf-8 $* | pandoc $PANDOC_OPTS | iconv -f utf-8
diff --git a/markdown2latex b/markdown2latex
index 3f78adbda..59a467fbc 100644
--- a/markdown2latex
+++ b/markdown2latex
@@ -1,7 +1,11 @@
#!/bin/sh -e
# converts markdown to latex
-[ -n "$(which pandoc)" ] || {
- echo >&2 "You need 'pandoc' to use this program!"
- exit 1
-}
+
+for p in pandoc; do
+ which $p >/dev/null 2>&1 || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
+done
+
iconv -t utf-8 $* | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8
diff --git a/markdown2pdf b/markdown2pdf
index eba975436..4af407fb7 100644
--- a/markdown2pdf
+++ b/markdown2pdf
@@ -1,14 +1,12 @@
#!/bin/sh
# converts markdown to latex, then uses latex to make a PDF
-[ -n "$(which pandoc)" ] || {
- echo >&2 "You need 'pandoc' to use this program!"
- exit 1
-}
-[ -n "$(which pdflatex)" ] || {
- echo >&2 "You need 'pdflatex' to use this program!"
- exit 1
-}
+for p in pandoc pdflatex; do
+ which $p >/dev/null 2>&1 || {
+ echo >&2 "You need '$p' to use this program!"
+ exit 1
+ }
+done
outfile=
for option; do
@@ -58,8 +56,9 @@ TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
mkdir -p $TEMP
-iconv -t utf-8 $infile | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8 > $TEMP/$BASE.tex
-(
+iconv -t utf-8 $infile | \
+pandoc $PANDOC_OPTS -w latex -s | \
+iconv -f utf-8 > $TEMP/$BASE.tex && (
cd $TEMP
if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
echo >&2 "LaTeX errors:"
@@ -71,12 +70,13 @@ iconv -t utf-8 $infile | pandoc $PANDOC_OPTS -w latex -s | iconv -f utf-8 > $TEM
is_target_exists=
if [ -f $outfile ]; then
is_target_exists=1
+ mv -f $outfile $outfile~
fi
-mv --suffix=~ --backup $TEMP/$BASE.pdf $outfile
+mv -f $TEMP/$BASE.pdf $outfile
-echo -n >&2 "Created $outfile"
+printf "Created $outfile" >&2
[ -z "$is_target_exists" ] || {
- echo -n >&2 " (previous file has been backed up as '$outfile~')"
+ printf " (previous file has been backed up as '$outfile~')" >&2
}
echo >&2 .