summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-04-01 19:58:51 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-04-01 19:58:55 +0300
commit41d8d958250a1c84927428e8cf654b81cc66f16a (patch)
tree01b00aeb1d2908f0b449b8b3445f46e4058e6ad9
parentd4ab2e7d0147a5443b5fbf03dedc3324f0b1b2cf (diff)
NewStory: support for advanced url & img bbcodes
-rw-r--r--plugins/NewStory/src/templates.cpp52
-rw-r--r--plugins/NewStory/src/utils.cpp4
2 files changed, 41 insertions, 15 deletions
diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp
index 4ece9662f5..8e43a93b1c 100644
--- a/plugins/NewStory/src/templates.cpp
+++ b/plugins/NewStory/src/templates.cpp
@@ -45,6 +45,21 @@ static wchar_t* font2html(LOGFONTA &lf, wchar_t *dest)
return dest;
}
+static void AppendImage(CMStringW &buf, const CMStringW &wszUrl, const CMStringW &wszDescr, ItemData *pItem)
+{
+ if (g_plugin.bShowPreview) {
+ int iWidth = 300;
+ pItem->pOwner->webPage.load_image(wszUrl);
+ if (Bitmap *pImage = pItem->pOwner->webPage.find_image(wszUrl))
+ if (pImage->GetWidth() < 300)
+ iWidth = pImage->GetWidth();
+
+ buf.AppendFormat(L"<img style=\"width: %d;\" src=\"%s\" title=\"%s\" alt=\"%s\"/><br>",
+ iWidth, wszUrl.c_str(), wszDescr.c_str(), wszDescr.c_str());
+ }
+ else buf.AppendFormat(L"<a class=\"link\" href=\"%s\">%s</a>", wszUrl.c_str(), wszDescr.c_str());
+}
+
static void AppendString(CMStringW &buf, const wchar_t *p, ItemData *pItem)
{
bool wasSpace = false;
@@ -122,19 +137,30 @@ static void AppendString(CMStringW &buf, const wchar_t *p, ItemData *pItem)
if (auto *p2 = wcsstr(p1, L"[/img]")) {
CMStringW wszDescr(p1, int(p2 - p1));
+ AppendImage(buf, wszUrl, wszDescr, pItem);
+ p = p2 + 5;
+ }
+ }
+ }
+ else if (!wcsncmp(p, L"img]", 4)) {
+ p += 4;
- if (g_plugin.bShowPreview) {
- int iWidth = 300;
- pItem->pOwner->webPage.load_image(wszUrl);
- if (Bitmap *pImage = pItem->pOwner->webPage.find_image(wszUrl))
- if (pImage->GetWidth() < 300)
- iWidth = pImage->GetWidth();
+ if (auto *p1 = wcsstr(p, L"[/img]")) {
+ CMStringW wszUrl(p, int(p1 - p));
+ AppendImage(buf, wszUrl, L"", pItem);
+ p = p1 + 5;
+ }
+ }
+ else if (!wcsncmp(p, L"url=", 4)) {
+ p += 4;
- buf.AppendFormat(L"<img style=\"width: %d;\" src=\"%s\" title=\"%s\" alt=\"%s\"/><br>",
- iWidth, wszUrl.c_str(), wszDescr.c_str(), wszDescr.c_str());
- }
- else buf.AppendFormat(L"<a class=\"link\" href=\"%s\">%s</a>", wszUrl.c_str(), wszDescr.c_str());
+ if (auto *p1 = wcschr(p, ']')) {
+ CMStringW wszUrl(p, int(p1 - p));
+ p1++;
+ if (auto *p2 = wcsstr(p1, L"[/url]")) {
+ CMStringW wszDescr(p1, int(p2 - p1));
+ buf.AppendFormat(L"<a class=\"link\" href=\"%s\">%s</a>", wszUrl.c_str(), wszDescr.c_str());
p = p2 + 5;
}
}
@@ -142,10 +168,10 @@ static void AppendString(CMStringW &buf, const wchar_t *p, ItemData *pItem)
else if (!wcsncmp(p, L"url]", 4)) {
p += 4;
- if (auto *p2 = wcsstr(p, L"[/url]")) {
- CMStringW wszUrl(p, int(p2 - p));
+ if (auto *p1 = wcsstr(p, L"[/url]")) {
+ CMStringW wszUrl(p, int(p1 - p));
buf.AppendFormat(L"<a class=\"link\" href=\"%s\">%s</a>", wszUrl.c_str(), wszUrl.c_str());
- p = p2 + 5;
+ p = p1 + 5;
}
}
else {
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp
index fdeb6db9f3..a02d6aa393 100644
--- a/plugins/NewStory/src/utils.cpp
+++ b/plugins/NewStory/src/utils.cpp
@@ -148,11 +148,11 @@ void UrlAutodetect(CMStringW &str)
int level = 0;
for (auto *p = str.c_str(); *p; p++) {
- if (!wcsncmp(p, L"[img=", 5) || !wcsncmp(p, L"[url]", 5)) {
+ if (!wcsncmp(p, L"[img=", 5) || !wcsncmp(p, L"[img]", 5) || !wcsncmp(p, L"[url]", 5) || !wcsncmp(p, L"[url=", 5)) {
p += 4;
level++;
}
- if (!wcsncmp(p, L"[/img]", 6) || !wcsncmp(p, L"[/img]", 6)) {
+ if (!wcsncmp(p, L"[/img]", 6) || !wcsncmp(p, L"[/url]", 6)) {
p += 5;
level--;
}