char OSISFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; bool hide = false; SWBuf tagText; XMLTag startTag; SWBuf refs = ""; int footnoteNum = 1; char buf[254]; SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; parser = new VerseKey(); } *parser = key->getText(); SWBuf orig = text; const char *from = orig.c_str(); XMLTag tag; bool strongsMarkup = false; for (text = ""; *from; ++from) { // remove all newlines temporarily to fix kjv2003 module if ((*from == 10) || (*from == 13)) { if ((text.length()>1) && (text[text.length()-2] != ' ') && (*(from+1) != ' ')) text.append(' '); continue; } if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; if (!strncmp(token, "note", 4) || !strncmp(token.c_str(), "/note", 5)) { tag = token; if (!tag.isEndTag()) { if (tag.getAttribute("type") && (!strcmp("x-strongsMarkup", tag.getAttribute("type")) || !strcmp("strongsMarkup", tag.getAttribute("type"))) // deprecated ) { tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... /> strongsMarkup = true; } if (!tag.isEmpty()) { // if ((!tag.isEmpty()) || (SWBuf("strongsMarkup") == tag.getAttribute("type"))) { refs = ""; startTag = tag; hide = true; tagText = ""; continue; } } if (hide && tag.isEndTag()) { if (module->isProcessEntryAttributes() && !strongsMarkup) { //don`t parse strongsMarkup to EntryAttributes as Footnote sprintf(buf, "%i", footnoteNum++); StringList attributes = startTag.getAttributeNames(); for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) { module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str()); } module->getEntryAttributes()["Footnote"][buf]["body"] = tagText; startTag.setAttribute("swordFootnote", buf); if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) { if (!refs.length()) refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } } hide = false; if (option || (startTag.getAttribute("type") && !strcmp(startTag.getAttribute("type"), "crossReference"))) { // we want the tag in the text; crossReferences are handled by another filter text.append(startTag); // text.append(tagText); // we don't put the body back in because it is retrievable from EntryAttributes["Footnotes"][]["body"]. } else continue; } strongsMarkup = false; } // if not a heading token, keep token in text //if ((!strcmp(tag.getName(), "reference")) && (!tag.isEndTag())) { // SWBuf osisRef = tag.getAttribute("osisRef"); if (!strncmp(token, "reference", 9)) { if (refs.length()) { refs.append("; "); } const char* attr = strstr(token.c_str() + 9, "osisRef=\""); const char* end = attr ? strchr(attr+9, '"') : 0; if (attr && end) { refs.append(attr+9, end-(attr+9)); } } if (!hide) { text.append('<'); text.append(token); text.append('>'); } else { tagText.append('<'); tagText.append(token); tagText.append('>'); } continue; } if (intoken) { //copy token token.append(*from); } else if (!hide) { //copy text which is not inside a token text.append(*from); } else tagText.append(*from); } delete parser; return 0; }
bool OSISHeadings::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { MyUserData *u = (MyUserData *)userData; XMLTag tag(token); SWBuf name = tag.getName(); // we only care about titles and divs or if we're already in a heading // // are we currently in a heading? if (u->currentHeadingName.size()) { u->heading.append(u->lastTextNode); if (name == u->currentHeadingName) { if (tag.isEndTag(u->sID)) { if (!u->depth-- || u->sID) { // see comment below about preverse div changed and needing to preserve the <title> container tag for old school pre-verse titles // we've just finished a heading. It's all stored up in u->heading bool canonical = (SWBuf("true") == u->currentHeadingTag.getAttribute("canonical")); bool preverse = (SWBuf("x-preverse") == u->currentHeadingTag.getAttribute("subType") || SWBuf("x-preverse") == u->currentHeadingTag.getAttribute("subtype")); // do we want to put anything in EntryAttributes? if (u->module->isProcessEntryAttributes() && (option || canonical || !preverse)) { SWBuf buf; buf.appendFormatted("%i", u->headerNum++); // leave the actual <title...> wrapper in if we're part of an old school preverse title // because now frontend have to deal with preverse as a div which may or may not include <title> elements // and they can't simply wrap all preverse material in <h1>, like they probably did previously SWBuf heading; if (u->currentHeadingName == "title") { XMLTag wrapper = u->currentHeadingTag; if (SWBuf("x-preverse") == wrapper.getAttribute("subType")) wrapper.setAttribute("subType", 0); else if (SWBuf("x-preverse") == wrapper.getAttribute("subtype")) wrapper.setAttribute("subtype", 0); heading = wrapper; heading += u->heading; heading += tag; } else heading = u->heading; u->module->getEntryAttributes()["Heading"][(preverse)?"Preverse":"Interverse"][buf] = heading; StringList attributes = u->currentHeadingTag.getAttributeNames(); for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) { u->module->getEntryAttributes()["Heading"][buf][it->c_str()] = u->currentHeadingTag.getAttribute(it->c_str()); } } // do we want the heading in the body? if (!preverse && (option || canonical)) { buf.append(u->currentHeadingTag); buf.append(u->heading); buf.append(tag); } u->suspendTextPassThru = false; u->clear(); } } else u->depth++; } u->heading.append(tag); return true; } // are we a title or a preverse div? else if ( name == "title" || (name == "div" && ( SWBuf("x-preverse") == tag.getAttribute("subType") || SWBuf("x-preverse") == tag.getAttribute("subtype")))) { u->currentHeadingName = name; u->currentHeadingTag = tag; u->heading = ""; u->sID = u->currentHeadingTag.getAttribute("sID"); u->depth = 0; u->suspendTextPassThru = true; return true; } return false; }
char ThMLFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) { SWBuf token; bool intoken = false; bool hide = false; SWBuf tagText; XMLTag startTag; SWBuf refs = ""; int footnoteNum = 1; char buf[254]; SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; parser = new VerseKey(); } *parser = key->getText(); SWBuf orig = text; const char *from = orig.c_str(); for (text = ""; *from; from++) { if (*from == '<') { intoken = true; token = ""; continue; } if (*from == '>') { // process tokens intoken = false; XMLTag tag(token); if (!strcmp(tag.getName(), "note")) { if (!tag.isEndTag()) { if (!tag.isEmpty()) { refs = ""; startTag = tag; hide = true; tagText = ""; continue; } } if (hide && tag.isEndTag()) { if (module->isProcessEntryAttributes()) { SWBuf fc = module->getEntryAttributes()["Footnote"]["count"]["value"]; footnoteNum = (fc.length()) ? atoi(fc.c_str()) : 0; sprintf(buf, "%i", ++footnoteNum); module->getEntryAttributes()["Footnote"]["count"]["value"] = buf; StringList attributes = startTag.getAttributeNames(); for (StringList::iterator it = attributes.begin(); it != attributes.end(); it++) { module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str()); } module->getEntryAttributes()["Footnote"][buf]["body"] = tagText; startTag.setAttribute("swordFootnote", buf); if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) { if (!refs.length()) refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText(); module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); } } hide = false; if ((option) || ((startTag.getAttribute("type") && (!strcmp(startTag.getAttribute("type"), "crossReference"))))) { // we want the tag in the text; crossReferences are handled by another filter text += startTag; text.append(tagText); } else continue; } } // if not a note token, keep token in text if ((!strcmp(tag.getName(), "scripRef")) && (!tag.isEndTag())) { SWBuf osisRef = tag.getAttribute("passage"); if (refs.length()) refs += "; "; refs += osisRef; } if (!hide) { text += '<'; text.append(token); text += '>'; } else { tagText += '<'; tagText.append(token); tagText += '>'; } continue; } if (intoken) { //copy token token += *from; } else if (!hide) { //copy text which is not inside a token text += *from; } else tagText += *from; } delete parser; return 0; }
char GBFFootnotes::processText (std::string &text, const SWKey *key, const SWModule *module) { (void) key; std::string token; bool intoken = false; bool hide = false; std::string tagText; XMLTag startTag; std::string refs = ""; int footnoteNum = 1; char buf[254]; std::string 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; //XMLTag tag(token); if (!std::strncmp(token.c_str(), "RF",2)) { // tag = token; refs = ""; startTag = token.c_str(); hide = true; tagText = ""; continue; } else if (!std::strncmp(token.c_str(), "Rf",2)) { if (module->isProcessEntryAttributes()) { //tag = token; if((tagText.length() == 1) || (module->getName() == "IGNT")) { if (option) { // for ASV marks text in verse then put explanation at end of verse text.append(" <FS>["); text.append(tagText); text.append("]<Fs>"); hide = false; continue; } } std::string fc = module->getEntryAttributes()["Footnote"]["count"]["value"]; footnoteNum = (fc.length()) ? std::atoi(fc.c_str()) : 0; sprintf(buf, "%i", ++footnoteNum); module->getEntryAttributes()["Footnote"]["count"]["value"] = buf; for (auto const & attr : startTag.attributeNames()) module->getEntryAttributes()["Footnote"][buf][attr.c_str()] = startTag.attribute(attr.c_str()); module->getEntryAttributes()["Footnote"][buf]["body"] = tagText; startTag.setAttribute("swordFootnote", buf); } hide = false; if (option) { text.append(startTag.toString()); text.append(tagText); } else continue; } if (!hide) { text.push_back('<'); text.append(token); text.push_back('>'); } else { tagText.push_back('<'); tagText.append(token); tagText.push_back('>'); } continue; } if (intoken) { //copy token token.push_back(*from); } else if (!hide) { //copy text which is not inside a token text.push_back(*from); } else tagText.push_back(*from); } return 0; /* if (!option) { // if we don't want footnotes char token[4096]; // cheese. Fix. int tokpos = 0; bool intoken = false; int len; bool hide = false; const char *from; std::string orig = text; from = orig.c_str(); for (text = ""; *from; from++) { if (*from == '<') { intoken = true; tokpos = 0; // std::memset(token, 0, 4096); token[0] = 0; token[1] = 0; token[2] = 0; continue; } if (*from == '>') { // process tokens intoken = false; switch (*token) { case 'R': // Reference switch(token[1]) { case 'F': // Begin footnote hide = true; break; case 'f': // end footnote hide = false; break; } continue; // skip token case 'W': if (token[1] == 'T') { switch (token[2]) { case 'P': case 'S': case 'A': continue; // remove this token default: break; } } } // if not a footnote token, keep token in text if (!hide) { text += '<'; text += token; text += '>'; } continue; } if (intoken) { if (tokpos < 4090) token[tokpos++] = *from; token[tokpos+2] = 0; // +2 cuz we init token with 2 extra '0' because of switch statement } else { if (!hide) { text += *from; } } } } return 0;*/ }