Comparison

mod_pubsub_summary/mod_pubsub_summary.lua @ 4513:ade2064160e3

mod_pubsub_summary: Fix to not strip inline links Links were turned into `label <url>` and then a later pass removed the `<url>` part leaving only the label. This should avoid that. Escaping is hard.
author Kim Alvefur <zash@zash.se>
date Wed, 17 Mar 2021 15:52:12 +0100
parent 4507:86a97e7572b2
child 4600:98864dffb231
comparison
equal deleted inserted replaced
4512:b88f05c878ac 4513:ade2064160e3
9 local content_tag = payload:get_child("content") or payload:get_child("summary"); 9 local content_tag = payload:get_child("content") or payload:get_child("summary");
10 local content = content_tag and content_tag:get_text(); 10 local content = content_tag and content_tag:get_text();
11 if content and content_tag.attr.type == "html" then 11 if content and content_tag.attr.type == "html" then
12 content = content:gsub("\n*<p[^>]*>\n*(.-)\n*</p>\n*", "%1\n\n"); 12 content = content:gsub("\n*<p[^>]*>\n*(.-)\n*</p>\n*", "%1\n\n");
13 content = content:gsub("<li>(.-)</li>\n", "* %1\n"); 13 content = content:gsub("<li>(.-)</li>\n", "* %1\n");
14 content = content:gsub("<a[^>]*href=[\"'](.-)[\"'][^>]*>(.-)</a>", "%2 <%1>"); 14 content = content:gsub("<a[^>]*href=[\"'](.-)[\"'][^>]*>(.-)</a>", "\1%1\2%2\3");
15 content = content:gsub("<b>(.-)</b>", "*%1*"); 15 content = content:gsub("<b>(.-)</b>", "*%1*");
16 content = content:gsub("<strong>(.-)</strong>", "*%1*"); 16 content = content:gsub("<strong>(.-)</strong>", "*%1*");
17 content = content:gsub("<em>(.-)</em>", "*%1*"); 17 content = content:gsub("<em>(.-)</em>", "*%1*");
18 content = content:gsub("<i>(.-)</i>", "*%1*"); 18 content = content:gsub("<i>(.-)</i>", "*%1*");
19 content = content:gsub("<img[^>]*src=[\"'](.-)[\"'][^>]*>", " %1 "); -- TODO alt= would have been nice to grab 19 content = content:gsub("<img[^>]*src=[\"'](.-)[\"'][^>]*>", " %1 "); -- TODO alt= would have been nice to grab
20 content = content:gsub("<br[^>]*>", "\n"); 20 content = content:gsub("<br[^>]*>", "\n");
21 content = content:gsub("<[^>]+>", ""); 21 content = content:gsub("<[^>]+>", "");
22 content = content:gsub("\1(.-)\2(.-)\3", "%2 <%1>");
22 content = content:gsub("^%s*", ""):gsub("%s*$", ""); 23 content = content:gsub("^%s*", ""):gsub("%s*$", "");
23 content = content:gsub("\n\n\n+", "\n\n"); 24 content = content:gsub("\n\n\n+", "\n\n");
24 content = content:gsub("&(%w+);", { 25 content = content:gsub("&(%w+);", {
25 apos = "'"; 26 apos = "'";
26 quot = '"'; 27 quot = '"';