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