~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/modules/filters/thmlhtml.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
Import upstream version 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                     thmlhtml.cpp  -  ThML to HTML filter
 
3
                             -------------------
 
4
    begin                : 1999-10-27
 
5
    copyright            : 2001 by CrossWire Bible Society
 
6
 ***************************************************************************/
 
7
 
 
8
/***************************************************************************
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
 
 
17
#include <stdlib.h>
 
18
#include <thmlhtml.h>
 
19
#include <swmodule.h>
 
20
#include <utilxml.h>
 
21
 
 
22
SWORD_NAMESPACE_START
 
23
 
 
24
ThMLHTML::ThMLHTML() {
 
25
        setTokenStart("<");
 
26
        setTokenEnd(">");
 
27
/*
 
28
        setEscapeStart("&");
 
29
        setEscapeEnd(";");
 
30
 
 
31
        setEscapeStringCaseSensitive(true);
 
32
 
 
33
        addEscapeStringSubstitute("nbsp", " ");
 
34
        addEscapeStringSubstitute("quot", "\"");
 
35
        addEscapeStringSubstitute("amp", "&");
 
36
        addEscapeStringSubstitute("lt", "<");
 
37
        addEscapeStringSubstitute("gt", ">");
 
38
        addEscapeStringSubstitute("brvbar", "|");
 
39
        addEscapeStringSubstitute("sect", "�");
 
40
        addEscapeStringSubstitute("copy", "�");
 
41
        addEscapeStringSubstitute("laquo", "�");
 
42
        addEscapeStringSubstitute("reg", "�");
 
43
        addEscapeStringSubstitute("acute", "�");
 
44
        addEscapeStringSubstitute("para", "�");
 
45
        addEscapeStringSubstitute("raquo", "�");
 
46
 
 
47
        addEscapeStringSubstitute("Aacute", "�");
 
48
        addEscapeStringSubstitute("Agrave", "�");
 
49
        addEscapeStringSubstitute("Acirc", "�");
 
50
        addEscapeStringSubstitute("Auml", "�");
 
51
        addEscapeStringSubstitute("Atilde", "�");
 
52
        addEscapeStringSubstitute("Aring", "�");
 
53
        addEscapeStringSubstitute("aacute", "�");
 
54
        addEscapeStringSubstitute("agrave", "�");
 
55
        addEscapeStringSubstitute("acirc", "�");
 
56
        addEscapeStringSubstitute("auml", "�");
 
57
        addEscapeStringSubstitute("atilde", "�");
 
58
        addEscapeStringSubstitute("aring", "�");
 
59
        addEscapeStringSubstitute("Eacute", "�");
 
60
        addEscapeStringSubstitute("Egrave", "�");
 
61
        addEscapeStringSubstitute("Ecirc", "�");
 
62
        addEscapeStringSubstitute("Euml", "�");
 
63
        addEscapeStringSubstitute("eacute", "�");
 
64
        addEscapeStringSubstitute("egrave", "�");
 
65
        addEscapeStringSubstitute("ecirc", "�");
 
66
        addEscapeStringSubstitute("euml", "�");
 
67
        addEscapeStringSubstitute("Iacute", "�");
 
68
        addEscapeStringSubstitute("Igrave", "�");
 
69
        addEscapeStringSubstitute("Icirc", "�");
 
70
        addEscapeStringSubstitute("Iuml", "�");
 
71
        addEscapeStringSubstitute("iacute", "�");
 
72
        addEscapeStringSubstitute("igrave", "�");
 
73
        addEscapeStringSubstitute("icirc", "�");
 
74
        addEscapeStringSubstitute("iuml", "�");
 
75
        addEscapeStringSubstitute("Oacute", "�");
 
76
        addEscapeStringSubstitute("Ograve", "�");
 
77
        addEscapeStringSubstitute("Ocirc", "�");
 
78
        addEscapeStringSubstitute("Ouml", "�");
 
79
        addEscapeStringSubstitute("Otilde", "�");
 
80
        addEscapeStringSubstitute("oacute", "�");
 
81
        addEscapeStringSubstitute("ograve", "�");
 
82
        addEscapeStringSubstitute("ocirc", "�");
 
83
        addEscapeStringSubstitute("ouml", "�");
 
84
        addEscapeStringSubstitute("otilde", "�");
 
85
        addEscapeStringSubstitute("Uacute", "�");
 
86
        addEscapeStringSubstitute("Ugrave", "�");
 
87
        addEscapeStringSubstitute("Ucirc", "�");
 
88
        addEscapeStringSubstitute("Uuml", "�");
 
89
        addEscapeStringSubstitute("uacute", "�");
 
90
        addEscapeStringSubstitute("ugrave", "�");
 
91
        addEscapeStringSubstitute("ucirc", "�");
 
92
        addEscapeStringSubstitute("uuml", "�");
 
93
        addEscapeStringSubstitute("Yacute", "�");
 
94
        addEscapeStringSubstitute("yacute", "�");
 
95
        addEscapeStringSubstitute("yuml", "�");
 
96
 
 
97
        addEscapeStringSubstitute("deg", "�");
 
98
        addEscapeStringSubstitute("plusmn", "�");
 
99
        addEscapeStringSubstitute("sup2", "�");
 
100
        addEscapeStringSubstitute("sup3", "�");
 
101
        addEscapeStringSubstitute("sup1", "�");
 
102
        addEscapeStringSubstitute("nbsp", "�");
 
103
        addEscapeStringSubstitute("pound", "�");
 
104
        addEscapeStringSubstitute("cent", "�");
 
105
        addEscapeStringSubstitute("frac14", "�");
 
106
        addEscapeStringSubstitute("frac12", "�");
 
107
        addEscapeStringSubstitute("frac34", "�");
 
108
        addEscapeStringSubstitute("iquest", "�");
 
109
        addEscapeStringSubstitute("iexcl", "�");
 
110
        addEscapeStringSubstitute("ETH", "�");
 
111
        addEscapeStringSubstitute("eth", "�");
 
112
        addEscapeStringSubstitute("THORN", "�");
 
113
        addEscapeStringSubstitute("thorn", "�");
 
114
        addEscapeStringSubstitute("AElig", "�");
 
115
        addEscapeStringSubstitute("aelig", "�");
 
116
        addEscapeStringSubstitute("Oslash", "�");
 
117
        addEscapeStringSubstitute("curren", "�");
 
118
        addEscapeStringSubstitute("Ccedil", "�");
 
119
        addEscapeStringSubstitute("ccedil", "�");
 
120
        addEscapeStringSubstitute("szlig", "�");
 
121
        addEscapeStringSubstitute("Ntilde", "�");
 
122
        addEscapeStringSubstitute("ntilde", "�");
 
123
        addEscapeStringSubstitute("yen", "�");
 
124
        addEscapeStringSubstitute("not", "�");
 
125
        addEscapeStringSubstitute("ordf", "�");
 
126
        addEscapeStringSubstitute("uml", "�");
 
127
        addEscapeStringSubstitute("shy", "�");
 
128
        addEscapeStringSubstitute("macr", "�");
 
129
*/
 
130
        setTokenCaseSensitive(true);
 
131
 
 
132
        addTokenSubstitute("note", " <font color=\"#800000\"><small>(");
 
133
        addTokenSubstitute("/note", ")</small></font> ");
 
134
}
 
135
 
 
136
 
 
137
bool ThMLHTML::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
 
138
        if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution
 
139
                MyUserData *u = (MyUserData *)userData;
 
140
                XMLTag tag(token);
 
141
                if (!strcmp(tag.getName(), "sync")) {
 
142
                        if (tag.getAttribute("type") && tag.getAttribute("value") && !strcmp(tag.getAttribute("type"), "Strongs")) {
 
143
                                const char* value = tag.getAttribute("value");
 
144
                                if (*value == 'H' || *value == 'G' || *value == 'A') {
 
145
                                        value++;
 
146
                                        buf += "<small><em>";
 
147
                                        buf += value;
 
148
                                        buf += "</em></small>";
 
149
                                }
 
150
                                else if (*value == 'T') {
 
151
                                        value += 2;
 
152
 
 
153
                                        buf += "<small><i>";
 
154
                                        buf += value;
 
155
                                        buf += "</i></small>";
 
156
                                }
 
157
                        }
 
158
                        else if (tag.getAttribute("type") && tag.getAttribute("value") && !strcmp(tag.getAttribute("type"), "morph")) {
 
159
                                buf += "<small><em>";
 
160
                                buf += tag.getAttribute("value");
 
161
                                buf += "</em></small>";
 
162
                        }
 
163
                        else if (tag.getAttribute("type") && tag.getAttribute("value") && !strcmp(tag.getAttribute("type"), "lemma")) {
 
164
                                buf += "<small><em>(";
 
165
                                buf += tag.getAttribute("value");
 
166
                                buf += ")</em></small>";
 
167
                        }
 
168
                }
 
169
                else if (!strcmp(tag.getName(), "div")) {
 
170
                        if (tag.isEndTag() && (u->SecHead)) {
 
171
                                buf += "</i></b><br />";
 
172
                                u->SecHead = false;
 
173
                        }
 
174
                        else if (tag.getAttribute("class")) {
 
175
                                if (!strcmp(tag.getAttribute("class"), "sechead")) {
 
176
                                        u->SecHead = true;
 
177
                                        buf += "<br /><b><i>";
 
178
                                }
 
179
                                else if (!strcmp(tag.getAttribute("class"), "title")) {
 
180
                                        u->SecHead = true;
 
181
                                        buf += "<br /><b><i>";
 
182
                                }
 
183
                        }
 
184
                }
 
185
                else if (!strcmp(tag.getName(), "img")) {
 
186
                        const char *src = strstr(token, "src");
 
187
                        if (!src)               // assert we have a src attribute
 
188
                                return false;
 
189
 
 
190
                        buf += '<';
 
191
                        for (const char *c = token; *c; c++) {
 
192
                                if (c == src) {
 
193
                                        for (;((*c) && (*c != '"')); c++)
 
194
                                                buf += *c;
 
195
 
 
196
                                        if (!*c) { c--; continue; }
 
197
 
 
198
                                        buf += '"';
 
199
                                        if (*(c+1) == '/') {
 
200
                                                buf += "file:";
 
201
                                                buf += userData->module->getConfigEntry("AbsoluteDataPath");
 
202
                                                if (buf[buf.length()-2] == '/')
 
203
                                                        c++;            // skip '/'
 
204
                                        }
 
205
                                        continue;
 
206
                                }
 
207
                                buf += *c;
 
208
                        }
 
209
                        buf += '>';
 
210
                }
 
211
                else if (!strcmp(tag.getName(), "scripRef")) { //do nothing with scrip refs, we leave them out
 
212
 
 
213
                }
 
214
                else {
 
215
                        buf += '<';
 
216
                        buf += token;
 
217
                        buf += '>';
 
218
 
 
219
//                      return false;  // we still didn't handle token
 
220
                }
 
221
        }
 
222
        return true;
 
223
}
 
224
 
 
225
 
 
226
SWORD_NAMESPACE_END