1
1
#! /bin/bash
2
2
3
+ SCRIPT_DIR=" ` dirname " $0 " ` "
4
+ SCRIPT_DIR=" ` cd " $SCRIPT_DIR " && pwd` "
5
+
3
6
usage () {
4
7
cat << EOF
5
8
# Usage: convert.sh <INPUT_DIR> <OUTPUT_FILE>
@@ -27,8 +30,8 @@ convert_md_to_json() {
27
30
n=0
28
31
echo -n " [" > " $output_file "
29
32
# for each file in directory (revert sort with file name without extension)
30
- # caution: 2.3.0-1 must be prior then 2.3.0
31
- for file in ` ls $input_dir /* .md | rev | cut -d . -f 2- | rev | sort -r`
33
+ # caution: 2.3.0-1 must be prior to 2.3.0
34
+ for file in ` ls -1 " $input_dir " /* .md | rev | cut -d . -f 2- | rev | sort -r`
32
35
do
33
36
version=" $( basename " $file " ) "
34
37
echo " Find $version ($file )"
@@ -42,12 +45,11 @@ convert_md_to_json() {
42
45
echo " ${version} \" ," >> " $output_file "
43
46
echo -n $' \t\t "content": "' >> " $output_file "
44
47
45
- # Reading each line and convert CR with "\n"
46
- while read line; do
47
- # Escape '"'
48
- line=$( echo " $line " | sed -e ' s/[\"]/\\&/g' )
49
- echo -n " $line \\\\ n" >> " $output_file "
50
- done < " ${file} .md"
48
+ # Read each line and convert CR with "\n"
49
+ " $SCRIPT_DIR /../JSON.sh/JSON.sh" -Q < " ${file} .md" >> " $output_file "
50
+ # Add literal "\n" at end of converted text, before the closing quote"
51
+ echo -n ' \\' >> " $output_file "
52
+ echo -n ' n' >> " $output_file "
51
53
echo -n $' "\n\t }' >> " $output_file "
52
54
n=$(( n+ 1 ))
53
55
done
@@ -60,6 +62,7 @@ convert_md_to_json() {
60
62
if [ $# -lt 2 ]; then
61
63
echo " Bad parameters"
62
64
usage
65
+ exit 1
63
66
else
64
67
input_dir=" $1 "
65
68
output_file=" $2 "
0 commit comments