8aa7eb Update html_updateHeadings.sh to add comments; and also move FILES

Authored and Committed by areguera 14 years ago
    Update html_updateHeadings.sh to add comments; and also move FILES
    variable definition from html_updateHeadings.sh upt to html.sh. This
    makes the variable accesible no just by html_updateHeadings but for
    all functionalities. Just one definition, available to many files.
    
    
        
Scripts/Bash/Functions/Html/html.sh CHANGED
@@ -25,8 +25,18 @@
25
25
# ----------------------------------------------------------------------
26
26
27
27
function html {
28
+
29
+ local FILES=''
30
+
31
+ # Define list of html files to process using option value as
32
+ # reference.
33
+ if [[ -d $OPTIONVAL ]];then
34
+ FILES=$(find $OPTIONVAL -regextype posix-egrep -type f -regex '.*/*.(html|htm)$')
35
+ elif [[ -f $OPTIONVAL ]];then
36
+ FILES=$OPTIONVAL
37
+ fi
28
38
29
- # Initialize documentation functions and path patterns.
39
+ # Define command line interface for html-based actions.
30
40
html_getActions
31
41
32
42
}
Scripts/Bash/Functions/Html/html_updateHeadings.sh CHANGED
@@ -41,7 +41,6 @@
41
41
function html_updateHeadings {
42
42
43
43
# Define variables as local to avoid conflicts outside.
44
- local FILES=''
45
44
local COUNT=0
46
45
local PREVCOUNT=0
47
46
local PATTERN=''
@@ -51,18 +50,16 @@ function html_updateHeadings {
51
50
local -a OPTNS
52
51
local -a LEVEL
53
52
local -a PARENT
53
+ local -a TOCENTRIES
54
+ local -a LINK
54
55
55
- # Define list of html files to process using option value as
56
- # reference.
57
- if [[ -d $OPTIONVAL ]];then
56
+ # Define html heading regular expression pattern. Use parenthisis
57
+ # to save html option name, option value, and heading title.
58
+ PATTERN="<h([1-9])>(<a.*[^\>]>)(.*[^<])</a></h[1-9]>"
58
- FILES=$(find $OPTIONVAL -regextype posix-egrep -type f -regex '.*/*.(html|htm)$')
59
- elif [[ -f $OPTIONVAL ]];then
60
- FILES=$OPTIONVAL
61
- fi
62
59
63
60
for FILE in $FILES;do
64
61
65
- # Verify list of html files. Are they really html files? If
62
+ # Verify list of html files. Are files really html files? If
66
63
# they don't, continue with the next one in the list.
67
64
if [[ ! $(file --brief $FILE) =~ '^(XHTML|HTML|XML)' ]];then
68
65
continue
@@ -71,14 +68,10 @@ function html_updateHeadings {
71
68
# Output action message.
72
69
cli_printMessage $FILE 'AsUpdatingLine'
73
70
74
- # Define html heading regular expression. Use parenthisis to save
75
- # html option name, option value, and heading title.
76
- PATTERN="<h([1-9])>(<a.*[^\>]>)(.*[^<])</a></h[1-9]>"
77
-
78
71
# Define list of headings to process. When building the
79
72
# heading, it is required to change spaces characters from its
80
- # current output form to something different (e.g., its \040
81
- # octal alternative). This is required because the space
73
+ # current decimal output to something different (e.g., its
74
+ # \040 octal alternative). This is required because the space
82
75
# character is used as egrep default field separator and
83
76
# spaces can be present inside heading strings we don't want
84
77
# to separate.
@@ -101,26 +94,29 @@ function html_updateHeadings {
101
94
102
95
# Transform heading information using initial heading
103
96
# information as reference.
104
- if [[ ${OPTNS[$COUNT]} =~ '^<a (href|name)=".*[^"]" (href|name)=".*[^"]">$' ]];then
97
+ if [[ ${OPTNS[$COUNT]} =~ '^<a (href|name)="(.*)" (href|name)="(.*)">$' ]];then
105
98
OPTNS[$COUNT]='<a name="head-'${MD5SM[$COUNT]}'" href="#head-'${MD5SM[$COUNT]}'">'
106
- elif [[ ${OPTNS[$COUNT]} =~ '^<a name=".*[^"]">$' ]];then
99
+ elif [[ ${OPTNS[$COUNT]} =~ '^<a name="(.*)">$' ]];then
107
100
OPTNS[$COUNT]='<a name="head-'${MD5SM[$COUNT]}'">'
108
- elif [[ ${OPTNS[$COUNT]} =~ '^<a href=".*[^"]">$' ]];then
101
+ elif [[ ${OPTNS[$COUNT]} =~ '^<a href="(.*)">$' ]];then
109
102
OPTNS[$COUNT]='<a href="#head-'${MD5SM[$COUNT]}'">'
110
103
fi
111
104
112
105
# Build final html heading structure.
113
106
FINAL[$COUNT]='<h'${LEVEL[$COUNT]}'>'${OPTNS[$COUNT]}${TITLE[$COUNT]}'</a></h'${LEVEL[$COUNT]}'>'
114
107
115
- # Build html heading link structure.
108
+ # Build html heading link structure. These links are used
109
+ # by the table of contents later.
116
110
LINK[$COUNT]='<a href="#head-'${MD5SM[$COUNT]}'">'${TITLE[$COUNT]}'</a>'
117
111
118
112
# Build table of contents entry with numerical
119
- # identifications.
113
+ # identifications. The numerical identification is what we
114
+ # use to determine the correct position of each heading
115
+ # link on the table of content.
120
116
TOCENTRIES[$COUNT]="$COUNT:${LEVEL[$COUNT]}:${PARENT[$COUNT]}:${LINK[$COUNT]}"
121
117
122
- # Update heading information using the first and last
123
- # heading structures.
118
+ # Update heading information inside the current file being
119
+ # processed. Use the first and final heading information.
124
120
sed -i -r "s!${FIRST[$COUNT]}!${FINAL[$COUNT]}!" $FILE
125
121
126
122
# Increase heading counter.
@@ -128,7 +124,12 @@ function html_updateHeadings {
128
124
129
125
done
130
126
131
- # Use awk to build the table of content.
127
+ # Build the table of contents using heading numerical
128
+ # identifications as reference. The numerical identification
129
+ # describes the order of headings in one html file. This
130
+ # information is processed by awk to make the appropriate
131
+ # replacements. Finnally, the result is stored in the TOC
132
+ # variable.
132
133
TOC=$(echo '<div class="toc">'
133
134
echo "<h3>`gettext "Table of contents"`</h3>"
134
135
for TOCENTRY in "${TOCENTRIES[@]}";do
@@ -182,13 +183,24 @@ function html_updateHeadings {
182
183
}')
183
184
184
185
185
- # Update file's table of contents.
186
+ # Update table of contents inside the current file being
187
+ # processed.
186
188
sed -i -r '/<div class="toc">(.*)<\/div>/c'"$(echo -e $TOC)" $FILE
187
189
188
190
# Reset counters.
189
191
COUNT=0
190
192
PREVCOUNT=0
191
193
194
+ # Clean up variables to receive the next file.
195
+ unset FINAL
196
+ unset TITLE
197
+ unset MD5SM
198
+ unset OPTNS
199
+ unset LEVEL
200
+ unset PARENT
201
+ unset TOCENTRIES
202
+ unset LINK
203
+
192
204
done
193
205
194
206
}