The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfxhtml.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * gbfxhtml.cpp - GBF to classed XHTML
4  *
5  * $Id: gbfxhtml.cpp 3726 2020-04-26 17:53:51Z scribe $
6  *
7  * Copyright 2011-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 
24 #include <stdlib.h>
25 #include <gbfxhtml.h>
26 #include <swmodule.h>
27 #include <utilxml.h>
28 #include <versekey.h>
29 #include <ctype.h>
30 #include <url.h>
31 
33 
34 const char *GBFXHTML::getHeader() const {
35  return "\
36  .wordsOfJesus {\
37  color: red;\
38  }\
39  ";
40 }
41 
43  if (module) {
44  version = module->getName();
45  }
46 }
47 
49  setTokenStart("<");
50  setTokenEnd(">");
51 
53 
54  //addTokenSubstitute("Rf", ")</small></font>");
55  addTokenSubstitute("FA", "<font color=\"#800000\">"); // for ASV footnotes to mark text
56  addTokenSubstitute("Rx", "</a>");
57  addTokenSubstitute("FI", "<i>"); // italics begin
58  addTokenSubstitute("Fi", "</i>");
59  addTokenSubstitute("FB", "<b>"); // bold begin
60  addTokenSubstitute("Fb", "</b>");
61  addTokenSubstitute("FR", "<span class=\"wordsOfJesus\">"); // words of Jesus begin
62  addTokenSubstitute("Fr", "</span>");
63  addTokenSubstitute("FU", "<u>"); // underline begin
64  addTokenSubstitute("Fu", "</u>");
65  addTokenSubstitute("FO", "<cite>"); // Old Testament quote begin
66  addTokenSubstitute("Fo", "</cite>");
67  addTokenSubstitute("FS", "<sup>"); // Superscript begin// Subscript begin
68  addTokenSubstitute("Fs", "</sup>");
69  addTokenSubstitute("FV", "<sub>"); // Subscript begin
70  addTokenSubstitute("Fv", "</sub>");
71  addTokenSubstitute("TT", "<big>"); // Book title begin
72  addTokenSubstitute("Tt", "</big>");
73  addTokenSubstitute("PP", "<cite>"); // poetry begin
74  addTokenSubstitute("Pp", "</cite>");
75  addTokenSubstitute("Fn", "</font>"); // font end
76  addTokenSubstitute("CL", "<br />"); // new line
77  addTokenSubstitute("CM", "<!P><br />"); // paragraph <!P> is a non showing comment that can be changed in the front end to <P> if desired
78  addTokenSubstitute("CG", ""); // ???
79  addTokenSubstitute("CT", ""); // ???
80  addTokenSubstitute("JR", "<div align=\"right\">"); // right align begin
81  addTokenSubstitute("JC", "<div align=\"center\">"); // center align begin
82  addTokenSubstitute("JL", "</div>"); // align end
83 
84  renderNoteNumbers = false;
85 }
86 
87 
88 bool GBFXHTML::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
89  const char *tok;
90  MyUserData *u = (MyUserData *)userData;
91 
92  if (!substituteToken(buf, token)) {
93  XMLTag tag(token);
94 
95  if (!strncmp(token, "WG", 2)) { // strong's numbers
96  //buf += " <small><em>&lt;<a href=\"type=Strongs value=";
97  buf += " <small><em class=\"strongs\">&lt;<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value=";
98  for (tok = token+2; *tok; tok++)
99  //if(token[i] != '\"')
100  buf += *tok;
101  buf += "\" class=\"strongs\">";
102  for (tok = token + 2; *tok; tok++)
103  //if(token[i] != '\"')
104  buf += *tok;
105  buf += "</a>&gt;</em></small>";
106  }
107  else if (!strncmp(token, "WH", 2)) { // strong's numbers
108  //buf += " <small><em>&lt;<a href=\"type=Strongs value=";
109  buf += " <small><em class=\"strongs\">&lt;<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value=";
110  for (tok = token+2; *tok; tok++)
111  //if(token[i] != '\"')
112  buf += *tok;
113  buf += "\" class=\"strongs\">";
114  for (tok = token + 2; *tok; tok++)
115  //if(token[i] != '\"')
116  buf += *tok;
117  buf += "</a>&gt;</em></small>";
118  }
119  else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense
120  //buf += " <small><em>(<a href=\"type=Strongs value=";
121  buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value=";
122  for (tok = token + 3; *tok; tok++)
123  if(*tok != '\"')
124  buf += *tok;
125  buf += "\" class=\"strongs\">";
126  for (tok = token + 3; *tok; tok++)
127  if(*tok != '\"')
128  buf += *tok;
129  buf += "</a>)</em></small>";
130  }
131  else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense
132  //buf += " <small><em>(<a href=\"type=Strongs value=";
133  buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value=";
134  for (tok = token + 3; *tok; tok++)
135  if(*tok != '\"')
136  buf += *tok;
137  buf += "\" class=\"strongs\">";
138  for (tok = token + 3; *tok; tok++)
139  if(*tok != '\"')
140  buf += *tok;
141  buf += "</a>)</em></small>";
142  }
143 
144  else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags
145  //buf += " <small><em>(<a href=\"type=morph class=none value=";
146  buf += " <small><em class=\"morph\">(<a href=\"passagestudy.jsp?action=showMorph&type=Greek&value=";
147 
148  for (tok = token + 2; *tok; tok++)
149  if(*tok != '\"')
150  buf += *tok;
151  buf += "\" class=\"morph\">";
152  for (tok = token + 2; *tok; tok++)
153  if(*tok != '\"')
154  buf += *tok;
155  buf += "</a>)</em></small>";
156  }
157 
158  else if (!strcmp(tag.getName(), "RX")) {
159  buf += "<a href=\"";
160  for (tok = token + 3; *tok; tok++) {
161  if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
162  buf += *tok;
163  }
164  else {
165  break;
166  }
167  }
168  buf += "\">";
169  }
170  else if (!strcmp(tag.getName(), "RF")) {
171  SWBuf type = tag.getAttribute("type");
172  SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
173  SWBuf noteName = tag.getAttribute("n");
174  SWBuf classExtras = "";
175 
176  if (type.size()) {
177  classExtras.append(" ").append(type);
178  }
179 
180  if (u->vkey) {
181  // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt.
182  //char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
183  buf.appendFormatted("<a class=\"noteMarker%s\" href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup class=\"n\">*n%s</sup></small></a> ",
184  classExtras.c_str(),
185  URL::encode(footnoteNumber.c_str()).c_str(),
186  URL::encode(u->version.c_str()).c_str(),
187  URL::encode(u->vkey->getText()).c_str(),
188  (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str(): ""));
189  }
190  u->suspendTextPassThru = true;
191  }
192  else if (!strcmp(tag.getName(), "Rf")) {
193  u->suspendTextPassThru = false;
194  }
195 /*
196  else if (!strncmp(token, "RB", 2)) {
197  buf += "<i> ";
198  u->hasFootnotePreTag = true;
199  }
200 
201  else if (!strncmp(token, "Rf", 2)) {
202  buf += "&nbsp<a href=\"note=";
203  buf += u->lastTextNode.c_str();
204  buf += "\">";
205  buf += "<small><sup>*n</sup></small></a>&nbsp";
206  // let's let text resume to output again
207  u->suspendTextPassThru = false;
208  }
209 
210  else if (!strncmp(token, "RF", 2)) {
211  if (u->hasFootnotePreTag) {
212  u->hasFootnotePreTag = false;
213  buf += "</i> ";
214  }
215  u->suspendTextPassThru = true;
216  }
217 */
218  else if (!strncmp(token, "FN", 2)) {
219  buf += "<font face=\"";
220  for (tok = token + 2; *tok; tok++)
221  if(*tok != '\"')
222  buf += *tok;
223  buf += "\">";
224  }
225 
226  else if (!strncmp(token, "CA", 2)) { // ASCII value
227  buf += (char)atoi(&token[2]);
228  }
229 
230  else {
231  return false;
232  }
233  }
234  return true;
235 }
236 
const char * getName() const
Definition: swmodule.cpp:204
#define SWORD_NAMESPACE_START
Definition: defs.h:39
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
void setTokenEnd(const char *tokenEnd)
Definition: swbuf.h:47
const char * getName() const
Definition: utilxml.h:58
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
void setTokenCaseSensitive(bool val)
bool renderNoteNumbers
Definition: gbfxhtml.h:34
bool substituteToken(SWBuf &buf, const char *token)
const VerseKey * vkey
Definition: swbasicfilter.h:44
virtual const char * getText() const
Definition: versekey.cpp:1242
MyUserData(const SWModule *module, const SWKey *key)
Definition: gbfxhtml.cpp:42
void setTokenStart(const char *tokenStart)
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
GBFXHTML()
Definition: gbfxhtml.cpp:48
virtual const char * getHeader() const
Definition: gbfxhtml.cpp:34
unsigned long size() const
Definition: swbuf.h:185
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
void addTokenSubstitute(const char *findString, const char *replaceString)
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: gbfxhtml.cpp:88
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
static const SWBuf encode(const char *urlText)
Definition: url.cpp:231