|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
# This script adds top-level tags to your XML files. |
|
|
|
# - XML header |
|
|
|
# - TEI header |
|
|
|
# - <canto> and <terzine> tags with attributes |
|
|
|
|
|
|
|
echo -e "\nAdding top-level tags." |
|
|
|
@ -11,20 +12,38 @@ do |
|
|
|
if [[ "$file" != 'top-level-tags.sh' ]]; then |
|
|
|
CANTO_NUM="$(echo "'$file'" | tr -d -c 0-9)" # get canto number |
|
|
|
if [[ "$file" == inferno* ]]; then |
|
|
|
CANTICLE="Inferno" |
|
|
|
COMM_NUM="$CANTO_NUM" # same as inferno canto number |
|
|
|
elif [[ "$file" == purgatorio* ]]; then |
|
|
|
CANTICLE="Purgatorio" |
|
|
|
COMM_NUM="$((CANTO_NUM + 34))" # add 34 if in purgatory |
|
|
|
else |
|
|
|
elif [[ "$file" == paradiso* ]]; then |
|
|
|
CANTICLE="Paradiso" |
|
|
|
COMM_NUM="$((CANTO_NUM + 67))" # add 68 if in paradise |
|
|
|
else |
|
|
|
echo -e "\nWhat file is this? $file" |
|
|
|
fi |
|
|
|
# Add tags to first line of file |
|
|
|
sed -i '1s/^/<?xml version="1.0" encoding="UTF-8"?>\n\n<canto num=~CANTO_NUM~ num_comm=~COMM_NUM~>\n\t<terzine>\n/' "$file" |
|
|
|
# Replace canto number and comedy number |
|
|
|
sed -i "s/~CANTO_NUM~/\"$CANTO_NUM\"/" "$file" |
|
|
|
sed -i "s/~COMM_NUM~/\"$COMM_NUM\"/" "$file" |
|
|
|
sed -i -e '1s/^/<?xml version="1.0" encoding="UTF-8"?>\ |
|
|
|
\n<TEI xmlns="http:\/\/www.tei-c.org\/ns\/1.0">\ |
|
|
|
\t<teiHeader>\ |
|
|
|
\t\t<fileDesc>\ |
|
|
|
\t\t\t<titleStmt>Canto ~TITLE_CANTO_NUM~ of ~CANTICLE~<\/titleStmt>\ |
|
|
|
\t\t<\/fileDesc>\ |
|
|
|
\t<\/teiHeader>\ |
|
|
|
\t<text>\ |
|
|
|
\t\t<canto num=~CANTO_NUM~ num_comm=~COMM_NUM~>\ |
|
|
|
\t\t\t<tercets>\n/' "$file" |
|
|
|
# Replace canto number, comedy number, and canticle |
|
|
|
sed -i -e "s/~TITLE_CANTO_NUM~/$CANTO_NUM/" "$file" |
|
|
|
sed -i -e "s/~CANTO_NUM~/\"$CANTO_NUM\"/" "$file" |
|
|
|
sed -i -e "s/~COMM_NUM~/\"$COMM_NUM\"/" "$file" |
|
|
|
sed -i -e "s/~CANTICLE~/$CANTICLE/" "$file" |
|
|
|
# Add tags to end of file |
|
|
|
echo -e "\t</terzine>" >> "$file" |
|
|
|
echo -e "</canto>" >> "$file" |
|
|
|
echo -e "\t\t\t</tercets>" >> "$file" |
|
|
|
echo -e "\t\t</canto>" >> "$file" |
|
|
|
echo -e "\t</text>" >> "$file" |
|
|
|
echo -e "</TEI>" >> "$file" |
|
|
|
# Add a `.xml` extension |
|
|
|
mv "$file" "$file.xml" |
|
|
|
fi |
|
|
|
|