From a2d3672fa8daec7de5c720f995461b6f14e6e783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Mon, 26 May 2025 00:29:15 +0300 Subject: [PATCH] properly handle url= tags --- lib/babycode.lua | 15 +++++++++++---- views/common/bbcode_help.etlua | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/babycode.lua b/lib/babycode.lua index 7d4e8ef..301102b 100644 --- a/lib/babycode.lua +++ b/lib/babycode.lua @@ -23,15 +23,17 @@ function babycode.to_html(s, escape_html) end end) + local url_tags = {} -- replace `[url=https://example.com]Example[/url] tags text = text:gsub("%[url=([^%]]+)%](.-)%[/url%]", function(url, label) - return ''..label..'' + table.insert(url_tags, {url = url, label = label}) + return "\1URL:"..#url_tags.."\1" end) -- replace `[url]https://example.com[/url] tags - text = text:gsub("%[url%]([^%]]+)%[/url%]", function(url) - return ''..url..'' - end) + -- text = text:gsub("%[url%]([^%]]+)%[/url%]", function(url) + -- return ''..url..'' + -- end) -- bold, italics, strikethrough text = text:gsub("%[b%](.-)%[/b%]", "%1") @@ -48,6 +50,11 @@ function babycode.to_html(s, escape_html) return url end) + text = text:gsub("\1URL:(%d+)\1", function(n) + local url = url_tags[tonumber(n)] + return ("%s"):format(url.url, url.label) + end) + -- rule text = text:gsub("\n+%-%-%-", "
") diff --git a/views/common/bbcode_help.etlua b/views/common/bbcode_help.etlua index b3bc808..e934c67 100644 --- a/views/common/bbcode_help.etlua +++ b/views/common/bbcode_help.etlua @@ -1,11 +1,11 @@
babycode guide