[sword-svn] r1906 - trunk/src/modules/filters

scribe at crosswire.org scribe at crosswire.org
Wed Apr 19 13:03:44 MST 2006


Author: scribe
Date: 2006-04-19 13:03:42 -0700 (Wed, 19 Apr 2006)
New Revision: 1906

Modified:
   trunk/src/modules/filters/thmlheadings.cpp
Log:
Added fix for adding ThMLHeadings into entry attributes (thanks _mg_)


Modified: trunk/src/modules/filters/thmlheadings.cpp
===================================================================
--- trunk/src/modules/filters/thmlheadings.cpp	2006-04-15 22:35:29 UTC (rev 1905)
+++ trunk/src/modules/filters/thmlheadings.cpp	2006-04-19 20:03:42 UTC (rev 1906)
@@ -9,6 +9,7 @@
 #include <thmlheadings.h>
 #include <utilxml.h>
 #include <utilstr.h>
+#include <swmodule.h>
 
 SWORD_NAMESPACE_START
 
@@ -28,63 +29,110 @@
 
 
 char ThMLHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
-	if (!option) {	// if we don't want headings
-		SWBuf token;
-		bool intoken = false;
-		bool hide = false;
+	SWBuf token;
+	bool intoken    = false;
+	bool hide       = false;
+	bool preverse   = false;
+	SWBuf header;
+	int headerNum   = 0;
+	int pvHeaderNum = 0;
+	char buf[254];
+	XMLTag startTag;
 
-		SWBuf orig = text;
-		const char *from = orig.c_str();
+	SWBuf orig = text;
+	const char *from = orig.c_str();
+	
+	XMLTag tag;
 
-		for (text = ""; *from; from++) {
-			if (*from == '<') {
-				intoken = true;
-				token = "";
-				continue;
-			}
-			if (*from == '>') {	// process tokens
-				intoken = false;
+	for (text = ""; *from; ++from) {
+		if (*from == '<') {
+			intoken = true;
+			token = "";
+			
+			continue;
+		}
+		if (*from == '>') {	// process tokens
+			intoken = false;
 
-				XMLTag tag(token);
-
-				if (!stricmp(tag.getName(), "div")) { //we only want a div tag
-					//std::cout << tag.toString() << " " << tag.isEndTag() << std::endl;
-
-					if (tag.getAttribute("class") && !stricmp(tag.getAttribute("class"), "sechead")) {
-						hide = true;
+			if (!strnicmp(token.c_str(), "div", 3) || !strnicmp(token.c_str(), "/div", 4)) {
+				tag = token;
+				if (hide && tag.isEndTag()) {
+					if (module->isProcessEntryAttributes() && (option || (!preverse))) {
+						if (preverse) {
+							sprintf(buf, "%i", pvHeaderNum++);
+							module->getEntryAttributes()["Heading"]["Preverse"][buf] = header;
+						}
+						else {
+							sprintf(buf, "%i", headerNum++);
+							module->getEntryAttributes()["Heading"]["Interverse"][buf] = header;
+							if (option) {	// we want the tag in the text
+								text.append(header);
+							}
+						}
+						
+						StringList attributes = startTag.getAttributeNames();
+						for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) {
+							module->getEntryAttributes()["Heading"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
+						}
+					}
+					
+					hide = false;
+					if (!option || preverse) {	// we don't want the tag in the text anymore
+						preverse = false;
 						continue;
 					}
-
-					if (tag.getAttribute("class") && !stricmp(tag.getAttribute("class"), "title")) {
+					preverse = false;
+				}
+				if (tag.getAttribute("class") && ((!stricmp(tag.getAttribute("class"), "sechead"))
+										 ||  (!stricmp(tag.getAttribute("class"), "title")))) {
+					
+					if (!tag.isEndTag()) { //start tag
+						if (!tag.isEmpty()) {
+							startTag = tag;
+					
+/* how do we tell a ThML preverse title from one that should be in the text?  probably if any text is before the title...  just assuming all are preverse for now
+					}
+					if (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse")) {
+*/
 						hide = true;
+						preverse = true;
+						header = "";
 						continue;
+						}	// move back up under startTag = tag
 					}
-
-					if (hide && tag.isEndTag()) {
-						hide = false;
+/* this is where non-preverse will go eventually
+					if (!tag.isEndTag()) { //start tag
+						hide = true;
+						header = "";
+						if (option) {	// we want the tag in the text
+							text.append('<');
+							text.append(token);
+							text.append('>');
+						}
 						continue;
 					}
-
+*/
 				}
-
-				// if not a heading token, keep token in text
-				if (!hide) {
-					text += '<';
-					text += token;
-					text += '>';
-				}
-				continue;
 			}
 
-			if (intoken) { //copy token
-				token += *from;
+			// if not a heading token, keep token in text
+			if (!hide) {
+				text.append('<');
+				text.append(token);
+				text.append('>');
 			}
-			else if (!hide) { //copy text which is not inside a token
-				text += *from;
-			}
+			continue;
 		}
+		if (intoken) { //copy token
+			token.append(*from);
+		}
+		else if (!hide) { //copy text which is not inside a token
+			text.append(*from);
+		}
+		else header.append(*from);
 	}
 	return 0;
 }
 
+
 SWORD_NAMESPACE_END



More information about the sword-cvs mailing list