From ffdd74691e2069369095e8c7b035b71c85d94c3c Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Oct 07 2010 18:59:48 +0000 Subject: Update html_updateHeadings.sh. Got something functional at this point, but table of contents aren't still supported. They are planned for to night :). Update html_getActions.sh to let know when the option is not valid. --- diff --git a/Scripts/Bash/Functions/Html/html_getActions.sh b/Scripts/Bash/Functions/Html/html_getActions.sh index a77f282..89de57b 100755 --- a/Scripts/Bash/Functions/Html/html_getActions.sh +++ b/Scripts/Bash/Functions/Html/html_getActions.sh @@ -31,11 +31,15 @@ function html_getActions { # script supports. case $OPTIONNAM in - --update-headings ) + '--update-headings' ) # Update html headings to create table of content. html_updateHeadings ;; + * ) + cli_printMessage "`eval_gettext "The option provided is not valid."`" + ;; + esac } diff --git a/Scripts/Bash/Functions/Html/html_updateHeadings.sh b/Scripts/Bash/Functions/Html/html_updateHeadings.sh index 3176284..a5230a1 100644 --- a/Scripts/Bash/Functions/Html/html_updateHeadings.sh +++ b/Scripts/Bash/Functions/Html/html_updateHeadings.sh @@ -5,6 +5,18 @@ # heading levels are supported using nested lists. Use this function # over html files inside the repository to standardize their headings. # +# - In order for this function to work, you need to put headings in +# just one line and they must have the following format: +# +#

Title

+# +# Here h1 alternates between 1 and 6. Closing tag must be present +# and match the one opening. The value of option is +# the md5sum of page location, the 'head-' string plus heading +# title. If heading title or page location changes, does the option value changes too. This idea is similar to that +# one used by MoinMoin wiki. +# # - This function looks for
...
specification # inside your page and, if present, replace the content inside # with the link list o headinds. @@ -41,4 +53,96 @@ function html_updateHeadings { + # Define variables as local to avoid conflicts outside. + local FILES='' + local LEVEL=1 + local HEADING='' + local PATTERN='' + local -a FIRST + local -a NAME + local -a FINAL + local -a TITLE + + # Define list of html files to process using option value as + # reference. + if [[ -d $OPTIONVAL ]];then + FILES=$(find $OPTIONVAL -regextype posix-egrep -type f -regex '.*/*.(html|htm)$') + elif [[ -f $OPTIONVAL ]];then + FILES=$OPTIONVAL + fi + + for FILE in $FILES;do + + # Verify list of html files. Are they really html files? If + # they don't, continue with the next one in the list. + if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then + continue + fi + + # Output action message. + cli_printMessage $FILE 'AsUpdatingLine' + + # Define how many heading levels this function works with. + until [[ $LEVEL -eq 7 ]]; do + + # Define translation pattern. Use parenthisis to save + # html option name, option value, and heading title. + PATTERN="(]>)(.*[^<])
" + + # Define list of headings to process. When building the + # heading, it is required to change spaces characters from + # its current output form to something different (e.g., + # its \x040 octal alternative). This is required because + # the space character is used as egrep default field + # separator and spaces can be present inside heading + # strings we don't want to separate. + for HEADING in $(egrep "$PATTERN" $FILE \ + | sed -r -e 's!^[[:space:]]+!!' -e "s! !\x040!g");do + + # Define initial heading information. + FIRST[$COUNT]=$(echo $HEADING | sed -r "s!\x040! !g") + TITLE[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\2!") + MD5SM[$COUNT]=$(echo "${FILE}${TITLE[$COUNT]}" | md5sum | sed -r 's![[:space:]]+-$!!') + OPTNS[$COUNT]=$(echo ${FIRST[$COUNT]} | sed -r "s!$PATTERN!\1!") + + # Transform heading information using initial heading + # information as reference. + if [[ ${OPTNS[$COUNT]} =~ '^$' ]];then + + OPTNS[$COUNT]='' + + elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then + + OPTNS[$COUNT]='' + + elif [[ ${OPTNS[$COUNT]} =~ '^$' ]];then + + OPTNS[$COUNT]='' + + fi + + FINAL[$COUNT]=''${OPTNS[$COUNT]}${TITLE[$COUNT]}'' + + # Update heading information using transformed heading + # information. + sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE + + # Increase heading counter. + COUNT=$(($COUNT + 1)) + + done + + # Reset heading counter. + COUNT=0 + + # Increase level counter. + LEVEL=$(($LEVEL + 1)) + + done + + # Reset level counter. + LEVEL=0 + + done + }