diff src/lib/Bbcode.luan @ 23:cdcd1b70c15e

tinymce work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 Jul 2022 23:50:48 -0600
parents 33731231093a
children 6871eec2cf4c
line wrap: on
line diff
--- a/src/lib/Bbcode.luan	Sun Jul 17 21:47:55 2022 -0600
+++ b/src/lib/Bbcode.luan	Mon Jul 18 23:50:48 2022 -0600
@@ -16,6 +16,7 @@
 local String = require "luan:String.luan"
 local gsub = String.gsub or error()
 local matches = String.matches or error()
+local match = String.match or error()
 local User = require "site:/lib/User.luan"
 local Shared = require "site:/lib/Shared.luan"
 local list_to_set = Shared.list_to_set or error()
@@ -79,7 +80,7 @@
 end
 
 function html.size(bbcode,options)
-	%><span style="font-size:<%=bbcode.param%>%"><% to_html(bbcode.contents,options) %></span><%
+	%><span style="font-size:<%=bbcode.param%>"><% to_html(bbcode.contents,options) %></span><%
 end
 
 function html.quote(bbcode,options)
@@ -100,21 +101,31 @@
 	options.strip_newline = true
 end
 
+local youtube_ptn1 = [[https://youtu.be/([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?]]
+local youtube_ptn2 = [[https://www.youtube.com/watch\?v=([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?]]
+local bitchute_ptn = [[https://www.bitchute.com/video/([a-zA-Z0-9]+)/]]
+
 function html.video(bbcode,options)
-	local url = html_encode(bbcode.contents)
-	local site = bbcode.site
-	if site == "youtube" then
-		%><iframe width="420" height="315" src="https://www.youtube.com/embed/<%=bbcode.id%><%
-		local start = bbcode.start
+	local url = bbcode.contents
+	local id, start = match(url,youtube_ptn1)
+	if id == nil then
+		id, start = match(url,youtube_ptn2)
+	end
+	if id ~= nil then
+		%><iframe width="560" height="315" src="https://www.youtube.com/embed/<%=id%><%
 		if start ~= nil then
 			%>?start=<%=start%><%
 		end
 		%>" frameborder="0" allowfullscreen></iframe><%
-	elseif site == "bitchute" then
-		%><iframe width="420" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/<%=bbcode.id%>/"></iframe><%
-	else
-		%><a href="<%=url%>"><%=url%></a><%
+		return
 	end
+	id = match(url,bitchute_ptn)
+	if id ~= nil then
+		%><iframe width="560" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/<%=id%>/"></iframe><%
+		return
+	end
+	url = html_encode(url)
+	%><a href="<%=url%>"><%=url%></a><%
 end
 
 local function list_to_html(bbcode,options)