00001 /*************************************************************************** 00002 thmlhtml.cpp - ThML to HTML filter 00003 ------------------- 00004 begin : 1999-10-27 00005 copyright : 2001 by CrossWire Bible Society 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include <stdlib.h> 00018 #include <string.h> 00019 #include <thmlhtml.h> 00020 #include <swmodule.h> 00021 00022 00023 ThMLHTML::ThMLHTML() { 00024 setTokenStart("<"); 00025 setTokenEnd(">"); 00026 /* 00027 setEscapeStart("&"); 00028 setEscapeEnd(";"); 00029 00030 setEscapeStringCaseSensitive(true); 00031 00032 addEscapeStringSubstitute("nbsp", " "); 00033 addEscapeStringSubstitute("quot", "\""); 00034 addEscapeStringSubstitute("amp", "&"); 00035 addEscapeStringSubstitute("lt", "<"); 00036 addEscapeStringSubstitute("gt", ">"); 00037 addEscapeStringSubstitute("brvbar", "|"); 00038 addEscapeStringSubstitute("sect", "§"); 00039 addEscapeStringSubstitute("copy", "©"); 00040 addEscapeStringSubstitute("laquo", "«"); 00041 addEscapeStringSubstitute("reg", "®"); 00042 addEscapeStringSubstitute("acute", "´"); 00043 addEscapeStringSubstitute("para", "¶"); 00044 addEscapeStringSubstitute("raquo", "»"); 00045 00046 addEscapeStringSubstitute("Aacute", "Á"); 00047 addEscapeStringSubstitute("Agrave", "À"); 00048 addEscapeStringSubstitute("Acirc", "Â"); 00049 addEscapeStringSubstitute("Auml", "Ä"); 00050 addEscapeStringSubstitute("Atilde", "Ã"); 00051 addEscapeStringSubstitute("Aring", "Å"); 00052 addEscapeStringSubstitute("aacute", "á"); 00053 addEscapeStringSubstitute("agrave", "à"); 00054 addEscapeStringSubstitute("acirc", "â"); 00055 addEscapeStringSubstitute("auml", "ä"); 00056 addEscapeStringSubstitute("atilde", "ã"); 00057 addEscapeStringSubstitute("aring", "å"); 00058 addEscapeStringSubstitute("Eacute", "É"); 00059 addEscapeStringSubstitute("Egrave", "È"); 00060 addEscapeStringSubstitute("Ecirc", "Ê"); 00061 addEscapeStringSubstitute("Euml", "Ë"); 00062 addEscapeStringSubstitute("eacute", "é"); 00063 addEscapeStringSubstitute("egrave", "è"); 00064 addEscapeStringSubstitute("ecirc", "ê"); 00065 addEscapeStringSubstitute("euml", "ë"); 00066 addEscapeStringSubstitute("Iacute", "Í"); 00067 addEscapeStringSubstitute("Igrave", "Ì"); 00068 addEscapeStringSubstitute("Icirc", "Î"); 00069 addEscapeStringSubstitute("Iuml", "Ï"); 00070 addEscapeStringSubstitute("iacute", "í"); 00071 addEscapeStringSubstitute("igrave", "ì"); 00072 addEscapeStringSubstitute("icirc", "î"); 00073 addEscapeStringSubstitute("iuml", "ï"); 00074 addEscapeStringSubstitute("Oacute", "Ó"); 00075 addEscapeStringSubstitute("Ograve", "Ò"); 00076 addEscapeStringSubstitute("Ocirc", "Ô"); 00077 addEscapeStringSubstitute("Ouml", "Ö"); 00078 addEscapeStringSubstitute("Otilde", "Õ"); 00079 addEscapeStringSubstitute("oacute", "ó"); 00080 addEscapeStringSubstitute("ograve", "ò"); 00081 addEscapeStringSubstitute("ocirc", "ô"); 00082 addEscapeStringSubstitute("ouml", "ö"); 00083 addEscapeStringSubstitute("otilde", "õ"); 00084 addEscapeStringSubstitute("Uacute", "Ú"); 00085 addEscapeStringSubstitute("Ugrave", "Ù"); 00086 addEscapeStringSubstitute("Ucirc", "Û"); 00087 addEscapeStringSubstitute("Uuml", "Ü"); 00088 addEscapeStringSubstitute("uacute", "ú"); 00089 addEscapeStringSubstitute("ugrave", "ù"); 00090 addEscapeStringSubstitute("ucirc", "û"); 00091 addEscapeStringSubstitute("uuml", "ü"); 00092 addEscapeStringSubstitute("Yacute", "Ý"); 00093 addEscapeStringSubstitute("yacute", "ý"); 00094 addEscapeStringSubstitute("yuml", "ÿ"); 00095 00096 addEscapeStringSubstitute("deg", "°"); 00097 addEscapeStringSubstitute("plusmn", "±"); 00098 addEscapeStringSubstitute("sup2", "²"); 00099 addEscapeStringSubstitute("sup3", "³"); 00100 addEscapeStringSubstitute("sup1", "¹"); 00101 addEscapeStringSubstitute("nbsp", "º"); 00102 addEscapeStringSubstitute("pound", "£"); 00103 addEscapeStringSubstitute("cent", "¢"); 00104 addEscapeStringSubstitute("frac14", "¼"); 00105 addEscapeStringSubstitute("frac12", "½"); 00106 addEscapeStringSubstitute("frac34", "¾"); 00107 addEscapeStringSubstitute("iquest", "¿"); 00108 addEscapeStringSubstitute("iexcl", "¡"); 00109 addEscapeStringSubstitute("ETH", "Ð"); 00110 addEscapeStringSubstitute("eth", "ð"); 00111 addEscapeStringSubstitute("THORN", "Þ"); 00112 addEscapeStringSubstitute("thorn", "þ"); 00113 addEscapeStringSubstitute("AElig", "Æ"); 00114 addEscapeStringSubstitute("aelig", "æ"); 00115 addEscapeStringSubstitute("Oslash", "Ø"); 00116 addEscapeStringSubstitute("curren", "¤"); 00117 addEscapeStringSubstitute("Ccedil", "Ç"); 00118 addEscapeStringSubstitute("ccedil", "ç"); 00119 addEscapeStringSubstitute("szlig", "ß"); 00120 addEscapeStringSubstitute("Ntilde", "Ñ"); 00121 addEscapeStringSubstitute("ntilde", "ñ"); 00122 addEscapeStringSubstitute("yen", "¥"); 00123 addEscapeStringSubstitute("not", "¬"); 00124 addEscapeStringSubstitute("ordf", "ª"); 00125 addEscapeStringSubstitute("uml", "¨"); 00126 addEscapeStringSubstitute("shy", ""); 00127 addEscapeStringSubstitute("macr", "¯"); 00128 */ 00129 setTokenCaseSensitive(true); 00130 00131 addTokenSubstitute("/scripRef", " </a>"); 00132 addTokenSubstitute("note", " <font color=\"#800000\"><small>("); 00133 addTokenSubstitute("/note", ")</small></font> "); 00134 } 00135 00136 00137 bool ThMLHTML::handleToken(char **buf, const char *token, DualStringMap &userData) { 00138 if (!substituteToken(buf, token)) { 00139 // manually process if it wasn't a simple substitution 00140 if (!strncmp(token, "sync type=\"Strongs\" value=\"", 27)) { 00141 if (token[27] == 'H' || token[27] == 'G' || token[27] == 'A') { 00142 pushString(buf, "<small><em>"); 00143 for (const char *tok = token + 5; *tok; tok++) 00144 if(*tok != '\"') 00145 *(*buf)++ = *tok; 00146 pushString(buf, "</em></small>"); 00147 } 00148 else if (token[27] == 'T') { 00149 pushString(buf, "<small><i>"); 00150 for (unsigned int i = 29; token[i] != '\"'; i++) 00151 *(*buf)++ = token[i]; 00152 pushString(buf, "</i></small>"); 00153 } 00154 } 00155 else if (!strncmp(token, "sync type=\"morph\" value=\"", 25)) { 00156 pushString(buf, "<small><em>"); 00157 for (unsigned int i = 25; token[i] != '\"'; i++) 00158 *(*buf)++ = token[i]; 00159 pushString(buf, "</em></small>"); 00160 } 00161 else if (!strncmp(token, "sync type=\"lemma\" value=\"", 25)) { 00162 pushString(buf, "<small><em>("); 00163 for (unsigned int i = 25; token[i] != '\"'; i++) 00164 *(*buf)++ = token[i]; 00165 pushString(buf, ")</em></small>"); 00166 } 00167 else if (!strncmp(token, "scripRef", 8)) { 00168 pushString(buf, "<a href=\""); 00169 for (const char *tok = token + 9; *tok; tok++) 00170 if(*tok != '\"') 00171 *(*buf)++ = *tok; 00172 *(*buf)++ = '\"'; 00173 *(*buf)++ = '>'; 00174 } 00175 else if (!strncmp(token, "img ", 4)) { 00176 const char *src = strstr(token, "src"); 00177 if (!src) // assert we have a src attribute 00178 return false; 00179 00180 *(*buf)++ = '<'; 00181 for (const char *c = token; *c; c++) { 00182 if (c == src) { 00183 for (;((*c) && (*c != '"')); c++) 00184 *(*buf)++ = *c; 00185 00186 if (!*c) { c--; continue; } 00187 00188 *(*buf)++ = '"'; 00189 if (*(c+1) == '/') { 00190 pushString(buf, "file:"); 00191 pushString(buf, module->getConfigEntry("AbsoluteDataPath")); 00192 if (*((*buf)-1) == '/') 00193 c++; // skip '/' 00194 } 00195 continue; 00196 } 00197 *(*buf)++ = *c; 00198 } 00199 *(*buf)++ = '>'; 00200 } 00201 else if(!strncmp(token, "note", 4)) { 00202 pushString(buf, " <font color=\"#800000\"><small>("); 00203 } 00204 00205 else { 00206 return false; // we still didn't handle token 00207 } 00208 } 00209 return true; 00210 } 00211