|
Alain Reguera Delgado |
8f60cb |
#!/bin/bash
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# xhtml_doToc.sh -- This functionality transforms web page headings to
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# contents is expanded in place, wherever the
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# piece of code has be expanded, there is no need to put anything else
|
|
Alain Reguera Delgado |
8f60cb |
# in the page.
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# forms:
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# Copyright (C) 2009-2013 The CentOS Project
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# This program is free software; you can redistribute it and/or modify
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# General Public License for more details.
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
8f60cb |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# ----------------------------------------------------------------------
|
|
Alain Reguera Delgado |
8f60cb |
# $Id$
|
|
Alain Reguera Delgado |
8f60cb |
# ----------------------------------------------------------------------
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function xhtml_doToc {
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
local COUNT=0
|
|
Alain Reguera Delgado |
8f60cb |
local PREVCOUNT=0
|
|
Alain Reguera Delgado |
8f60cb |
local -a FINAL
|
|
Alain Reguera Delgado |
8f60cb |
local -a TITLE
|
|
Alain Reguera Delgado |
8f60cb |
local -a MD5SM
|
|
Alain Reguera Delgado |
8f60cb |
local -a OPTNS
|
|
Alain Reguera Delgado |
8f60cb |
local -a CLASS
|
|
Alain Reguera Delgado |
8f60cb |
local -a LEVEL
|
|
Alain Reguera Delgado |
8f60cb |
local -a PARENT
|
|
Alain Reguera Delgado |
8f60cb |
local -a TOCENTRIES
|
|
Alain Reguera Delgado |
8f60cb |
local -a LINK
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
local TOC_CONFIG=${TUNEUP_CONFIG_DIR}/toc.awk
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
cli_checkFiles -e ${TOC_CONFIG}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
local PATTERN='<h([1-6])(.*)>(<a.*[^\>]>)(.*[^<])</h[1-6]>'
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then
|
|
Alain Reguera Delgado |
8f60cb |
continue
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
for HEADING in $(egrep "$PATTERN" $FILE \
|
|
Alain Reguera Delgado |
8f60cb |
| sed -r -e 's!^[[:space:]]+!!' -e "s! !\\\040!g");do
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
if [[ $COUNT -ne 0 ]];then
|
|
Alain Reguera Delgado |
8f60cb |
PREVCOUNT=$(($COUNT-1))
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
FIRST[$COUNT]=$(echo $HEADING | sed -r "s!\\\040! !g")
|
|
Alain Reguera Delgado |
8f60cb |
TITLE[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\4!")
|
|
Alain Reguera Delgado |
8f60cb |
MD5SM[$COUNT]=$(echo "${FILE}${FIRST[$COUNT]}" | md5sum | sed -r 's![[:space:]]+-$!!')
|
|
Alain Reguera Delgado |
8f60cb |
OPTNS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\3!")
|
|
Alain Reguera Delgado |
8f60cb |
CLASS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\2!")
|
|
Alain Reguera Delgado |
8f60cb |
LEVEL[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\1!")
|
|
Alain Reguera Delgado |
8f60cb |
PARENT[$COUNT]=${LEVEL[$PREVCOUNT]}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
if [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
Alain Reguera Delgado |
8f60cb |
OPTNS[$COUNT]=''
|
|
Alain Reguera Delgado |
8f60cb |
elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
Alain Reguera Delgado |
8f60cb |
OPTNS[$COUNT]=''
|
|
Alain Reguera Delgado |
8f60cb |
elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then
|
|
Alain Reguera Delgado |
8f60cb |
OPTNS[$COUNT]=''
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
FINAL[$COUNT]='<h'${LEVEL[$COUNT]}${CLASS[$COUNT]}'>'${OPTNS[$COUNT]}${TITLE[$COUNT]}'</h'${LEVEL[$COUNT]}'>'
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
LINK[$COUNT]=''${TITLE[$COUNT]}''
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
TOCENTRIES[$COUNT]="$COUNT:${LEVEL[$COUNT]}:${PARENT[$COUNT]}:${LINK[$COUNT]}"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
COUNT=$(($COUNT + 1))
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
done
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
TOC=$(echo ''
|
|
Alain Reguera Delgado |
8f60cb |
echo "`gettext "Table of contents"` "
|
|
Alain Reguera Delgado |
8f60cb |
for TOCENTRY in "${TOCENTRIES[@]}";do
|
|
Alain Reguera Delgado |
8f60cb |
echo $TOCENTRY
|
|
Alain Reguera Delgado |
8f60cb |
done \
|
|
Alain Reguera Delgado |
8f60cb |
| awk -f ${TOC_CONFIG})
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
sed -i -r '/[^<\/div].*<\/div>/c'"$(echo -e $TOC)" $FILE
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
unset FINAL
|
|
Alain Reguera Delgado |
8f60cb |
unset TITLE
|
|
Alain Reguera Delgado |
8f60cb |
unset MD5SM
|
|
Alain Reguera Delgado |
8f60cb |
unset OPTNS
|
|
Alain Reguera Delgado |
8f60cb |
unset CLASS
|
|
Alain Reguera Delgado |
8f60cb |
unset LEVEL
|
|
Alain Reguera Delgado |
8f60cb |
unset PARENT
|
|
Alain Reguera Delgado |
8f60cb |
unset TOCENTRIES
|
|
Alain Reguera Delgado |
8f60cb |
unset LINK
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
}
|