-
Notifications
You must be signed in to change notification settings - Fork 11
/
tidy.sh
executable file
·58 lines (46 loc) · 1.62 KB
/
tidy.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
54
55
56
57
#!/bin/bash
if test $# -lt 2 ; then
echo usage: "${0##/*} [Source dir name] [Target dir name]"
exit
fi
output=$2
rm -rf $output
mkdir $output
for filepath in $(find $1 -type f -not -path "*/.svn*" -not -name "*tidy*" -name "*.xml");
do
file=${filepath#*/}
filename=${file%.*}
ext=${file#*.}
echo
echo "Working on $filename.$ext"
# Add tags so tidy won't wrap the <artwork> fields.
cp $filepath $output/$filename.temp
sed -i '' 's/<artwork\([^>]*\)>/<artwork\1><?php SPEC/g' $output/$filename.temp
sed -i '' 's/<\/artwork>/SPEC \?><\/artwork>/g' $output/$filename.temp
# Run tidy
tidy --input-xml yes \
--wrap 80 \
--add-xml-space yes \
--new-blocklevel-tags t \
--new-pre-tags artwork \
--indent yes \
--indent-spaces 1 \
--indent-attributes yes \
--tab-size 1 \
--wrap-php no \
--char-encoding utf8 \
--literal-attributes yes \
--quiet yes \
$output/$filename.temp > $output/$filename.temp.tidy
echo "Tidy exited with status $?"
# Remove the added tags.
awk '{gsub(/<\?php SPEC/, ""); gsub(/SPEC \?>/, "")}/./' $output/$filename.temp.tidy > $output/$filename.$ext
# Add a space after <xref ... /> or <eref ... /> unless it is followed by ., or )
sed -i '' 's/\(<[ex]ref[^>]*\/>\)\([^.),]\)/\1 \2/g' $output/$filename.$ext
# Add a space after </xref> or </eref> unless it is followed by ., or )
sed -i '' 's/\(<\/[ex]ref>\)\([^.),]\)/\1 \2/g' $output/$filename.$ext
echo "Rewrote <eref> and <xref> tags"
# Clean up
rm $output/$filename.temp $output/$filename.temp.tidy
done
cp $1/rfc2629.xslt $output