summaryrefslogtreecommitdiff
path: root/src/modules/filters/osisheadings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/filters/osisheadings.cpp')
-rw-r--r--src/modules/filters/osisheadings.cpp57
1 files changed, 45 insertions, 12 deletions
diff --git a/src/modules/filters/osisheadings.cpp b/src/modules/filters/osisheadings.cpp
index a072335..8872f24 100644
--- a/src/modules/filters/osisheadings.cpp
+++ b/src/modules/filters/osisheadings.cpp
@@ -2,9 +2,24 @@
*
*osisheadings - SWFilter descendant to hide or show headings
* in an OSIS module.
+ *
+ *
+ * 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 <stdio.h>
#include <osisheadings.h>
@@ -35,6 +50,9 @@ char OSISHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *mo
bool hide = false;
bool preverse = false;
bool withinTitle = false;
+ bool withinPreverseDiv = false;
+ SWBuf preverseDivID = "";
+ const char *pvDID = 0;
bool canonical = false;
SWBuf header;
int headerNum = 0;
@@ -56,27 +74,41 @@ char OSISHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *mo
}
if (*from == '>') { // process tokens
intoken = false;
-
- if (!strncmp(token.c_str(), "title", 5) || !strncmp(token.c_str(), "/title", 6)) {
- withinTitle = (!strnicmp(token.c_str(), "title", 5));
- tag = token;
+ tag = token;
+
+ // <title> </title> <div subType="x-preverse"> (</div> ## when in previous)
+ if ( (!withinPreverseDiv && !strcmp(tag.getName(), "title")) ||
+ (!strcmp(tag.getName(), "div") &&
+ ((withinPreverseDiv && (tag.isEndTag(pvDID))) ||
+ (tag.getAttribute("subType") && !strcmp(tag.getAttribute("subType"), "x-preverse")))
+ )) {
+
+ withinTitle = (!tag.isEndTag(pvDID));
+ if (!strcmp(tag.getName(), "div")) {
+ withinPreverseDiv = (!tag.isEndTag(pvDID));
+ if (!pvDID) {
+ preverseDivID = tag.getAttribute("sID");
+ pvDID = (preverseDivID.length())? preverseDivID.c_str() : 0;
+ }
+ }
- if (!tag.isEndTag()) { //start tag
- if (!tag.isEmpty()) {
+ if (!tag.isEndTag(pvDID)) { //start tag
+ if (!tag.isEmpty() || pvDID) {
startTag = tag;
}
}
- if ( (tag.getAttribute("subType") && !stricmp(tag.getAttribute("subType"), "x-preverse"))
- || (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse")) // deprecated
- ) {
+ if ( !tag.isEndTag(pvDID) && (withinPreverseDiv
+ || (tag.getAttribute("subType") && !stricmp(tag.getAttribute("subType"), "x-preverse"))
+ || (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse")) // deprecated
+ )) {
hide = true;
preverse = true;
header = "";
canonical = (tag.getAttribute("canonical") && (!stricmp(tag.getAttribute("canonical"), "true")));
continue;
}
- if (!tag.isEndTag()) { //start tag
+ if (!tag.isEndTag(pvDID)) { //start tag
hide = true;
header = "";
if (option || canonical) { // we want the tag in the text
@@ -86,7 +118,7 @@ char OSISHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *mo
}
continue;
}
- if (hide && tag.isEndTag()) {
+ if (hide && tag.isEndTag(pvDID)) {
if (module->isProcessEntryAttributes() && ((option || canonical) || (!preverse))) {
if (preverse) {
sprintf(buf, "%i", pvHeaderNum++);
@@ -112,6 +144,7 @@ char OSISHeadings::processText(SWBuf &text, const SWKey *key, const SWModule *mo
continue;
}
preverse = false;
+ pvDID = 0;
}
}