diff options
Diffstat (limited to 'src/modules/filters/osishtmlhref.cpp')
-rw-r--r-- | src/modules/filters/osishtmlhref.cpp | 157 |
1 files changed, 78 insertions, 79 deletions
diff --git a/src/modules/filters/osishtmlhref.cpp b/src/modules/filters/osishtmlhref.cpp index 3406e1b..74b2da7 100644 --- a/src/modules/filters/osishtmlhref.cpp +++ b/src/modules/filters/osishtmlhref.cpp @@ -1,11 +1,10 @@ /*************************************************************************** - * osishtmlhref.cpp - OSIS to HTML with hrefs filter - * ------------------- - * begin : 2003-06-24 - * copyright : 2003 by CrossWire Bible Society + * + * osishtmlhref.cpp - OSIS to HTML with hrefs filter * + * $Id: osishtmlhref.cpp 3005 2014-01-09 04:06:11Z greg.hellings $ * - * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -36,60 +35,6 @@ SWORD_NAMESPACE_START namespace { typedef std::stack<SWBuf> TagStack; -} - -// TODO: this bridge pattern is to preserve binary compat on 1.6.x -class OSISHTMLHREF::TagStacks { -public: - TagStack quoteStack; - TagStack hiStack; -}; - -OSISHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { - inXRefNote = false; - suspendLevel = 0; - tagStacks = new TagStacks(); - wordsOfChristStart = "<font color=\"red\"> "; - wordsOfChristEnd = "</font> "; - if (module) { - osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false"))); - version = module->Name(); - BiblicalText = (!strcmp(module->Type(), "Biblical Texts")); - } - else { - osisQToTick = true; // default - version = ""; - } -} - -OSISHTMLHREF::MyUserData::~MyUserData() { - delete tagStacks; -} - -OSISHTMLHREF::OSISHTMLHREF() { - setTokenStart("<"); - setTokenEnd(">"); - - setEscapeStart("&"); - setEscapeEnd(";"); - - setEscapeStringCaseSensitive(true); - setPassThruNumericEscapeString(true); - - addAllowedEscapeString("quot"); - addAllowedEscapeString("apos"); - addAllowedEscapeString("amp"); - addAllowedEscapeString("lt"); - addAllowedEscapeString("gt"); - - setTokenCaseSensitive(true); - - // addTokenSubstitute("lg", "<br />"); - // addTokenSubstitute("/lg", "<br />"); - - morphFirst = false; -} - // though this might be slightly slower, possibly causing an extra bool check, this is a renderFilter // so speed isn't the absolute highest priority, and this is a very minor possible hit static inline void outText(const char *t, SWBuf &o, BasicFilterUserData *u) { if (!u->suspendTextPassThru) o += t; else u->lastSuspendSegment += t; } @@ -157,6 +102,61 @@ void processMorph(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf) { //} } } +} // end anonymous namespace + +// TODO: this bridge pattern is to preserve binary compat on 1.6.x +class OSISHTMLHREF::TagStacks { +public: + TagStack quoteStack; + TagStack hiStack; +}; + +OSISHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) { + inXRefNote = false; + suspendLevel = 0; + tagStacks = new TagStacks(); + wordsOfChristStart = "<font color=\"red\"> "; + wordsOfChristEnd = "</font> "; + if (module) { + osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false"))); + version = module->getName(); + BiblicalText = (!strcmp(module->getType(), "Biblical Texts")); + } + else { + osisQToTick = true; // default + version = ""; + } +} + +OSISHTMLHREF::MyUserData::~MyUserData() { + delete tagStacks; +} + +OSISHTMLHREF::OSISHTMLHREF() { + setTokenStart("<"); + setTokenEnd(">"); + + setEscapeStart("&"); + setEscapeEnd(";"); + + setEscapeStringCaseSensitive(true); + setPassThruNumericEscapeString(true); + + addAllowedEscapeString("quot"); + addAllowedEscapeString("apos"); + addAllowedEscapeString("amp"); + addAllowedEscapeString("lt"); + addAllowedEscapeString("gt"); + + setTokenCaseSensitive(true); + + // addTokenSubstitute("lg", "<br />"); + // addTokenSubstitute("/lg", "<br />"); + + morphFirst = false; + renderNoteNumbers = false; +} + bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { MyUserData *u = (MyUserData *)userData; @@ -240,6 +240,7 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat if (!strongsMarkup) { // leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); + SWBuf noteName = tag.getAttribute("n"); VerseKey *vkey = NULL; char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n'); @@ -251,25 +252,14 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat vkey = SWDYNAMIC_CAST(VerseKey, u->key); } SWCATCH ( ... ) { } - if (vkey) { - //printf("URL = %s\n",URL::encode(vkey->getText()).c_str()); - buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c</sup></small></a>", - ch, - URL::encode(footnoteNumber.c_str()).c_str(), - URL::encode(u->version.c_str()).c_str(), - URL::encode(vkey->getText()).c_str(), - ch, - ch); - } - else { - buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c</sup></small></a>", - ch, - URL::encode(footnoteNumber.c_str()).c_str(), - URL::encode(u->version.c_str()).c_str(), - URL::encode(u->key->getText()).c_str(), - ch, - ch); - } + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c%s</sup></small></a>", + ch, + URL::encode(footnoteNumber.c_str()).c_str(), + URL::encode(u->version.c_str()).c_str(), + URL::encode(vkey ? vkey->getText() : u->key->getText()).c_str(), + ch, + ch, + (renderNoteNumbers ? noteName.c_str() : "")); } } u->suspendTextPassThru = (++u->suspendLevel); @@ -381,7 +371,7 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat } // <lb.../> - else if (!strcmp(tag.getName(), "lb")) { + else if (!strcmp(tag.getName(), "lb") && (!tag.getAttribute("type") || strcmp(tag.getAttribute("type"), "x-optional"))) { outText("<br />", buf, u); userData->supressAdjacentWhitespace = true; } @@ -485,10 +475,15 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat // <hi> text highlighting else if (!strcmp(tag.getName(), "hi")) { SWBuf type = tag.getAttribute("type"); + // handle tei rend attribute + if (!type.length()) type = tag.getAttribute("rend"); if ((!tag.isEndTag()) && (!tag.isEmpty())) { if (type == "bold" || type == "b" || type == "x-b") { outText("<b>", buf, u); } + else if (type == "ol") { + outText("<span style=\"text-decoration:overline\">", buf, u); + } else { // all other types outText("<i>", buf, u); } @@ -500,10 +495,14 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat XMLTag tag(u->tagStacks->hiStack.top()); u->tagStacks->hiStack.pop(); type = tag.getAttribute("type"); + if (!type.length()) type = tag.getAttribute("rend"); } if (type == "bold" || type == "b" || type == "x-b") { outText("</b>", buf, u); } + else if (type == "ol") { + outText("</span>", buf, u); + } else outText("</i>", buf, u); } } |