1
/***************************************************************************
2
thmlhtml.cpp - ThML to HTML filter
5
copyright : 2001 by CrossWire Bible Society
6
***************************************************************************/
8
/***************************************************************************
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. *
15
***************************************************************************/
24
ThMLHTML::ThMLHTML() {
31
setEscapeStringCaseSensitive(true);
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", "�");
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", "�");
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", "�");
130
setTokenCaseSensitive(true);
132
addTokenSubstitute("note", " <font color=\"#800000\"><small>(");
133
addTokenSubstitute("/note", ")</small></font> ");
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;
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') {
146
buf += "<small><em>";
148
buf += "</em></small>";
150
else if (*value == 'T') {
155
buf += "</i></small>";
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>";
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>";
169
else if (!strcmp(tag.getName(), "div")) {
170
if (tag.isEndTag() && (u->SecHead)) {
171
buf += "</i></b><br />";
174
else if (tag.getAttribute("class")) {
175
if (!strcmp(tag.getAttribute("class"), "sechead")) {
177
buf += "<br /><b><i>";
179
else if (!strcmp(tag.getAttribute("class"), "title")) {
181
buf += "<br /><b><i>";
185
else if (!strcmp(tag.getName(), "img")) {
186
const char *src = strstr(token, "src");
187
if (!src) // assert we have a src attribute
191
for (const char *c = token; *c; c++) {
193
for (;((*c) && (*c != '"')); c++)
196
if (!*c) { c--; continue; }
201
buf += userData->module->getConfigEntry("AbsoluteDataPath");
202
if (buf[buf.length()-2] == '/')
211
else if (!strcmp(tag.getName(), "scripRef")) { //do nothing with scrip refs, we leave them out
219
// return false; // we still didn't handle token