|
|
9f1608 |
#!/bin/bash
|
|
|
9f1608 |
#
|
|
|
9f1608 |
# html_updateHeadings.sh -- This function transforms html headings to
|
|
|
ad45de |
|
|
|
9f1608 |
#
|
|
|
7cd8e9 |
# - In order for this function to work, you need to put headings in
|
|
|
7cd8e9 |
|
|
|
ffdd74 |
#
|
|
|
7cd8e9 |
#
|
|
|
7cd8e9 |
#
|
|
|
7cd8e9 |
#
|
|
|
ffdd74 |
#
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
|
|
|
7cd8e9 |
# name=""> and options will change too.
|
|
|
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 |
|
|
|
9f1608 |
function html_updateHeadings {
|
|
|
9f1608 |
|
|
|
ffdd74 |
|
|
|
ad45de |
local COUNT=0
|
|
|
3dc4a1 |
local FILE=''
|
|
|
3dc4a1 |
local FILES=''
|
|
|
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 |
|
|
|
8aa7eb |
PATTERN="<h([1-9])>(<a.*[^\>]>)(.*[^<])</h[1-9]>"
|
|
|
ffdd74 |
|
|
|
46d906 |
|
|
|
216869 |
FILES=$(cli_getFilesList "$ACTIONVAL" "${FLAG_FILTER}.*\.(xhtml|html|htm)")
|
|
|
216869 |
|
|
|
216869 |
|
|
|
216869 |
cli_printActionPreamble "${FILES}"
|
|
|
46d906 |
|
|
|
46d906 |
|
|
|
ffdd74 |
for FILE in $FILES;do
|
|
|
ffdd74 |
|
|
|
8aa7eb |
|
|
|
ffdd74 |
|
|
|
ffdd74 |
if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then
|
|
|
ffdd74 |
continue
|
|
|
ffdd74 |
fi
|
|
|
ffdd74 |
|
|
|
ffdd74 |
|
|
|
a9264e |
cli_printMessage $FILE 'AsUpdatingLine'
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
for HEADING in $(egrep "$PATTERN" $FILE \
|
|
|
a9264e |
| sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
if [[ $COUNT -ne 0 ]];then
|
|
|
c49cd9 |
PREVCOUNT=$(($COUNT-1))
|
|
|
c49cd9 |
fi
|
|
|
ffdd74 |
|
|
|
c49cd9 |
|
|
|
a9264e |
FIRST[$COUNT]=$(echo $HEADING | sed -r "s!\\\040! !g")
|
|
|
c49cd9 |
TITLE[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\3!")
|
|
|
c49cd9 |
MD5SM[$COUNT]=$(echo "${FILE}${FIRST[$COUNT]}" | md5sum | sed -r 's![[:space:]]+-$!!')
|
|
|
c49cd9 |
OPTNS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\2!")
|
|
|
c49cd9 |
LEVEL[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\1!")
|
|
|
c49cd9 |
PARENT[$COUNT]=${LEVEL[$PREVCOUNT]}
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
|
|
|
8aa7eb |
if [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
|
c49cd9 |
OPTNS[$COUNT]=''
|
|
|
8aa7eb |
elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
|
c49cd9 |
OPTNS[$COUNT]=''
|
|
|
8aa7eb |
elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
|
c49cd9 |
OPTNS[$COUNT]=''
|
|
|
ad45de |
fi
|
|
|
ad45de |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
FINAL[$COUNT]='<h'${LEVEL[$COUNT]}'>'${OPTNS[$COUNT]}${TITLE[$COUNT]}'</h'${LEVEL[$COUNT]}'>'
|
|
|
ffdd74 |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
c49cd9 |
LINK[$COUNT]=''${TITLE[$COUNT]}''
|
|
|
ffdd74 |
|
|
|
c49cd9 |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
c49cd9 |
TOCENTRIES[$COUNT]="$COUNT:${LEVEL[$COUNT]}:${PARENT[$COUNT]}:${LINK[$COUNT]}"
|
|
|
ffdd74 |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
a9264e |
sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE
|
|
|
ad45de |
|
|
|
c49cd9 |
|
|
|
c49cd9 |
COUNT=$(($COUNT + 1))
|
|
|
ad45de |
|
|
|
c49cd9 |
done
|
|
|
ad45de |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
a9264e |
TOC=$(echo ''
|
|
|
a9264e |
echo "`gettext "Table of contents"`"
|
|
|
a9264e |
for TOCENTRY in "${TOCENTRIES[@]}";do
|
|
|
a9264e |
echo $TOCENTRY
|
|
|
a9264e |
done \
|
|
|
0e71cb |
| awk -f /home/centos/artwork/trunk/Scripts/Bash/Functions/Html/Config/output_forHeadingsToc.awk)
|
|
|
a9264e |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
|
|
|
a9264e |
sed -i -r '/(.*)<\/div>/c'"$(echo -e $TOC)" $FILE
|
|
|
a9264e |
|
|
|
a9264e |
|
|
|
a9264e |
COUNT=0
|
|
|
a9264e |
PREVCOUNT=0
|
|
|
ffdd74 |
|
|
|
8aa7eb |
|
|
|
8aa7eb |
unset FINAL
|
|
|
8aa7eb |
unset TITLE
|
|
|
8aa7eb |
unset MD5SM
|
|
|
8aa7eb |
unset OPTNS
|
|
|
8aa7eb |
unset LEVEL
|
|
|
8aa7eb |
unset PARENT
|
|
|
8aa7eb |
unset TOCENTRIES
|
|
|
8aa7eb |
unset LINK
|
|
|
8aa7eb |
|
|
|
ffdd74 |
done
|
|
|
ffdd74 |
|
|
|
9f1608 |
}
|