mirror of https://github.com/kiwix/libkiwix.git
Better Kiwix Serve Taskbar insertion (after charset definition)
This commit is contained in:
parent
a61c94ef10
commit
a8bf9dd5b4
|
@ -29,5 +29,8 @@ std::string replaceRegex(const std::string& content,
|
||||||
std::string appendToFirstOccurence(const std::string& content,
|
std::string appendToFirstOccurence(const std::string& content,
|
||||||
const std::string& regex,
|
const std::string& regex,
|
||||||
const std::string& replacement);
|
const std::string& replacement);
|
||||||
|
std::string prependToFirstOccurence(const std::string& content,
|
||||||
|
const std::string& regex,
|
||||||
|
const std::string& replacement);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -203,9 +203,9 @@ void ContentResponse::introduce_taskbar()
|
||||||
data.set("title", m_bookTitle);
|
data.set("title", m_bookTitle);
|
||||||
data.set("withlibrarybutton", m_withLibraryButton);
|
data.set("withlibrarybutton", m_withLibraryButton);
|
||||||
auto head_content = render_template(RESOURCE::templates::head_part_html, data);
|
auto head_content = render_template(RESOURCE::templates::head_part_html, data);
|
||||||
m_content = appendToFirstOccurence(
|
m_content = prependToFirstOccurence(
|
||||||
m_content,
|
m_content,
|
||||||
"<head[^>]*>",
|
"</head[^>]*>",
|
||||||
head_content);
|
head_content);
|
||||||
|
|
||||||
auto taskbar_part = render_template(RESOURCE::templates::taskbar_part_html, data);
|
auto taskbar_part = render_template(RESOURCE::templates::taskbar_part_html, data);
|
||||||
|
|
|
@ -95,3 +95,22 @@ std::string appendToFirstOccurence(const std::string& content,
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string prependToFirstOccurence(const std::string& content,
|
||||||
|
const std::string& regex,
|
||||||
|
const std::string& replacement)
|
||||||
|
{
|
||||||
|
ucnv_setDefaultName("UTF-8");
|
||||||
|
icu::UnicodeString ucontent(content.c_str());
|
||||||
|
icu::UnicodeString ureplacement(replacement.c_str());
|
||||||
|
auto matcher = buildMatcher(regex, ucontent);
|
||||||
|
if (matcher->find()) {
|
||||||
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
|
ucontent.insert(matcher->start(status), ureplacement);
|
||||||
|
std::string tmp;
|
||||||
|
ucontent.toUTF8String(tmp);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue