aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/doc_reform/io_out
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc_reform/io_out')
-rw-r--r--src/doc_reform/io_out/cgi_sqlite_search_form.d56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/doc_reform/io_out/cgi_sqlite_search_form.d b/src/doc_reform/io_out/cgi_sqlite_search_form.d
index 31cab66..4523c2d 100644
--- a/src/doc_reform/io_out/cgi_sqlite_search_form.d
+++ b/src/doc_reform/io_out/cgi_sqlite_search_form.d
@@ -1217,6 +1217,45 @@ void cgi_function_intro(Cgi cgi) {
return sql_match_offset_count;
}
void sql_search_query() {
+ string highlight_text_matched(string _txt, string search_field) {
+ string _mark_open = "┤";
+ string _mark_close = "├";
+ string _span_yellow = "<span style=\"background-color: #ffff48\">";
+ string _span_red = "<span style=\"background-color: #ff48ff\">";
+ string _span_blue = "<span style=\"background-color: #48ffff\">";
+ string _span_close = "</span>";
+ string _sf_str = search_field.strip.split("%%20").join(" ").strip;
+ string[] _sf_arr = _sf_str.split(regex(r"\s+AND\s+|\s+OR\s+"));
+ auto rgx_url = regex(r"<a href=[^>]+?>");
+ foreach (_sf; _sf_arr) {
+ auto rgx_matched_text = regex(_sf, "i");
+ auto rgx_marked_pair = regex(r"┤(?P<keep>" ~ _sf ~ ")├", "i");
+ if (auto m = _txt.matchFirst(rgx_url)) {
+ _txt = replaceAll!(m =>
+ _mark_open
+ ~ m.captures[0]
+ ~ _mark_close
+ )(_txt, rgx_matched_text);
+ _txt = replaceAll!(m =>
+ replaceAll!(u =>
+ u["keep"]
+ )(m.hit, rgx_marked_pair)
+ )(_txt, rgx_url);
+ _txt = replaceAll!(m =>
+ _span_yellow
+ ~ m["keep"]
+ ~ _span_close
+ )(_txt, rgx_marked_pair);
+ } else {
+ _txt = replaceAll!(m =>
+ _span_yellow
+ ~ m.captures[0]
+ ~ _span_close
+ )(_txt, rgx_matched_text);
+ }
+ }
+ return _txt;
+ }
string select_field_like(string db_field, string search_field) {
string where_ = "";
if (!(search_field.empty)) {
@@ -1332,7 +1371,7 @@ LIMIT %%s OFFSET %%s
~ row["ocn"].as!string
~ "</a>"
~ "<br>"
- ~ row["body"].as!string
+ ~ highlight_text_matched(row["body"].as!string, tf.text)
);
} else {
cgi.write(
@@ -1344,7 +1383,7 @@ LIMIT %%s OFFSET %%s
~ row["ocn"].as!string
~ "</a>"
~ "<br>"
- ~ row["body"].as!string
+ ~ highlight_text_matched(row["body"].as!string, tf.text)
);
}
} else {
@@ -1446,18 +1485,23 @@ configuration "default" {
// Handle error
}
}
- { // cgi.d
+ { // get cgi.d
import std.net.curl, std.stdio;
+ char[] cgi_d;
try {
- auto cgi_d = get("https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d");
+ cgi_d = get!HTTP("https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d");
+ } catch (ErrnoException ex) {
+ // Handle error
+ // CurlCode perform(ThrowOnError throwOnError = Yes.throwOnError);
+ CurlCode perform(ThrowOnError throwOnError = No.throwOnError);
+ }
+ if (cgi_d && cgi_d.length > 0) {
try {
auto f = File(pth_sqlite_cgi.cgi_d_path_out, "w");
f.write(cgi_d);
} catch (ErrnoException ex) {
// Handle error
}
- } catch (ErrnoException ex) {
- // Handle error
}
}
}