diff options
Diffstat (limited to 'src/modules/filters/osishtmlhref.cpp')
-rw-r--r-- | src/modules/filters/osishtmlhref.cpp | 165 |
1 files changed, 112 insertions, 53 deletions
diff --git a/src/modules/filters/osishtmlhref.cpp b/src/modules/filters/osishtmlhref.cpp index fe3e058..6fce987 100644 --- a/src/modules/filters/osishtmlhref.cpp +++ b/src/modules/filters/osishtmlhref.cpp @@ -1,17 +1,25 @@ /*************************************************************************** - osishtmlhref.cpp - OSIS to HTML with hrefs filter - ------------------- - begin : 2003-06-24 - copyright : 2003 by CrossWire Bible Society - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation version 2 of the License. * - * * - ***************************************************************************/ + * osishtmlhref.cpp - OSIS to HTML with hrefs filter + * ------------------- + * begin : 2003-06-24 + * copyright : 2003 by CrossWire Bible Society + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ #include <stdlib.h> #include <ctype.h> @@ -111,7 +119,7 @@ void processLemma(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf) { if (!suspendTextPassThru) { buf.appendFormatted("<small><em><<a href=\"passagestudy.jsp?action=showStrongs&type=%s&value=%s\">%s</a>></em></small>", (gh.length()) ? gh.c_str() : "", - URL::encode(val2).c_str(), + URL::encode(val2).c_str(), val2); } //} @@ -188,8 +196,9 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat if ((attrib = tag.getAttribute("gloss"))) { val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; - outText(" ", buf, u); + outText("(", buf, u); outText(val, buf, u); + outText(")", buf, u); } if (!morphFirst) { processLemma(u->suspendTextPassThru, tag, buf); @@ -278,49 +287,71 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat } } + // Milestoned paragraphs, created by osis2mod + // <div type="paragraph" sID.../> + // <div type="paragraph" eID.../> + else if (tag.isEmpty() && !strcmp(tag.getName(), "div") && tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "paragraph")) { + // <div type="paragraph" sID... /> + if (tag.getAttribute("sID")) { // non-empty start tag + outText("<!P><br />", buf, u); + } + // <div type="paragraph" eID... /> + else if (tag.getAttribute("eID")) { + outText("<!/P><br />", buf, u); + userData->supressAdjacentWhitespace = true; + } + } + // <reference> tag else if (!strcmp(tag.getName(), "reference")) { if (!u->inXRefNote) { // only show these if we're not in an xref note - if ((!tag.isEndTag()) && (!tag.isEmpty())) { - u->suspendTextPassThru = (++u->suspendLevel); - } - if (tag.isEndTag()) { - if (!u->BiblicalText) { - SWBuf refList = tag.getAttribute("passage"); - if (!refList.length()) - refList = u->lastTextNode; - SWBuf version = tag.getAttribute("version"); - - buf.appendFormatted(" <a href=\"passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=%s\">", - (refList.length()) ? URL::encode(refList.c_str()).c_str() : "", - (version.length()) ? URL::encode(version.c_str()).c_str() : ""); - buf += u->lastTextNode.c_str(); - buf += "</a> "; + if (!tag.isEndTag()) { + SWBuf target; + SWBuf work; + SWBuf ref; + bool is_scripRef = false; + + target = tag.getAttribute("osisRef"); + const char* the_ref = strchr(target, ':'); + + if(!the_ref) { + // No work + ref = target; + is_scripRef = true; } else { - SWBuf footnoteNumber = tag.getAttribute("swordFootnote"); - VerseKey *vkey = NULL; - // see if we have a VerseKey * or descendant - SWTRY { - vkey = SWDYNAMIC_CAST(VerseKey, u->key); - } - SWCATCH ( ... ) {} - if (vkey) { - // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt. - //buf.appendFormatted("<a href=\"noteID=%s.x.%s\"><small><sup>*x</sup></small></a> ", vkey->getText(), footnoteNumber.c_str()); - buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=x&value=%s&module=%s&passage=%s\"><small><sup>*x</sup></small></a>", - URL::encode(footnoteNumber.c_str()).c_str(), - URL::encode(u->version.c_str()).c_str(), - URL::encode(vkey->getText()).c_str()); - - } + // Compensate for starting : + ref = the_ref + 1; + + int size = target.size() - ref.size() - 1; + work.setSize(size); + strncpy(work.getRawData(), target, size); + + // For Bible:Gen.3.15 or Bible.vulgate:Gen.3.15 + if(!strncmp(work, "Bible", 5)) + is_scripRef = true; + } + + if(is_scripRef) + { + buf.appendFormatted("<a href=\"passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=\">", + URL::encode(ref.c_str()).c_str() +// (work.size()) ? URL::encode(work.c_str()).c_str() : "") + ); + } + else + { + // Dictionary link, or something + buf.appendFormatted("<a href=\"sword://%s/%s\">", + URL::encode(work.c_str()).c_str(), + URL::encode(ref.c_str()).c_str() + ); } - u->suspendTextPassThru = (--u->suspendLevel); } - }/* - if (tag.isEndTag()) { - u->suspendTextPassThru = false; - }*/ + else { + outText("</a>", buf, u); + } + } } // <l> poetry, etc @@ -383,7 +414,26 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat outText("</b><br />", buf, u); } } + + // <list> + else if (!strcmp(tag.getName(), "list")) { + if((!tag.isEndTag()) && (!tag.isEmpty())) { + outText("<ul>", buf, u); + } + else if (tag.isEndTag()) { + outText("</ul>", buf, u); + } + } + // <item> + else if (!strcmp(tag.getName(), "item")) { + if((!tag.isEndTag()) && (!tag.isEmpty())) { + outText("<li>", buf, u); + } + else if (tag.isEndTag()) { + outText("</li>", buf, u); + } + } // <catchWord> & <rdg> tags (italicize) else if (!strcmp(tag.getName(), "rdg") || !strcmp(tag.getName(), "catchWord")) { if ((!tag.isEndTag()) && (!tag.isEmpty())) { @@ -405,6 +455,16 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat if (lastText.size()) { toupperstr(lastText); scratch.setFormatted("%c<font size=\"-1\">%s</font>", lastText[0], lastText.c_str()+1); + + const unsigned char *tmpBuf = (const unsigned char *)lastText.c_str(); + getUniCharFromUTF8(&tmpBuf); + int char_length = (tmpBuf - (const unsigned char *)lastText.c_str()); + scratch.setFormatted("%.*s<font size=\"-1\">%s</font>", + char_length, + lastText.c_str(), + lastText.c_str() + char_length + ); + outText(scratch.c_str(), buf, u); } } @@ -542,8 +602,7 @@ bool OSISHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserDat outText(URL::encode(u->version.c_str()).c_str(), buf, u); outText("\">", buf, u); -// we do this because BibleCS looks for this EXACT format for an image tag - outText("<image border=0 src=\"", buf, u); + outText("<img border=\"0\" src=\"", buf, u); outText(filepath, buf, u); outText("\" />", buf, u); |