void Filters::BT_OSISHTML::renderReference(const char *osisRef, sword::SWBuf &buf, sword::SWModule *myModule, BT_UserData *myUserData) { QString ref( osisRef ); QString hrefRef( ref ); //Q_ASSERT(!ref.isEmpty()); checked later if (!ref.isEmpty()) { //find out the mod, using the current module makes sense if it's a bible or commentary because the refs link into a bible by default. //If the osisRef is something like "ModuleID:key comes here" then the // modulename is given, so we'll use that one CSwordModuleInfo* mod = CPointers::backend()->findSwordModuleByPointer(myModule); //Q_ASSERT(mod); checked later if (!mod || (mod->type() != CSwordModuleInfo::Bible && mod->type() != CSwordModuleInfo::Commentary)) { mod = CBTConfig::get( CBTConfig::standardBible ); } // Q_ASSERT(mod); There's no necessarily a module or standard Bible //if the osisRef like "GerLut:key" contains a module, use that int pos = ref.indexOf(":"); if ((pos >= 0) && ref.at(pos-1).isLetter() && ref.at(pos+1).isLetter()) { QString newModuleName = ref.left(pos); hrefRef = ref.mid(pos+1); if (CPointers::backend()->findModuleByName(newModuleName)) { mod = CPointers::backend()->findModuleByName(newModuleName); } } if (mod) { CReferenceManager::ParseOptions options; options.refBase = QString::fromUtf8(myUserData->key->getText()); options.refDestinationModule = QString(mod->name()); options.sourceLanguage = QString(myModule->Lang()); options.destinationLanguage = QString("en"); buf.append("<a href=\""); buf.append( //create the hyperlink with key and mod CReferenceManager::encodeHyperlink( mod->name(), CReferenceManager::parseVerseReference(hrefRef, options), CReferenceManager::typeFromModule(mod->type()) ).toUtf8().constData() ); buf.append("\" crossrefs=\""); buf.append((const char*)CReferenceManager::parseVerseReference(ref, options).toUtf8().constData()); //ref must contain the osisRef module marker if there was any buf.append("\">"); } // should we add something if there were no referenced module available? } }
/** Prints a key using the hyperlink created by CReferenceManager. */ bool CExportManager::printByHyperlink( const QString& hyperlink, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions ) { QString moduleName; QString keyName; CReferenceManager::Type type; CReferenceManager::decodeHyperlink(hyperlink, moduleName, keyName, type); if (moduleName.isEmpty()) { moduleName = CReferenceManager::preferredModule(type); } CPrinter::KeyTree tree; CPrinter::KeyTreeItem::Settings settings; settings.keyRenderingFace = displayOptions.verseNumbers ? CPrinter::KeyTreeItem::Settings::SimpleKey : CPrinter::KeyTreeItem::Settings::NoKey; CSwordModuleInfo* module = backend()->findModuleByName(moduleName); Q_ASSERT(module); if (module) { //check if we have a range of entries or a single one if ((module->type() == CSwordModuleInfo::Bible) || (module->type() == CSwordModuleInfo::Commentary)) { sword::ListKey verses = sword::VerseKey().ParseVerseList((const char*)keyName.toUtf8(), "Genesis 1:1", true); for (int i = 0; i < verses.Count(); ++i) { sword::VerseKey* element = dynamic_cast<sword::VerseKey*>(verses.GetElement(i)); if (element) { const QString startKey = QString::fromUtf8(element->LowerBound().getText()); const QString stopKey = QString::fromUtf8(element->UpperBound().getText()); tree.append( new CPrinter::KeyTreeItem(startKey, stopKey, module, settings) ); } else if (verses.GetElement(i)) { const QString key = QString::fromUtf8(verses.GetElement(i)->getText()); tree.append( new CPrinter::KeyTreeItem(key, module, settings) ); } } } else { tree.append( new CPrinter::KeyTreeItem(keyName, module, settings) ); } } boost::scoped_ptr<CPrinter> printer(new CPrinter(0, displayOptions, filterOptions)); printer->printKeyTree(tree); return true; }
bool ModuleInterface::isLocked(const QString& moduleName) { CSwordModuleInfo* module = CSwordBackend::instance()->findModuleByName(moduleName); if (module) { // Verse intros must be false for checking lock if (module->type() == CSwordModuleInfo::Bible || module->type() == CSwordModuleInfo::Commentary) { ((sword::VerseKey*)(module->module()->getKey()))->setIntros(false); } bool locked = module->isLocked(); return locked; } return false; }
const QString Rendering::CChapterDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) { Q_ASSERT( modules.count() >= 1 ); Q_ASSERT( !keyName.isEmpty() ); CSwordModuleInfo* module = modules.first(); if (modules.count() == 1) module->module()->setSkipConsecutiveLinks( true ); //skip empty, linked verses CTextRendering::KeyTreeItem::Settings settings; settings.keyRenderingFace = displayOptions.verseNumbers ? CTextRendering::KeyTreeItem::Settings::SimpleKey : CTextRendering::KeyTreeItem::Settings::NoKey; QString startKey = keyName; QString endKey = startKey; //check whether there's an intro we have to include Q_ASSERT((module->type() == CSwordModuleInfo::Bible)); if (module->type() == CSwordModuleInfo::Bible) { ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys CSwordBibleModuleInfo* bible = dynamic_cast<CSwordBibleModuleInfo*>(module); Q_ASSERT(bible); CSwordVerseKey k1(module); k1.Headings(1); k1.key(keyName); if (k1.Chapter() == 1) k1.Chapter(0); //Chapter 1, start with 0:0, otherwise X:0 k1.Verse(0); startKey = k1.key(); if (k1.Chapter() == 0) k1.Chapter(1); k1.Verse(bible->verseCount(k1.book(), k1.Chapter())); endKey = k1.key(); } CDisplayRendering render(displayOptions, filterOptions); return render.renderKeyRange( startKey, endKey, modules, keyName, settings ); }
/** Returns the rendered text using the modules in the list and using the key parameter. * The displayoptions and filter options are used, too. */ const QString CEntryDisplay::text( const QList<CSwordModuleInfo*>& modules, const QString& keyName, const CSwordBackend::DisplayOptions displayOptions, const CSwordBackend::FilterOptions filterOptions ) { CDisplayRendering render(displayOptions, filterOptions); //no highlighted key and no extra key link in the text CTextRendering::KeyTreeItem::Settings normal_settings(false, CTextRendering::KeyTreeItem::Settings::CompleteShort); CSwordModuleInfo* module = modules.first(); Rendering::CTextRendering::KeyTree tree; //in Bibles and Commentaries we need to check if 0:0 and X:0 contain something if (module->type() == CSwordModuleInfo::Bible || module->type() == CSwordModuleInfo::Commentary) { ((sword::VerseKey*)(module->module()->getKey()))->Headings(1); //HACK: enable headings for VerseKeys CSwordVerseKey k1(module); k1.Headings(1); k1.key(keyName); // don't print the key CTextRendering::KeyTreeItem::Settings preverse_settings(false, CTextRendering::KeyTreeItem::Settings::NoKey); if (k1.Verse() == 1) { //X:1, prepend X:0 if (k1.Chapter() == 1) { //1:1, also prepend 0:0 before that k1.Chapter(0); k1.Verse(0); if ( k1.rawText().length() > 0 ) { tree.append( new Rendering::CTextRendering::KeyTreeItem(k1.key(), modules, preverse_settings) ); } k1.Chapter(1); } k1.Verse(0); if ( k1.rawText().length() > 0 ) { tree.append( new Rendering::CTextRendering::KeyTreeItem(k1.key(), modules, preverse_settings) ); } } } tree.append( new Rendering::CTextRendering::KeyTreeItem(keyName, modules, normal_settings) ); QString result(render.renderKeyTree(tree)); qDeleteAll(tree); return result; }
void BtSearchResultArea::updatePreview(const QString& key) { using namespace Rendering; CSwordModuleInfo* module = m_moduleListBox->activeModule(); if ( module ) { const QString searchedText = CSearchDialog::getSearchDialog()->searchText(); QString text; CDisplayRendering render; BtConstModuleList modules; modules.append(module); CTextRendering::KeyTreeItem::Settings settings; //for bibles render 5 context verses if (module->type() == CSwordModuleInfo::Bible) { CSwordVerseKey vk(module); vk.setIntros(true); vk.setKey(key); // HACK: enable headings for VerseKeys: static_cast<sword::VerseKey *>(module->module()->getKey()) ->setIntros(true); //first go back and then go forward the keys to be in context vk.previous(CSwordVerseKey::UseVerse); vk.previous(CSwordVerseKey::UseVerse); //include Headings in display, they are indexed and searched too if (vk.getVerse() == 1) { if (vk.getChapter() == 1) { vk.setChapter(0); } vk.setVerse(0); } const QString startKey = vk.key(); vk.setKey(key); vk.next(CSwordVerseKey::UseVerse); vk.next(CSwordVerseKey::UseVerse); const QString endKey = vk.key(); settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::CompleteShort; text = render.renderKeyRange(startKey, endKey, modules, key, settings); } //for commentaries only one verse, but with heading else if (module->type() == CSwordModuleInfo::Commentary) { CSwordVerseKey vk(module); vk.setIntros(true); vk.setKey(key); // HACK: enable headings for VerseKeys: static_cast<sword::VerseKey *>(module->module()->getKey()) ->setIntros(true); //include Headings in display, they are indexed and searched too if (vk.getVerse() == 1) { if (vk.getChapter() == 1) { vk.setChapter(0); } vk.setVerse(0); } const QString startKey = vk.key(); vk.setKey(key); const QString endKey = vk.key(); settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::NoKey; text = render.renderKeyRange(startKey, endKey, modules, key, settings); } else { text = render.renderSingleKey(key, modules, settings); } m_previewDisplay->setText( CSwordModuleSearch::highlightSearchedText(text, searchedText) ); m_previewDisplay->moveToAnchor( CDisplayRendering::keyToHTMLAnchor(key) ); } }
bool Filters::BT_ThMLHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) { if (!substituteToken(buf, token) && !substituteEscapeString(buf, token)) { sword::XMLTag tag(token); BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData); sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack to be able to call stuff like Lang() if ( tag.getName() && !sword::stricmp(tag.getName(), "foreign") ) { // a text part in another language, we have to set the right font if (tag.getAttribute("lang")) { const char* abbrev = tag.getAttribute("lang"); //const CLanguageMgr::Language* const language = CPointers::languageMgr()->languageForAbbrev( QString::fromLatin1(abbrev) ); buf.append("<span class=\"foreign\" lang=\""); buf.append(abbrev); buf.append("\">"); } } else if (tag.getName() && !sword::stricmp(tag.getName(), "sync")) { //lemmas, morph codes or strongs if (tag.getAttribute("type") && (!sword::stricmp(tag.getAttribute("type"), "morph") || !sword::stricmp(tag.getAttribute("type"), "Strongs") || !sword::stricmp(tag.getAttribute("type"), "lemma"))) { // Morph or Strong buf.append('<'); buf.append(token); buf.append('>'); } } else if (tag.getName() && !sword::stricmp(tag.getName(), "note")) { // <note> tag if (!tag.isEndTag() && !tag.isEmpty()) { //appending is faster than appendFormatted buf.append(" <span class=\"footnote\" note=\""); buf.append(myModule->Name()); buf.append('/'); buf.append(myUserData->key->getShortText()); buf.append('/'); buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() ); buf.append("\">*</span> "); myUserData->suspendTextPassThru = true; myUserData->inFootnoteTag = true; } else if (tag.isEndTag() && !tag.isEmpty()) { //end tag //buf += ")</span>"; myUserData->suspendTextPassThru = false; myUserData->inFootnoteTag = false; } } else if (tag.getName() && !sword::stricmp(tag.getName(), "scripRef")) { // a scripRef //scrip refs which are embeded in footnotes may not be displayed! if (!myUserData->inFootnoteTag) { if (tag.isEndTag()) { if (myUserData->inscriptRef) { // like "<scripRef passage="John 3:16">See John 3:16</scripRef>" buf.append("</a></span>"); myUserData->inscriptRef = false; myUserData->suspendTextPassThru = false; } else { // like "<scripRef>John 3:16</scripRef>" CSwordModuleInfo* mod = CBTConfig::get(CBTConfig::standardBible); //Q_ASSERT(mod); tested later if (mod) { CReferenceManager::ParseOptions options; options.refBase = QString::fromUtf8(myUserData->key->getText()); //current module key options.refDestinationModule = QString(mod->name()); options.sourceLanguage = QString(myModule->Lang()); options.destinationLanguage = QString("en"); //it's ok to split the reference, because to descriptive text is given bool insertSemicolon = false; buf.append("<span class=\"crossreference\">"); QStringList refs = QString::fromUtf8(myUserData->lastTextNode.c_str()).split(";"); QString oldRef; //the previous reference to use as a base for the next refs for (QStringList::iterator it(refs.begin()); it != refs.end(); ++it) { if (! oldRef.isEmpty() ){ options.refBase = oldRef; //use the last ref as a base, e.g. Rom 1,2-3, when the next ref is only 3:3-10 } const QString completeRef( CReferenceManager::parseVerseReference((*it), options) ); oldRef = completeRef; //use the parsed result as the base for the next ref. if (insertSemicolon) { //prepend a ref divider if we're after the first one buf.append("; "); } buf.append("<a href=\""); buf.append( CReferenceManager::encodeHyperlink( mod->name(), completeRef, CReferenceManager::typeFromModule(mod->type()) ).toUtf8().constData() ); buf.append("\" crossrefs=\""); buf.append((const char*)completeRef.toUtf8()); buf.append("\">"); buf.append((const char*)(*it).toUtf8()); buf.append("</a>"); insertSemicolon = true; } buf.append("</span>"); //crossref end } myUserData->suspendTextPassThru = false; } } else if (tag.getAttribute("passage") ) { //the passage was given as a parameter value myUserData->inscriptRef = true; myUserData->suspendTextPassThru = false; const char* ref = tag.getAttribute("passage"); Q_ASSERT(ref); CSwordModuleInfo* mod = CBTConfig::get(CBTConfig::standardBible); //Q_ASSERT(mod); tested later CReferenceManager::ParseOptions options; options.refBase = QString::fromUtf8(myUserData->key->getText()); options.refDestinationModule = QString(mod->name()); options.sourceLanguage = myModule->Lang(); options.destinationLanguage = QString("en"); const QString completeRef = CReferenceManager::parseVerseReference(QString::fromUtf8(ref), options); if (mod) { buf.append("<span class=\"crossreference\">"); buf.append("<a href=\""); buf.append( CReferenceManager::encodeHyperlink( mod->name(), completeRef, CReferenceManager::typeFromModule(mod->type()) ).toUtf8().constData() ); buf.append("\" crossrefs=\""); buf.append((const char*)completeRef.toUtf8()); buf.append("\">"); } else { buf.append("<span><a>"); } } else if ( !tag.getAttribute("passage") ) { // we're starting a scripRef like "<scripRef>John 3:16</scripRef>" myUserData->inscriptRef = false; // let's stop text from going to output, the text get's added in the -tag handler myUserData->suspendTextPassThru = true; } } } else if (tag.getName() && !sword::stricmp(tag.getName(), "div")) { if (tag.isEndTag()) { buf.append("</div>"); } else if ( tag.getAttribute("class") && !sword::stricmp(tag.getAttribute("class"),"sechead") ) { buf.append("<div class=\"sectiontitle\">"); } else if (tag.getAttribute("class") && !sword::stricmp(tag.getAttribute("class"), "title")) { buf.append("<div class=\"booktitle\">"); } } else if (tag.getName() && !sword::stricmp(tag.getName(), "img") && tag.getAttribute("src")) { const char* value = tag.getAttribute("src"); if (value[0] == '/') { value++; //strip the first / } buf.append("<img src=\"file:"); buf.append(myUserData->module->getConfigEntry("AbsoluteDataPath")); buf.append('/'); buf.append(value); buf.append("\" />"); } else { // let unknown token pass thru return sword::ThMLHTML::handleToken(buf, token, userData); } } return true; }
const QString CInfoDisplay::decodeCrossReference( const QString& data ) { Q_ASSERT(!data.isEmpty()); if (data.isEmpty()) { return QString("<div class=\"crossrefinfo\"><h3>%1</h3></div>") .arg(tr("Cross references")); } // qWarning("setting crossref %s", data.latin1()); CSwordBackend::DisplayOptions dispOpts; dispOpts.lineBreaks = false; dispOpts.verseNumbers = true; CSwordBackend::FilterOptions filterOpts; filterOpts.headings = false; filterOpts.strongNumbers = false; filterOpts.morphTags = false; filterOpts.lemmas = false; filterOpts.footnotes = false; filterOpts.scriptureReferences = false; CrossRefRendering renderer(dispOpts, filterOpts); CTextRendering::KeyTree tree; // const bool isBible = true; CSwordModuleInfo* module = CBTConfig::get (CBTConfig::standardBible); //a prefixed module gives the module to look into QRegExp re("^[^ ]+:"); // re.setMinimal(true); int pos = re.indexIn(data); if (pos != -1) { pos += re.matchedLength()-1; } if (pos > 0) { const QString moduleName = data.left(pos); // qWarning("found module %s", moduleName.latin1()); module = CPointers::backend()->findModuleByName(moduleName); if (!module) { module = CBTConfig::get (CBTConfig::standardBible); } // Q_ASSERT(module); } //Q_ASSERT(module); //why? the existense of the module is tested later CTextRendering::KeyTreeItem::Settings settings ( false, CTextRendering::KeyTreeItem::Settings::CompleteShort ); if (module && (module->type() == CSwordModuleInfo::Bible)) { VerseKey vk; sword::ListKey refs = vk.ParseVerseList((const char*)data.mid((pos == -1) ? 0 : pos+1).toUtf8(), "Gen 1:1", true); for (int i = 0; i < refs.Count(); ++i) { SWKey* key = refs.getElement(i); Q_ASSERT(key); VerseKey* vk = dynamic_cast<VerseKey*>(key); CTextRendering::KeyTreeItem* itm = (CTextRendering::KeyTreeItem*)0; //explicit conversion for MS VS if (vk && vk->isBoundSet()) { //render a range of keys itm = new CTextRendering::KeyTreeItem( QString::fromUtf8(vk->LowerBound().getText()), QString::fromUtf8(vk->UpperBound().getText()), module, settings ); } else { itm = new CTextRendering::KeyTreeItem( QString::fromUtf8(key->getText()), QString::fromUtf8(key->getText()), module, settings ); } Q_ASSERT(itm); tree.append( itm ); } } else if (module) { CTextRendering::KeyTreeItem* itm = new CTextRendering::KeyTreeItem( data.mid((pos == -1) ? 0 : pos+1), module, settings ); tree.append( itm ); } // qWarning("rendered the tree: %s", renderer.renderKeyTree(tree).latin1()); //spanns containing rtl text need dir=rtl on their parent tag to be aligned properly QString lang = "en"; // default english if (module) lang = module->language()->abbrev(); return QString("<div class=\"crossrefinfo\" lang=\"%1\"><h3>%2</h3><div class=\"para\" dir=\"%3\">%4</div></div>") .arg(lang) .arg(tr("Cross references")) .arg(module ? ((module->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl") : "") .arg(renderer.renderKeyTree(tree)); }
bool Filters::BT_OSISHTML::handleToken(sword::SWBuf &buf, const char *token, sword::BasicFilterUserData *userData) { // manually process if it wasn't a simple substitution if (!substituteToken(buf, token)) { BT_UserData* myUserData = dynamic_cast<BT_UserData*>(userData); sword::SWModule* myModule = const_cast<sword::SWModule*>(myUserData->module); //hack sword::XMLTag tag(token); // qWarning("found %s", token); const bool osisQToTick = ((!userData->module->getConfigEntry("OSISqToTick")) || (strcmp(userData->module->getConfigEntry("OSISqToTick"), "false"))); if (!tag.getName()) { return false; } // <div> tag if (!strcmp(tag.getName(), "div")) { //handle intro if ((!tag.isEmpty()) && (!tag.isEndTag())) { //start tag sword::SWBuf type( tag.getAttribute("type") ); if (type == "introduction") { buf.append("<div class=\"introduction\">"); } else if (type == "chapter") { buf.append("<div class=\"chapter\" />"); //don't open a div here, that would lead to a broken XML structure } else { buf.append("<div>"); } } else if (tag.isEndTag()) { //end tag buf.append("</div>"); } } else if (!strcmp(tag.getName(), "w")) { if ((!tag.isEmpty()) && (!tag.isEndTag())) { //start tag const char *attrib; const char *val; sword::XMLTag outTag("span"); sword::SWBuf attrValue; if ((attrib = tag.getAttribute("xlit"))) { val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; outTag.setAttribute("xlit", val); } if ((attrib = tag.getAttribute("gloss"))) { val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; outTag.setAttribute("gloss", val); } if ((attrib = tag.getAttribute("lemma"))) { char splitChar = '|'; const int countSplit1 = tag.getAttributePartCount("lemma", '|'); const int countSplit2 = tag.getAttributePartCount("lemma", ' '); //TODO: not allowed, remove soon int count = 0; if (countSplit1 > countSplit2) { //| split char splitChar = '|'; //TODO: not allowed, remove soon count = countSplit1; } else { splitChar = ' '; count = countSplit2; } int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0 attrValue = ""; do { if (attrValue.length()) { attrValue.append( '|' ); } attrib = tag.getAttribute("lemma", i, splitChar); if (i < 0) { // to handle our -1 condition i = 0; } val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; attrValue.append(val); } while (++i < count); if (attrValue.length()) { outTag.setAttribute("lemma", attrValue.c_str()); } } if ((attrib = tag.getAttribute("morph"))) { char splitChar = '|'; const int countSplit1 = tag.getAttributePartCount("morph", '|'); const int countSplit2 = tag.getAttributePartCount("morph", ' '); //TODO: not allowed, remove soon int count = 0; if (countSplit1 > countSplit2) { //| split char splitChar = '|'; count = countSplit1; } else { splitChar = ' '; count = countSplit2; } int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0 attrValue = ""; do { if (attrValue.length()) { attrValue.append('|'); } attrib = tag.getAttribute("morph", i, splitChar); if (i < 0) { i = 0; // to handle our -1 condition } val = strchr(attrib, ':'); if (val) { //the prefix gives the modulename //check the prefix if (!strncmp("robinson:", attrib, 9)) { //robinson attrValue.append( "Robinson:" ); //work is not the same as Sword's module name attrValue.append( val+1 ); } //strongs is handled by BibleTime /*else if (!strncmp("strongs", attrib, val-atrrib)) { attrValue.append( !strncmp(attrib, "x-", 2) ? attrib+2 : attrib ); }*/ else { attrValue.append( !strncmp(attrib, "x-", 2) ? attrib+2 : attrib ); } } else { //no prefix given const bool skipFirst = ((val[0] == 'T') && ((val[1] == 'H') || (val[1] == 'H'))); attrValue.append( skipFirst ? val+1 : val ); } } while (++i < count); if (attrValue.length()) { outTag.setAttribute("morph", attrValue.c_str()); } } if ((attrib = tag.getAttribute("POS"))) { val = strchr(attrib, ':'); val = (val) ? (val + 1) : attrib; outTag.setAttribute("pos", val); } buf.append( outTag.toString() ); } else if (tag.isEndTag()) { // end or empty <w> tag buf.append("</span>"); } } // <note> tag else if (!strcmp(tag.getName(), "note")) { if (!tag.isEndTag()) { //start tag const sword::SWBuf type( tag.getAttribute("type") ); if (type == "crossReference") { //note containing cross references myUserData->inCrossrefNote = true; myUserData->noteType = BT_UserData::CrossReference; myUserData->swordFootnote++; // cross refs count as notes, too /* //get the refList value of the right entry attribute AttributeList notes = myModule->getEntryAttributes()["Footnote"]; bool foundNote = false; SWBuf id( tag.getAttribute("osisID") ); SWBuf refList; for (AttributeList::iterator list_it = notes.begin(); (list_it != notes.end()) && !foundNote; ++list_it ) { for (AttributeValue::iterator val_it = list_it->second.begin(); (val_it != list_it->second.end()) && !foundNote; ++val_it ) { if ((val_it->first == "osisID") && (val_it->second == id)) { foundNote = true; //this break the loop refList = list_it->second["refList"]; } } } if (refList.length()) { buf.append(" <span class=\"crossreference\" crossrefs=\""); buf.append(refList.c_str()); buf.append("\"> "); myUserData->noteType = BT_UserData::CrossReference; } else { myUserData->noteType = BT_UserData::Unknown; }*/ buf.append("<span class=\"crossreference\">"); } /* else if (type == "explanation") { } */ else if ((type == "strongsMarkup") || (type == "x-strongsMarkup")) { /** * leave strong's markup notes out, in the future we'll probably have * different option filters to turn different note types on or off */ myUserData->suspendTextPassThru = true; myUserData->noteType = BT_UserData::StrongsMarkup; } else { // qWarning("found note in %s", myUserData->key->getShortText()); buf.append(" <span class=\"footnote\" note=\""); buf.append(myModule->Name()); buf.append('/'); buf.append(myUserData->key->getShortText()); buf.append('/'); buf.append( QString::number(myUserData->swordFootnote++).toUtf8().constData() ); //inefficient const sword::SWBuf n = tag.getAttribute("n"); buf.append("\">"); buf.append( (n.length() > 0) ? n.c_str() : "*" ); buf.append("</span> "); myUserData->noteType = BT_UserData::Footnote; myUserData->suspendTextPassThru = true; } } else { //if (tag.isEndTag()) { Q_ASSERT(myUserData->noteType != BT_UserData::Unknown); if (myUserData->noteType == BT_UserData::CrossReference) { buf.append("</span> "); // myUserData->suspendTextPassThru = false; myUserData->inCrossrefNote = false; } myUserData->noteType = BT_UserData::Unknown; myUserData->suspendTextPassThru = false; } } // The <p> paragraph tag is handled by OSISHTMLHref else if (!strcmp(tag.getName(), "reference")) { // <reference> tag if (!tag.isEndTag() && !tag.isEmpty()) { QString ref( tag.getAttribute("osisRef") ); QString hrefRef( ref ); Q_ASSERT(!ref.isEmpty()); if (!ref.isEmpty()) { //find out the mod, using the current module makes sense if it's a bible or commentary because the refs link into a bible by default. //If the osisRef is something like "ModuleID:key comes here" then the // modulename is given, so we'll use that one CSwordModuleInfo* mod = CPointers::backend()->findSwordModuleByPointer(myModule); Q_ASSERT(mod); if (!mod || (mod->type() != CSwordModuleInfo::Bible && mod->type() != CSwordModuleInfo::Commentary)) { mod = CBTConfig::get( CBTConfig::standardBible ); } Q_ASSERT(mod); //if the osisRef like "GerLut:key" contains a module, use that int pos = ref.indexOf(":"); if ((pos >= 0) && ref.at(pos-1).isLetter() && ref.at(pos+1).isLetter()) { QString newModuleName = ref.left(pos); hrefRef = ref.mid(pos+1); if (CPointers::backend()->findModuleByName(newModuleName)) { mod = CPointers::backend()->findModuleByName(newModuleName); } } CReferenceManager::ParseOptions options; options.refBase = QString::fromUtf8(myUserData->key->getText()); options.refDestinationModule = QString(mod->name()); options.sourceLanguage = QString(myModule->Lang()); options.destinationLanguage = QString("en"); buf.append("<a href=\""); buf.append( //create the hyperlink with key and mod CReferenceManager::encodeHyperlink( mod->name(), CReferenceManager::parseVerseReference(hrefRef, options), CReferenceManager::typeFromModule(mod->type()) ).toUtf8().constData() ); buf.append("\" crossrefs=\""); buf.append((const char*)CReferenceManager::parseVerseReference(ref, options).toUtf8().constData()); //ref must contain the osisRef module marker if there was any buf.append("\">"); } } else if (tag.isEndTag()) { buf.append("</a>"); } else { // empty reference marker // -- what should we do? nothing for now. } } // <l> is handled by OSISHTMLHref // <title> else if (!strcmp(tag.getName(), "title")) { if (!tag.isEndTag() && !tag.isEmpty()) { buf.append("<div class=\"sectiontitle\">"); } else if (tag.isEndTag()) { buf.append("</div>"); } else { // empty title marker // what to do? is this even valid? buf.append("<br/>"); } } // <hi> highlighted text else if (!strcmp(tag.getName(), "hi")) { const sword::SWBuf type = tag.getAttribute("type"); if ((!tag.isEndTag()) && (!tag.isEmpty())) { if (type == "bold") { buf.append("<span class=\"bold\">"); } else if (type == "illuminated") { buf.append("<span class=\"illuminated\">"); } else if (type == "italic") { buf.append("<span class=\"italic\">"); } else if (type == "line-through") { buf.append("<span class=\"line-through\">"); } else if (type == "normal") { buf.append("<span class=\"normal\">"); } else if (type == "small-caps") { buf.append("<span class=\"small-caps\">"); } else if (type == "underline") { buf.append("<span class=\"underline\">"); } else { buf.append("<span>"); //don't break markup, </span> is inserted later } } else if (tag.isEndTag()) { //all hi replacements are html spans buf.append("</span>"); } } //name else if (!strcmp(tag.getName(), "name")) { const sword::SWBuf type = tag.getAttribute("type"); if ((!tag.isEndTag()) && (!tag.isEmpty())) { if (type == "geographic") { buf.append("<span class=\"name\"><span class=\"geographic\">"); } else if (type == "holiday") { buf.append("<span class=\"name\"><span class=\"holiday\">"); } else if (type == "nonhuman") { buf.append("<span class=\"name\"><span class=\"nonhuman\">"); } else if (type == "person") { buf.append("<span class=\"name\"><span class=\"person\">"); } else if (type == "ritual") { buf.append("<span class=\"name\"><span class=\"ritual\">"); } else { buf.append("<span class=\"name\"><span>"); } } else if (tag.isEndTag()) { //all hi replacements are html spans buf.append("</span></span> "); } } else if (!strcmp(tag.getName(), "transChange")) { sword::SWBuf type( tag.getAttribute("type") ); if ( !type.length() ) { type = tag.getAttribute("changeType"); } if ((!tag.isEndTag()) && (!tag.isEmpty())) { if (type == "added") { buf.append("<span class=\"transchange\" title=\""); buf.append(QObject::tr("Added text").toUtf8().constData()); buf.append("\"><span class=\"added\">"); } else if (type == "amplified") { buf.append("<span class=\"transchange\"><span class=\"amplified\">"); } else if (type == "changed") { buf.append("<span class=\"transchange\"><span class=\"changed\">"); } else if (type == "deleted") { buf.append("<span class=\"transchange\"><span class=\"deleted\">"); } else if (type == "moved") { buf.append("<span class=\"transchange\"><span class=\"moved\">"); } else if (type == "tenseChange") { buf.append("<span class=\"transchange\" title=\""); buf.append(QObject::tr("Verb tense changed").toUtf8().constData()); buf.append("\"><span class=\"tenseChange\">"); } else { buf.append("<span class=\"transchange\"><span>"); } } else if (tag.isEndTag()) { //all hi replacements are html spans buf.append("</span></span>"); } } else if (!strcmp(tag.getName(), "p")) { if (tag.isEmpty()) { buf.append("<p/>"); } } // <q> quote else if (!strcmp(tag.getName(), "q")) { sword::SWBuf type = tag.getAttribute("type"); sword::SWBuf who = tag.getAttribute("who"); const char *lev = tag.getAttribute("level"); int level = (lev) ? atoi(lev) : 1; if ((!tag.isEndTag()) && (!tag.isEmpty())) { myUserData->quote.who = who; if(osisQToTick) //alternate " and ' buf.append((level % 2) ? '\"' : '\''); if (who == "Jesus") { buf.append("<span class=\"jesuswords\">"); } } else if (tag.isEndTag()) { if (myUserData->quote.who == "Jesus") { buf.append("</span>"); } if (osisQToTick) { //alternate " and ' buf.append((level % 2) ? '\"' : '\''); } myUserData->quote.who = ""; } } // abbr tag else if (!strcmp(tag.getName(), "abbr")) { if (!tag.isEndTag() && !tag.isEmpty()) { const sword::SWBuf expansion = tag.getAttribute("expansion"); buf.append("<span class=\"abbreviation\" expansion=\""); buf.append(expansion); buf.append("\">"); } else if (tag.isEndTag()) { buf.append("</span>"); } } // <milestone> tag else if (!strcmp(tag.getName(), "milestone")) { const sword::SWBuf type = tag.getAttribute("type"); if ((type == "screen") || (type == "line")) {//line break buf.append("<br/>"); userData->supressAdjacentWhitespace = true; } else if (type == "x-p") { //e.g. occurs in the KJV2006 module //buf.append("<br/>"); const sword::SWBuf marker = tag.getAttribute("marker"); if (marker.length() > 0) { buf.append(marker); } } } //seg tag else if (!strcmp(tag.getName(), "seg")) { if (!tag.isEndTag() && !tag.isEmpty()) { const sword::SWBuf type = tag.getAttribute("type"); if (type == "morph") {//line break //This code is for WLC and MORPH (WHI) sword::XMLTag outTag("span"); outTag.setAttribute("class", "morphSegmentation"); const char* attrValue; //Transfer the values to the span //Problem: the data is in hebrew/aramaic, how to encode in HTML/BibleTime? if ((attrValue = tag.getAttribute("lemma"))) outTag.setAttribute("lemma", attrValue); if ((attrValue = tag.getAttribute("morph"))) outTag.setAttribute("morph", attrValue); if ((attrValue = tag.getAttribute("homonym"))) outTag.setAttribute("homonym", attrValue); buf.append(outTag.toString()); //buf.append("<span class=\"morphSegmentation\">"); } else{ buf.append("<span>"); } } else { // seg end tag buf.append("</span>"); } //qWarning(QString("handled <seg> token. result: %1").arg(buf.c_str()).latin1()); } //divine name, don't use simple tag replacing because it may have attributes else if (!strcmp(tag.getName(), "divineName")) { if (!tag.isEndTag()) { buf.append("<span class=\"name\"><span class=\"divine\">"); } else { //all hi replacements are html spans buf.append("</span></span>"); } } else { //all tokens handled by OSISHTMLHref will run through the filter now return sword::OSISHTMLHREF::handleToken(buf, token, userData); } } return false; }