[sword-svn] r2155 - in trunk: include lib/bcppmake src/mgr src/modules/filters
chrislit at www.crosswire.org
chrislit at www.crosswire.org
Mon May 12 15:09:43 MST 2008
Author: chrislit
Date: 2008-05-12 15:09:43 -0700 (Mon, 12 May 2008)
New Revision: 2155
Added:
trunk/include/teihtmlhref.h
trunk/src/modules/filters/teihtmlhref.cpp
Modified:
trunk/lib/bcppmake/libsword.bpf
trunk/lib/bcppmake/libsword.bpr
trunk/src/mgr/markupfiltmgr.cpp
trunk/src/modules/filters/Makefile.am
Log:
Applied Ben Morgan's TEIHTMLHREF filter
added TEIHTMLHREF filter to BCB5 project
Added: trunk/include/teihtmlhref.h
===================================================================
--- trunk/include/teihtmlhref.h (rev 0)
+++ trunk/include/teihtmlhref.h 2008-05-12 22:09:43 UTC (rev 2155)
@@ -0,0 +1,51 @@
+/******************************************************************************
+ *
+ * $Id:
+ *
+ * Copyright 1998 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.
+ *
+ */
+
+#ifndef TEIHTMLHREF_H
+#define TEIHTMLHREF_H
+
+#include <swbasicfilter.h>
+
+SWORD_NAMESPACE_START
+
+/** this filter converts TEI text to HTMLHREF text
+ */
+class SWDLLEXPORT TEIHTMLHREF : public SWBasicFilter {
+private:
+
+protected:
+ class MyUserData : public BasicFilterUserData {
+ public:
+ bool BiblicalText;
+ SWBuf lastHi;
+
+ SWBuf version;
+ MyUserData(const SWModule *module, const SWKey *key);
+ };
+ virtual BasicFilterUserData *createUserData(const SWModule *module, const SWKey *key) {
+ return new MyUserData(module, key);
+ }
+ virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
+public:
+ TEIHTMLHREF();
+};
+
+SWORD_NAMESPACE_END
+#endif
Modified: trunk/lib/bcppmake/libsword.bpf
===================================================================
--- trunk/lib/bcppmake/libsword.bpf 2008-05-12 21:31:57 UTC (rev 2154)
+++ trunk/lib/bcppmake/libsword.bpf 2008-05-12 22:09:43 UTC (rev 2155)
@@ -148,6 +148,7 @@
USEUNIT("..\..\src\modules\texts\rawtext4\rawtext4.cpp");
USEUNIT("..\..\src\modules\comments\rawcom4\rawcom4.cpp");
USEUNIT("..\..\src\modules\common\rawverse4.cpp");
+USEUNIT("..\..\src\modules\filters\teihtmlhref.cpp");
//---------------------------------------------------------------------------
#define Library
Modified: trunk/lib/bcppmake/libsword.bpr
===================================================================
--- trunk/lib/bcppmake/libsword.bpr 2008-05-12 21:31:57 UTC (rev 2154)
+++ trunk/lib/bcppmake/libsword.bpr 2008-05-12 22:09:43 UTC (rev 2155)
@@ -117,7 +117,8 @@
..\..\src\modules\filters\teirtf.obj
..\..\src\modules\texts\rawtext4\rawtext4.obj
..\..\src\modules\comments\rawcom4\rawcom4.obj
- ..\..\src\modules\common\rawverse4.obj"/>
+ ..\..\src\modules\common\rawverse4.obj
+ ..\..\src\modules\filters\teihtmlhref.obj"/>
<RESFILES value=""/>
<IDLFILES value=""/>
<IDLGENFILES value=""/>
@@ -297,4 +298,4 @@
ProjectLang=
RootDir=
</IDEOPTIONS>
-</PROJECT>
+</PROJECT>
\ No newline at end of file
Modified: trunk/src/mgr/markupfiltmgr.cpp
===================================================================
--- trunk/src/mgr/markupfiltmgr.cpp 2008-05-12 21:31:57 UTC (rev 2154)
+++ trunk/src/mgr/markupfiltmgr.cpp 2008-05-12 22:09:43 UTC (rev 2155)
@@ -30,6 +30,7 @@
#include <plainhtml.h>
#include <thmlhtmlhref.h>
#include <gbfhtmlhref.h>
+#include <teihtmlhref.h>
#include <thmlrtf.h>
#include <gbfrtf.h>
#include <gbfosis.h>
@@ -257,7 +258,7 @@
fromthml = new ThMLHTMLHREF();
fromgbf = new GBFHTMLHREF();
fromosis = new OSISHTMLHREF();
- fromtei = NULL;
+ fromtei = new TEIHTMLHREF();
break;
case FMT_RTF:
fromplain = NULL;
Modified: trunk/src/modules/filters/Makefile.am
===================================================================
--- trunk/src/modules/filters/Makefile.am 2008-05-12 21:31:57 UTC (rev 2154)
+++ trunk/src/modules/filters/Makefile.am 2008-05-12 22:09:43 UTC (rev 2155)
@@ -31,6 +31,7 @@
TEIFIL = $(filtersdir)/teiplain.cpp
TEIFIL += $(filtersdir)/teirtf.cpp
+TEIFIL += $(filtersdir)/teihtmlhref.cpp
CONVFIL = $(filtersdir)/gbfthml.cpp
CONVFIL += $(filtersdir)/gbfosis.cpp
Added: trunk/src/modules/filters/teihtmlhref.cpp
===================================================================
--- trunk/src/modules/filters/teihtmlhref.cpp (rev 0)
+++ trunk/src/modules/filters/teihtmlhref.cpp 2008-05-12 22:09:43 UTC (rev 2155)
@@ -0,0 +1,205 @@
+/***************************************************************************
+ teirtf.cpp - TEI to HTMLHREF filter
+ -------------------
+ begin : 2006-07-03
+ copyright : 2006 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; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <teihtmlhref.h>
+#include <utilxml.h>
+#include <swmodule.h>
+#include <url.h>
+
+
+SWORD_NAMESPACE_START
+
+
+TEIHTMLHREF::MyUserData::MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {
+ BiblicalText = false;
+ if (module) {
+ version = module->Name();
+ BiblicalText = (!strcmp(module->Type(), "Biblical Texts"));
+ }
+}
+
+
+TEIHTMLHREF::TEIHTMLHREF() {
+ setTokenStart("<");
+ setTokenEnd(">");
+
+ setEscapeStart("&");
+ setEscapeEnd(";");
+
+ setEscapeStringCaseSensitive(true);
+
+ addAllowedEscapeString("quot");
+ addAllowedEscapeString("apos");
+ addAllowedEscapeString("amp");
+ addAllowedEscapeString("lt");
+ addAllowedEscapeString("gt");
+
+ setTokenCaseSensitive(true);
+}
+
+bool TEIHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
+ // manually process if it wasn't a simple substitution
+ if (!substituteToken(buf, token)) {
+ MyUserData *u = (MyUserData *)userData;
+ XMLTag tag(token);
+
+ if (!strcmp(tag.getName(), "p")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
+ buf += "<!P><br />";
+ }
+ else if (tag.isEndTag()) { // end tag
+ buf += "<!/P><br />";
+ //userData->supressAdjacentWhitespace = true;
+ }
+ else { // empty paragraph break marker
+ buf += "<!P><br />";
+ //userData->supressAdjacentWhitespace = true;
+ }
+ }
+
+ // <hi>
+ else if (!strcmp(tag.getName(), "hi")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ SWBuf rend = tag.getAttribute("rend");
+
+ u->lastHi = rend;
+ if (rend == "ital")
+ buf += "<i>";
+ else if (rend == "bold")
+ buf += "<b>";
+ else if (rend == "sup")
+ buf += "<small><sup>";
+
+ }
+ else if (tag.isEndTag()) {
+ SWBuf rend = u->lastHi;
+ if (rend == "ital")
+ buf += "</i>";
+ else if (rend == "bold")
+ buf += "</b>";
+ else if (rend == "sup")
+ buf += "</sup></small>";
+ }
+ }
+
+ // <entryFree>
+ else if (!strcmp(tag.getName(), "entryFree")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ SWBuf n = tag.getAttribute("n");
+ if (n != "") {
+ buf += "<b>";
+ buf += n;
+ buf += "</b>";
+ }
+ }
+ }
+
+ // <sense>
+ else if (!strcmp(tag.getName(), "sense")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ SWBuf n = tag.getAttribute("n");
+ if (n != "") {
+ buf += "<br /><b>";
+ buf += n;
+ buf += "</b>";
+ }
+ }
+ }
+
+ // <div>
+ else if (!strcmp(tag.getName(), "div")) {
+
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "<!P>";
+ }
+ else if (tag.isEndTag()) {
+ }
+ }
+
+ // <pos>, <gen>, <case>, <gram>, <number>, <mood>, <pron>, <def>
+ else if (!strcmp(tag.getName(), "pos") ||
+ !strcmp(tag.getName(), "gen") ||
+ !strcmp(tag.getName(), "case") ||
+ !strcmp(tag.getName(), "gram") ||
+ !strcmp(tag.getName(), "number") ||
+ !strcmp(tag.getName(), "pron") ||
+ !strcmp(tag.getName(), "def")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "<i>";
+ }
+ else if (tag.isEndTag()) {
+ buf += "</i>";
+ }
+ }
+
+ // <tr>
+ else if (!strcmp(tag.getName(), "tr")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "<i>";
+ }
+ else if (tag.isEndTag()) {
+ buf += "</i>";
+ }
+ }
+
+ // orth
+ else if (!strcmp(tag.getName(), "orth")) {
+ if ((!tag.isEndTag()) && (!tag.isEmpty())) {
+ buf += "<b>";
+ }
+ else if (tag.isEndTag()) {
+ buf += "</b>";
+ }
+ }
+
+ // <etym>, <usg>
+ else if (!strcmp(tag.getName(), "etym") ||
+ !strcmp(tag.getName(), "usg")) {
+ // do nothing here
+ }
+
+ // <note> tag
+ else if (!strcmp(tag.getName(), "note")) {
+ if (!tag.isEndTag()) {
+ if (!tag.isEmpty()) {
+ u->suspendTextPassThru = true;
+ }
+ }
+ if (tag.isEndTag()) {
+ SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
+
+ buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup>*n</sup></small></a>",
+ URL::encode(footnoteNumber.c_str()).c_str(),
+ URL::encode(u->version.c_str()).c_str(),
+ URL::encode(u->key->getText()).c_str());
+
+ u->suspendTextPassThru = false;
+ }
+ }
+
+ else {
+ return false; // we still didn't handle token
+ }
+
+ }
+ return true;
+}
+
+
+SWORD_NAMESPACE_END
+
More information about the sword-cvs
mailing list