diff options
author | Your Name <you@example.com> | 2021-08-09 16:40:24 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-08-09 16:40:24 -0400 |
commit | ab2668a4b0e6eebd80668aea9110f6fb86aed5a4 (patch) | |
tree | bcffb10053a4080d87a2870ad23bc8bcc11cb4f1 /libbible.cc | |
parent | 41e9b6128ed8588c01d2aa2fb7d71af81709873e (diff) | |
download | libbible-ab2668a4b0e6eebd80668aea9110f6fb86aed5a4.tar.gz libbible-ab2668a4b0e6eebd80668aea9110f6fb86aed5a4.tar.bz2 libbible-ab2668a4b0e6eebd80668aea9110f6fb86aed5a4.zip |
Fixed processing of non-span xhtml formatting tags
Diffstat (limited to 'libbible.cc')
-rw-r--r-- | libbible.cc | 58 |
1 files changed, 19 insertions, 39 deletions
diff --git a/libbible.cc b/libbible.cc index 901ff4e..12e45a0 100644 --- a/libbible.cc +++ b/libbible.cc @@ -167,33 +167,10 @@ vector<libbible::text> libbible::getText(libbible::passage pass) { (*key)++) { string text = string(target->renderText()); - //printf("Processing text \"%s\"", text.c_str()); - - // Handle ¶ symbol if at beginning of line - /*if(text.find("¶") == 0) { - text.erase(0, 1); - // Append \n to text in previous texts (if applicable) - if(! texts.empty()) { - texts.back().text += '\n'; - } - endOfParagraph = true; - }*/ + //printf("Working with: %s\n", text.c_str()); texts.push_back(getEmptyText(key)); - /* Things to enforce: - * 1. No whitespace at start of verse - */ - - // Find and replace everything in "subs" map - /*const map<string, string> subs = {{"¶", "\n\t"}}; - for(auto const &repl : subs) { - string::size_type location; - while((location = text.find(repl.first)) != string::npos) { - text.replace(location, repl.first.size(), repl.second); - } - }*/ - if(key->getVerse() == 1 || endOfParagraph) { if(find(texts.back().modifiers.begin(), texts.back().modifiers.end(), "paragraph") == texts.back().modifiers.end()) { texts.back().modifiers.push_back("paragraph"); @@ -202,7 +179,7 @@ vector<libbible::text> libbible::getText(libbible::passage pass) { } // Variable to accumulate unterminated spans - std::vector<string> spans; + std::vector<std::pair<std::string, std::string>> spans; bool spansChanged = false; bool hasAddedText = false; // Iterate over text @@ -213,7 +190,7 @@ vector<libbible::text> libbible::getText(libbible::passage pass) { if(!texts.back().text.empty()) { texts.push_back(getEmptyText(key)); } - for(string modifier : spans) { + for(auto& [tag, modifier] : spans) { if(find(texts.back().modifiers.begin(), texts.back().modifiers.end(), modifier) == texts.back().modifiers.end()) { texts.back().modifiers.push_back(modifier); } @@ -243,21 +220,24 @@ vector<libbible::text> libbible::getText(libbible::passage pass) { for(; i != text.end(); i++) { span.push_back(*i); if(*i == '>') { - // The end of the span will be "</span>". - if(span == "</span>") { - if(! spans.empty()) { - spans.pop_back(); - spansChanged = true; + // The end of the span will be "</tag>". + if(span[1] == '/') { + string tag = span.substr(2, span.size()-3); + for(auto rit = spans.rbegin(); rit != spans.rend(); rit++) { + if(rit->first == tag) { + spans.erase(rit.base()-1); + spansChanged = true; + break; + } } - } else { - // The span will be formatted "<span class=\"NAME\">" + } else if(span.find("class=\"") != string::npos) { + // The span will be formatted "<tag class=\"NAME\">" // We want just the NAME - size_t start = span.find_first_of('"')+1; - size_t end = span.find_last_of('"'); - if(start > 0) { - spans.push_back(span.substr(start, end-start)); - spansChanged = true; - } + string tag = span.substr(1, span.find(" ")-1); + size_t start = span.find("class=\"")+7; + size_t end = span.find("\"", start); + spans.push_back(std::pair<string, string>(tag, span.substr(start, end-start))); + spansChanged = true; } break; } |