-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml-to-md.sh
executable file
·54 lines (48 loc) · 980 Bytes
/
xml-to-md.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
function print_syntax_and_exit {
echo Syntax: create-txts.sh [-u] [-o \<output-dir\>] file1 file2 ...
exit 1
}
SRCDIR=`dirname $0`
OUTPUTDIRECTORY="."
UPPERCASE="false"
# Process optional parameters.
while [[ $# -gt 0 && "$1" =~ ^(-u|-o)$ ]]
do
if [ $1 = "-o" ]
then
shift
if [ $# -lt 1 ]
then
print_syntax_and_exit
fi
OUTPUTDIRECTORY=$1
elif [ $1 = "-u" ]
then
UPPERCASE="true"
fi
shift
done
if [ $# -lt 1 ]
then
print_syntax_and_exit
fi
# Process actual files.
while [[ $# -gt 0 ]]
do
BASENAME=`basename $1 .xml`
if [ ${BASENAME} = "changelog" ]
then
XSLTFILE="changelog-md.xslt"
else
XSLTFILE="md.xslt"
fi
if [ $UPPERCASE = "true" ]
then
BASENAME=`echo "${BASENAME}" | tr '[:lower:]' '[:upper:]'`
fi
OUTPUTFILENAME="${OUTPUTDIRECTORY}/${BASENAME}.md"
echo "Converting \"$1\" to \"${OUTPUTFILENAME}\"."
xsltproc -o "$OUTPUTFILENAME" "${SRCDIR}/${XSLTFILE}" "$1"
shift
done