Debian Codegraph @

tohtml.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # tohtml.sh [v. 0.2.01, reldate: 04/13/12, a teeny bit less buggy]
3
4 # Convert a text file to HTML format.
5 # Author: Mendel Cooper
6 # License: GPL3
7 # Usage: sh tohtml.sh < textfile > htmlfile
8 # Script can easily be modified to accept source and target filenames.
9
10 # Assumptions:
11 # 1) Paragraphs in (target) text file are separated by a blank line.
12 # 2) Jpeg images (*.jpg) are located in "images" subdirectory.
13 # In the target file, the image names are enclosed in square brackets,
14 # for example, [image01.jpg].
15 # 3) Emphasized (italic) phrases begin with a space+underscore
16 #+ or the first character on the line is an underscore,
17 #+ and end with an underscore+space or underscore+end-of-line.
18
19
20 # Settings
21 FNTSIZE=2 # Small-medium font size
22 IMGDIR="images" # Image directory
23 # Headers
24 HDR01='&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;'
25 HDR02='&lt;!-- Converted to HTML by ***tohtml.sh*** script --&gt;'
26 HDR03='&lt;!-- script author: M. Leo Cooper &lt;[email protected]&gt; --&gt;'
27 HDR10='&lt;html&gt;'
28 HDR11='&lt;head&gt;'
29 HDR11a='&lt;/head&gt;'
30 HDR12a='&lt;title&gt;'
31 HDR12b='&lt;/title&gt;'
32 HDR121='&lt;META NAME="GENERATOR" CONTENT="tohtml.sh script"&gt;'
33 HDR13='&lt;body bgcolor="#dddddd"&gt;' # Change background color to suit.
34 HDR14a='&lt;font size='
35 HDR14b='&gt;'
36 # Footers
37 FTR10='&lt;/body&gt;'
38 FTR11='&lt;/html&gt;'
39 # Tags
40 BOLD="&lt;b&gt;"
41 CENTER="&lt;center&gt;"
42 END_CENTER="&lt;/center&gt;"
43 LF="&lt;br&gt;"
44
45
46 write_headersscip-shell shell abs-guide 10-4 write_headers(). ()
47 {
48 echoscip-shell system . . echo. "$HDR01"
49 echoscip-shell system . . echo.
50 echoscip-shell system . . echo. "$HDR02"
51 echoscip-shell system . . echo. "$HDR03"
52 echoscip-shell system . . echo.
53 echoscip-shell system . . echo.
54 echoscip-shell system . . echo. "$HDR10"
55 echoscip-shell system . . echo. "$HDR11"
56 echoscip-shell system . . echo. "$HDR121"
57 echoscip-shell system . . echo. "$HDR11a"
58 echoscip-shell system . . echo. "$HDR13"
59 echoscip-shell system . . echo.
60 echoscip-shell system . . echo. -n "$HDR14a"
61 echoscip-shell system . . echo. -n "$FNTSIZE"
62 echoscip-shell system . . echo. "$HDR14b"
63 echoscip-shell system . . echo.
64 echoscip-shell system . . echo. "$BOLD" # Everything in bold (more easily readable).
65 }
66
67
68 process_textscip-shell shell abs-guide 10-4 process_text(). ()
69 {
70 while read line # Read one line at a time.
71 do
72 {
73 if [scip-shell system . . `[`. ! "$line" ] # Blank line?
74 then # Then new paragraph must follow.
75 echoscip-shell system . . echo.
76 echoscip-shell system . . echo. "$LF" # Insert two &lt;br&gt; tags.
77 echoscip-shell system . . echo. "$LF"
78 echoscip-shell system . . echo.
79 continue # Skip the underscore test.
80 else # Otherwise . . .
81
82 if [[ "$line" =~ \[*jpg\] ]] # Is a graphic?
83 then # Strip away brackets.
84 temp=$( echoscip-shell system . . echo. "$line" | sedscip-shell system . . sed. -e 's/\[//' -e 's/\]//' )
85 line=""$CENTER" &lt;img src="\"$IMGDIR"/$temp\"&gt; "$END_CENTER" "
86 # Add image tag.
87 # And, center it.
88 fi
89
90 fi
91
92
93 echoscip-shell system . . echo. "$line" | grepscip-shell system . . grep. -q _
94 if [scip-shell system . . `[`. "$?" -eq 0 ] # If line contains underscore ...
95 then
96 # ===================================================
97 # Convert underscored phrase to italics.
98 temp=$( echoscip-shell system . . echo. "$line" |
99 sedscip-shell system . . sed. -e 's/ _/ &lt;i&gt;/' -e 's/_/&lt;\/i&gt; /' |
100 sedscip-shell system . . sed. -e 's/^_/&lt;i&gt;/' -e 's/_/&lt;\/i&gt;/' )
101 # Process only underscores prefixed by space,
102 #+ or at beginning or end of line.
103 # Do not convert underscores embedded within a word!
104 line="$temp"
105 # Slows script execution. Can be optimized?
106 # ===================================================
107 fi
108
109
110
111 # echo
112 echoscip-shell system . . echo. "$line"
113 # echo
114 # Don't want extra blank lines in generated text!
115 } # End while
116 done
117 } # End process_text ()
118
119
120 write_footersscip-shell shell abs-guide 10-4 write_footers(). () # Termination tags.
121 {
122 echoscip-shell system . . echo. "$FTR10"
123 echoscip-shell system . . echo. "$FTR11"
124 }
125
126
127 # main () {
128 # =========
129 write_headersscip-shell shell abs-guide 10-4 write_headers().
130 process_textscip-shell shell abs-guide 10-4 process_text().
131 write_footersscip-shell shell abs-guide 10-4 write_footers().
132 # =========
133 # }
134
135 exit $?
136
137 # Exercises:
138 # ---------
139 # 1) Fixup: Check for closing underscore before a comma or period.
140 # 2) Add a test for the presence of a closing underscore
141 #+ in phrases to be italicized.