|
|
9f1608 |
#!/bin/bash
|
|
|
9f1608 |
#
|
|
|
9f1608 |
# html_updateHeadings.sh -- This function transforms html headings to
|
|
|
89c744 |
|
|
|
89c744 |
# order for this function to work, you need to put headings in just
|
|
|
89c744 |
|
|
|
ffdd74 |
#
|
|
|
7cd8e9 |
#
|
|
|
7cd8e9 |
#
|
|
|
7cd8e9 |
#
|
|
|
ffdd74 |
#
|
|
|
89c744 |
|
|
|
89c744 |
# be present and match the openning tag. The value of and
|
|
|
89c744 |
|
|
|
89c744 |
# 'head-' string, plus the heading string. If heading title or page
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
ffdd74 |
#
|
|
|
9f5f2e |
# Copyright (C) 2009-2011 Alain Reguera Delgado
|
|
|
9f1608 |
#
|
|
|
7cd8e9 |
# This program is free software; you can redistribute it and/or
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
|
|
|
9f1608 |
#
|
|
|
9f1608 |
|
|
|
9f1608 |
|
|
|
9f1608 |
|
|
|
9f1608 |
# General Public License for more details.
|
|
|
9f1608 |
#
|
|
|
9f1608 |
|
|
|
9f1608 |
# along with this program; if not, write to the Free Software
|
|
|
9f1608 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
9f1608 |
# USA.
|
|
|
9f1608 |
#
|
|
|
9f1608 |
# ----------------------------------------------------------------------
|
|
|
9f1608 |
# $Id$
|
|
|
9f1608 |
# ----------------------------------------------------------------------
|
|
|
9f1608 |
|
|
|
89c744 |
function tuneup_doXhtmlHeadings {
|
|
|
9f1608 |
|
|
|
ffdd74 |
|
|
|
ad45de |
local COUNT=0
|
|
|
c49cd9 |
local PREVCOUNT=0
|
|
|
ffdd74 |
local PATTERN=''
|
|
|
ffdd74 |
local -a FINAL
|
|
|
ffdd74 |
local -a TITLE
|
|
|
ad45de |
local -a MD5SM
|
|
|
ad45de |
local -a OPTNS
|
|
|
c49cd9 |
local -a LEVEL
|
|
|
c49cd9 |
local -a PARENT
|
|
|
8aa7eb |
local -a TOCENTRIES
|
|
|
8aa7eb |
local -a LINK
|
|
|
ffdd74 |
|
|
|
8aa7eb |
|
|
|
79e7c6 |
|
|
|
89c744 |
PATTERN="<h([1-6])>(<a.*[^\>]>)(.*[^<])</h[1-6]>"
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then
|
|
|
89c744 |
continue
|
|
|
89c744 |
fi
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
for HEADING in $(egrep "$PATTERN" $FILE \
|
|
|
89c744 |
| sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
if [[ $COUNT -ne 0 ]];then
|
|
|
89c744 |
PREVCOUNT=$(($COUNT-1))
|
|
|
89c744 |
fi
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
FIRST[$COUNT]=$(echo $HEADING | sed -r "s!\\\040! !g")
|
|
|
89c744 |
TITLE[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\3!")
|
|
|
89c744 |
MD5SM[$COUNT]=$(echo "${FILE}${FIRST[$COUNT]}" | md5sum | sed -r 's![[:space:]]+-$!!')
|
|
|
89c744 |
OPTNS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\2!")
|
|
|
89c744 |
LEVEL[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\1!")
|
|
|
89c744 |
PARENT[$COUNT]=${LEVEL[$PREVCOUNT]}
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
if [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
|
89c744 |
OPTNS[$COUNT]=''
|
|
|
89c744 |
elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
|
89c744 |
OPTNS[$COUNT]=''
|
|
|
89c744 |
elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
|
89c744 |
OPTNS[$COUNT]=''
|
|
|
89c744 |
fi
|
|
|
ffdd74 |
|
|
|
89c744 |
|
|
|
89c744 |
FINAL[$COUNT]='<h'${LEVEL[$COUNT]}'>'${OPTNS[$COUNT]}${TITLE[$COUNT]}'</h'${LEVEL[$COUNT]}'>'
|
|
|
216869 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
LINK[$COUNT]=''${TITLE[$COUNT]}''
|
|
|
46d906 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
TOCENTRIES[$COUNT]="$COUNT:${LEVEL[$COUNT]}:${PARENT[$COUNT]}:${LINK[$COUNT]}"
|
|
|
ffdd74 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE
|
|
|
ffdd74 |
|
|
|
89c744 |
|
|
|
89c744 |
COUNT=$(($COUNT + 1))
|
|
|
8aa7eb |
|
|
|
ffdd74 |
done
|
|
|
ffdd74 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
TOC=$(echo ''
|
|
|
89c744 |
echo "`gettext "Table of contents"`"
|
|
|
89c744 |
for TOCENTRY in "${TOCENTRIES[@]}";do
|
|
|
89c744 |
echo $TOCENTRY
|
|
|
89c744 |
done \
|
|
|
89c744 |
| awk -f ${FUNCCONFIG}/output_forHeadingsToc.awk)
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
sed -i -r '/[^<\/div].*<\/div>/c'"$(echo -e $TOC)" $FILE
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
COUNT=0
|
|
|
89c744 |
PREVCOUNT=0
|
|
|
89c744 |
|
|
|
89c744 |
|
|
|
89c744 |
unset FINAL
|
|
|
89c744 |
unset TITLE
|
|
|
89c744 |
unset MD5SM
|
|
|
89c744 |
unset OPTNS
|
|
|
89c744 |
unset LEVEL
|
|
|
89c744 |
unset PARENT
|
|
|
89c744 |
unset TOCENTRIES
|
|
|
89c744 |
unset LINK
|
|
|
89c744 |
|
|
|
9f1608 |
}
|