[sword-cvs] sword/src/modules/filters thmlfootnotes.cpp,1.13,1.14 thmlhtmlhref.cpp,1.40,1.41
sword@www.crosswire.org
sword@www.crosswire.org
Sun, 21 Dec 2003 03:42:03 -0700
Update of /usr/local/cvsroot/sword/src/modules/filters
In directory www:/tmp/cvs-serv1693/src/modules/filters
Modified Files:
thmlfootnotes.cpp thmlhtmlhref.cpp
Log Message:
updated the thml filters slightly, more work needs to be done on these!
Index: thmlfootnotes.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/filters/thmlfootnotes.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- thmlfootnotes.cpp 7 Jul 2003 01:16:15 -0000 1.13
+++ thmlfootnotes.cpp 21 Dec 2003 10:42:01 -0000 1.14
@@ -7,6 +7,10 @@
#include <stdlib.h>
#include <thmlfootnotes.h>
+#include <swmodule.h>
+#include <swbuf.h>
+#include <versekey.h>
+#include <utilxml.h>
#ifndef __GNUC__
#else
#include <unixstr.h>
@@ -30,45 +34,89 @@
char ThMLFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
- if (!option) { // if we don't want footnotes
- bool intoken = false;
- bool hide = false;
+ SWBuf token;
+ bool intoken = false;
+ bool hide = false;
+ SWBuf tagText;
+ XMLTag startTag;
+ SWBuf refs = "";
+ int footnoteNum = 1;
+ char buf[254];
+ VerseKey parser = key->getText();
- SWBuf token;
- SWBuf orig = text;
- const char *from = orig.c_str();
- for (text = ""; *from; from++) {
- if (*from == '<') {
- intoken = true;
- token = "";
- continue;
- }
- else if (*from == '>') { // process tokens
- intoken = false;
- if (!strncmp(token.c_str(), "note", 4)) {
- hide = true;
- continue;
+ SWBuf orig = text;
+ const char *from = orig.c_str();
+
+ for (text = ""; *from; from++) {
+ if (*from == '<') {
+ intoken = true;
+ token = "";
+ continue;
+ }
+ if (*from == '>') { // process tokens
+ intoken = false;
+
+ XMLTag tag(token);
+ if (!strcmp(tag.getName(), "note")) {
+ if (!tag.isEndTag()) {
+ if (!tag.isEmpty()) {
+ refs = "";
+ startTag = tag;
+ hide = true;
+ tagText = "";
+ continue;
+ }
}
- else if (!strncmp(token.c_str(), "/note", 5)) {
- hide = false;
- continue;
+ if (hide && tag.isEndTag()) {
+ if (module->isProcessEntryAttributes()) {
+ sprintf(buf, "%i", footnoteNum++);
+ StringList attributes = startTag.getAttributeNames();
+ for (StringList::iterator it = attributes.begin(); it != attributes.end(); it++) {
+ module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
+ }
+ module->getEntryAttributes()["Footnote"][buf]["body"] = tagText;
+ startTag.setAttribute("swordFootnote", buf);
+ if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) {
+ if (!refs.length())
+ refs = parser.ParseVerseList(tagText.c_str(), parser, true).getRangeText();
+ module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str();
+ }
+ }
+ hide = false;
+ if ((option) || ((startTag.getAttribute("type") && (!strcmp(startTag.getAttribute("type"), "crossReference"))))) { // we want the tag in the text; crossReferences are handled by another filter
+ text += startTag;
+ text.append(tagText);
+ }
+ else continue;
}
+ }
- // if not a footnote token, keep token in text
- if (!hide) {
- text += '<';
- text += token;
- text += '>';
- }
- continue;
+ // if not a note token, keep token in text
+ if ((!strcmp(tag.getName(), "scripRef")) && (!tag.isEndTag())) {
+ SWBuf osisRef = tag.getAttribute("passage");
+ if (refs.length())
+ refs += "; ";
+ refs += osisRef;
}
- if (intoken) {
- token += *from; //copy chars of found token
+ if (!hide) {
+ text += '<';
+ text.append(token);
+ text += '>';
}
- else if (!hide) {
- text += *from;
+ else {
+ tagText += '<';
+ tagText.append(token);
+ tagText += '>';
}
+ continue;
}
+ if (intoken) { //copy token
+ token += *from;
+ }
+ else if (!hide) { //copy text which is not inside a token
+ text += *from;
+ }
+ else tagText += *from;
}
return 0;
}
Index: thmlhtmlhref.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/filters/thmlhtmlhref.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- thmlhtmlhref.cpp 21 Dec 2003 01:34:29 -0000 1.40
+++ thmlhtmlhref.cpp 21 Dec 2003 10:42:01 -0000 1.41
@@ -18,16 +18,15 @@
#include <thmlhtmlhref.h>
#include <swmodule.h>
#include <utilxml.h>
+#include <versekey.h>
SWORD_NAMESPACE_START
ThMLHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {
- SWModule *vmodule;
- vmodule = (SWModule*) module;
- if(vmodule) {
- version = vmodule->Name();
- BiblicalText = (!strcmp(vmodule->Type(), "Biblical Texts"));
+ if (module) {
+ version = module->Name();
+ BiblicalText = (!strcmp(module->Type(), "Biblical Texts"));
}
}
@@ -47,7 +46,7 @@
MyUserData *u = (MyUserData *)userData;
XMLTag tag(token);
if (tag.getName() && !strcmp(tag.getName(), "sync")) {
- const char* value = tag.getAttribute("value");
+ SWBuf value = tag.getAttribute("value");
if( tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "morph")) { //>
buf += "<small><em>(<a href=\"";
buf += "type=";
@@ -55,9 +54,9 @@
//const char* value = tag.getAttribute("value");
buf += " value=";
- buf += value ? value : "";
+ buf += (value.length()) ? value : "";
buf += "\">";
- buf += value ? value : "";
+ buf += (value.length()) ? value : "";
buf += "</a>) </em></small>";
}
else if( tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "Strongs")) {
@@ -67,10 +66,10 @@
//const char* value = tag.getAttribute("value");
buf += " value=";
- buf += value ? value : "";
+ buf += (value.length()) ? value : "";
buf += "\">";
- value++;
- buf += value ? value : "";
+ value<<1;
+ buf += (value.length()) ? value : "";
buf += "</a>> </em></small>";
}
else if( tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "Dict")) {
@@ -80,28 +79,34 @@
buf += "</b>";
}
}
- else if (tag.getName() && !strcmp(tag.getName(), "note")) {
+ // <note> tag
+ else if (!strcmp(tag.getName(), "note")) {
+ if (!tag.isEndTag()) {
+ if (!tag.isEmpty()) {
+ SWBuf type = tag.getAttribute("type");
+ SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
+ VerseKey *vkey;
+ // see if we have a VerseKey * or descendant
+ try {
+ vkey = SWDYNAMIC_CAST(VerseKey, u->key);
+ }
+ catch ( ... ) { }
+ if (vkey) {
+ // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt.
+ char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
+ buf.appendFormatted("<a href=\"noteID=%s.%c.%s\"><small><sup>*%c</sup></small></a> ", vkey->getText(), ch, footnoteNumber.c_str(), ch);
+ }
+ u->suspendTextPassThru = true;
+ }
+ }
if (tag.isEndTag()) {
- buf += " <a href=\"note=";
- buf += u->lastTextNode.c_str();
- buf += "\">";
- buf += "<small><sup>*n</sup></small></a> ";
- // let's let text resume to output again
u->suspendTextPassThru = false;
}
- else {
- // let's stop text from going to output
- u->suspendTextPassThru = true;
- }
- }
- else if (tag.getName() && !strcmp(tag.getName(), "scripture")) {
- u->inscriptRef = true;
- buf += "<i>";
}
else if (tag.getName() && !strcmp(tag.getName(), "scripRef")) {
if (tag.isEndTag()) {
if (u->inscriptRef) { // like "<scripRef passage="John 3:16">John 3:16</scripRef>"
- if(u->BiblicalText)
+ if (u->BiblicalText)
buf += "<small><sup>*x</sup></small>";
buf += "</a> ";
u->inscriptRef = false;
@@ -109,16 +114,17 @@
}
else { // end of scripRef like "<scripRef>John 3:16</scripRef>"
buf += " <a href=\"";
- if(u->BiblicalText)
+ if (u->BiblicalText) {
if (u->version) {
buf += "version=";
buf += u->version;
buf += " ";
}
+ }
buf += "passage=";
buf += u->lastTextNode.c_str();
buf += "\">";
- if(u->BiblicalText)
+ if (u->BiblicalText)
buf += "<small><sup>*x</sup></small>";
else {
buf += u->lastTextNode.c_str();
@@ -132,23 +138,29 @@
u->inscriptRef = true;
buf += " <a href=\"";
- if (const char* version = tag.getAttribute("version")) {
+ SWBuf version = tag.getAttribute("version");
+ if (version.length()) {
buf += "version=";
buf += version;
buf += " ";
}
- if (const char* passage = tag.getAttribute("passage")) {
+ SWBuf passage = tag.getAttribute("passage");
+ if (passage.length()) {
buf += "passage=";
buf += passage;
}
buf += "\">";
- //u->suspendTextPassThru = true;
+ u->suspendTextPassThru = true;
}
else { //no passage or version given
u->inscriptRef = false;
// let's stop text from going to output
u->suspendTextPassThru = true;
}
+ }
+ else if (tag.getName() && !strcmp(tag.getName(), "scripture")) {
+ u->inscriptRef = true;
+ buf += "<i>";
}
else if (tag.getName() && !strcmp(tag.getName(), "div")) {
if (tag.isEndTag() && u->SecHead) {