summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-03-29 14:26:31 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-03-29 14:26:31 +0300
commit6fd72c2415dd52977fef53db575cf62a85153cdd (patch)
tree68f7222fb710aec5c0cc9aeea15898b77f3bfe71
parent2293da320034052e5e9d5152f4929b4f653d8812 (diff)
better URL autodetect
-rw-r--r--plugins/NewStory/src/history_array.cpp2
-rw-r--r--plugins/NewStory/src/templates.cpp2
-rw-r--r--plugins/NewStory/src/utils.cpp27
3 files changed, 22 insertions, 9 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index a0e2999cc2..04c1b44d64 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -394,7 +394,7 @@ void ItemData::load(bool bLoadAlways)
auto *pwszLocalName = blob.getLocalName();
if (ProtoGetAvatarFileFormat(pwszLocalName) != PA_FORMAT_UNKNOWN)
- buf.AppendFormat(L"[img]%s[/img]", pwszLocalName);
+ buf.AppendFormat(L"[img]file://%s[/img]", pwszLocalName);
else
buf.AppendFormat(L"[url]file://%s[/url]", pwszLocalName);
}
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index ef7bba6b9f..405a198fe6 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -118,7 +118,7 @@ static void AppendString(CMStringW &buf, const wchar_t *p)
if (auto *p2 = wcsstr(p, L"[/img]")) {
CMStringW wszUrl(p, int(p2 - p));
- buf.AppendFormat(L"<img style=\"width: 300;\" src=\"file://%s\" /><br>", wszUrl.c_str());
+ buf.AppendFormat(L"<img style=\"width: 300;\" src=\"%s\" /><br>", wszUrl.c_str());
p = p2 + 5;
}
}
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp
index f227578fd4..bd12aea485 100644
--- a/plugins/NewStory/src/utils.cpp
+++ b/plugins/NewStory/src/utils.cpp
@@ -145,12 +145,25 @@ static int DetectUrl(const wchar_t *text)
void UrlAutodetect(CMStringW &str)
{
- for (auto *p = str.c_str(); *p; p++)
- if (int len = DetectUrl(p)) {
- int pos = p - str.c_str();
- CMStringW url = str.Mid(pos, len);
- str.Insert(pos + len, L"[/url]");
- str.Insert(pos, L"[url]");
- p = str.c_str() + pos + len + 11;
+ int level = 0;
+
+ for (auto *p = str.c_str(); *p; p++) {
+ if (!wcsncmp(p, L"[img]", 5) || !wcsncmp(p, L"[url]", 5)) {
+ p += 4;
+ level++;
+ }
+ if (!wcsncmp(p, L"[/img]", 6) || !wcsncmp(p, L"[/img]", 6)) {
+ p += 5;
+ level--;
}
+ else if (int len = DetectUrl(p)) {
+ if (level == 0) {
+ int pos = p - str.c_str();
+ CMStringW url = str.Mid(pos, len);
+ str.Insert(pos + len, L"[/url]");
+ str.Insert(pos, L"[url]");
+ p = str.c_str() + pos + len + 11;
+ }
+ }
+ }
}