annotate src/bbcode/Bbcode.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents cac477dd1f82
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local type = Luan.type or error()
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local ipairs = Luan.ipairs or error()
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
5 local pairs = Luan.pairs or error()
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local stringify = Luan.stringify or error()
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
7 local Io = require "luan:Io.luan"
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
8 local output_of = Io.output_of or error()
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Parsers = require "luan:Parsers.luan"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local bbcode_parse = Parsers.bbcode_parse or error()
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Html = require "luan:Html.luan"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local html_encode = Html.encode or error()
21
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
13 local html_parse = Html.parse or error()
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local Table = require "luan:Table.luan"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local is_list = Table.is_list or error()
21
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
16 local concat = Table.concat or error()
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
17 local String = require "luan:String.luan"
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
18 local regex = String.regex or error()
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
19 local ends_with = String.ends_with or error()
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local User = require "site:/lib/User.luan"
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
21 local Shared = require "site:/lib/Shared.luan"
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
22 local list_to_set = Shared.list_to_set or error()
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
23 local to_list = Shared.to_list or error()
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 local Logging = require "luan:logging/Logging.luan"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local logger = Logging.logger "Bbcode"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 local Bbcode = {}
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
30 local starting_cr_regex = regex[[^\n]]
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
31
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 local to_html
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 local html = {}
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
35 function html.b(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
36 %><b><% to_html(bbcode.contents,options) %></b><%
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
37 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
38
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
39 function html.i(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
40 %><i><% to_html(bbcode.contents,options) %></i><%
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
41 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
42
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
43 function html.u(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
44 %><u><% to_html(bbcode.contents,options) %></u><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
47 function html.s(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
48 %><s><% to_html(bbcode.contents,options) %></s><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
51 function html.sup(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
52 %><sup><% to_html(bbcode.contents,options) %></sup><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54
45
2d4f00755092 bcode editor work
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
55 function html.sub(bbcode,options)
2d4f00755092 bcode editor work
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
56 %><sub><% to_html(bbcode.contents,options) %></sub><%
2d4f00755092 bcode editor work
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
57 end
2d4f00755092 bcode editor work
Franklin Schmidt <fschmidt@gmail.com>
parents: 44
diff changeset
58
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
59 function html.brackets(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
60 %>[<% to_html(bbcode.contents,options) %>]<%
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
61 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
62
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
63 function html.url(bbcode,options)
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 local url = bbcode.param
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 if url == nil then
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 url = html_encode(bbcode.contents)
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 %><a href="<%=url%>"><%=url%></a><%
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 else
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 url = html_encode(url)
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
70 %><a href="<%=url%>"><% to_html(bbcode.contents,options) %></a><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
74 function html.code(bbcode,options)
49
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
75 if bbcode.param == "inline" then
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
76 %><code inline><%= html_encode(bbcode.contents) %></code><%
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
77 else
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
78 local s = starting_cr_regex.gsub(bbcode.contents,"")
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
79 %><code><%= html_encode(s) %></code><%
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
80 options.strip_newline = true
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
81 end
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
84 function html.img(bbcode,options)
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
85 %><img src="<%= html_encode(bbcode.contents) %>"<%
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
86 if bbcode.param ~= nil then
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
87 %> width="<%=bbcode.param%>"<%
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
88 end
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
89 %>><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
92 function html.color(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
93 %><span style="color:<%=bbcode.param%>"><% to_html(bbcode.contents,options) %></span><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
96 function html.size(bbcode,options)
23
cdcd1b70c15e tinymce work
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
97 %><span style="font-size:<%=bbcode.param%>"><% to_html(bbcode.contents,options) %></span><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
100 function html.quote(bbcode,options)
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101 %><blockquote><%
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
102 local user_name = bbcode.param
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
103 if user_name ~= nil then
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
104 local user = User.get_by_name(user_name)
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
105 if user == nil then
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106 %><%= user_name %> wrote:<%
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107 else
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 %><a href="/user_something"><%= user_name %></a> wrote:<%
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 end
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
110 else
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
111 options.strip_newline = true
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112 end
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
113 to_html(bbcode.contents,options)
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 %></blockquote><%
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
115 options.strip_newline = true
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
118 local function video_iframe(url)
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
119 %><iframe width="560" height="315" frameborder="0" allowfullscreen src="<%=url%>"></iframe><%
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
120 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
121
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
122 local video_urls = {
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
123 [[\.mp4$]]
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
124 }
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
125 local video_handlers = {}
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
126 local function regex_video(s)
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
127 video_urls[#video_urls+1] = s
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
128 return regex(s)
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
129 end
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
130 do
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
131 local ptn1 = regex_video[[^\Qhttps://youtu.be/\E([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?]]
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
132 local ptn2 = regex_video[[^\Qhttps://www.youtube.com/watch?v=\E([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
133 function video_handlers.youtube(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
134 local id, start = ptn1.match(url)
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
135 if id == nil then
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
136 id, start = ptn2.match(url)
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
137 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
138 if id == nil then
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
139 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
140 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
141 url = "https://www.youtube.com/embed/"..id
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
142 if start ~= nil then
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
143 url = url.."?start="..start
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
144 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
145 video_iframe(url)
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
146 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
147 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
148 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
149 do
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
150 local ptn = regex_video[[^\Qhttps://rumble.com/embed/\E[a-z0-9]+/\?pub=[a-z0-9]+]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
151 function video_handlers.rumble(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
152 if not ptn.matches(url) then
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
153 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
154 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
155 video_iframe(url)
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
156 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
157 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
158 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
159 do
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
160 local ptn = regex_video[[^\Qhttps://www.bitchute.com/video/\E([a-zA-Z0-9]+)/]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
161 function video_handlers.bitchute(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
162 local id = ptn.match(url)
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
163 if id == nil then
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
164 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
165 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
166 url = "https://www.bitchute.com/embed/"..id.."/"
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
167 video_iframe(url)
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
168 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
169 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
170 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
171 do
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
172 local ptn = regex_video[[^\Qhttps://vimeo.com/\E([0-9]+)]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
173 function video_handlers.vimeo(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
174 local id = ptn.match(url)
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
175 if id == nil then
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
176 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
177 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
178 url = "https://player.vimeo.com/video/"..id
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
179 video_iframe(url)
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
180 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
181 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
182 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
183 do
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
184 local ptn = regex_video[[^\Qhttps://dai.ly/\E([a-z0-9]+)]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
185 function video_handlers.dailymotion(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
186 local id = ptn.match(url)
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
187 if id == nil then
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
188 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
189 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
190 url = "https://www.dailymotion.com/embed/video/"..id
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
191 video_iframe(url)
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
192 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
193 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
194 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
195 do
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
196 local ptn = regex_video[[^\Qhttps://www.tiktok.com/\E[^/]+/video/([0-9]+)]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
197 function video_handlers.tiktok(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
198 local id = ptn.match(url)
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
199 if id == nil then
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
200 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
201 end
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
202 %><iframe allowfullscreen scrolling="no" width="325" height="720" src="https://www.tiktok.com/embed/<%=id%>"></iframe><%
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
203 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
204 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
205 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
206 do
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
207 local ptn = regex[[\.[a-zA-Z0-9]+$]]
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
208 function video_handlers.file(url)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
209 if not ptn.matches(url) then
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
210 return false
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
211 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
212 %><video controls width="560"><source src="<%=html_encode(url)%>"></video><%
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
213 return true
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
214 end
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
215 end
23
cdcd1b70c15e tinymce work
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
216
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
217 local video_regex = regex(concat(video_urls,"|"))
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
218
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
219 function html.video(bbcode,options)
23
cdcd1b70c15e tinymce work
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
220 local url = bbcode.contents
28
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
221 for _, handle in pairs(video_handlers) do
d9d7aa2a79db more video types
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
222 if handle(url) then return end
27
6871eec2cf4c add rumble
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
223 end
23
cdcd1b70c15e tinymce work
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
224 url = html_encode(url)
cdcd1b70c15e tinymce work
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
225 %><a href="<%=url%>"><%=url%></a><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
228 local function list_to_html(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
229 local list = to_list(bbcode.contents)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
230 for _, item in ipairs(list) do
48
4e1a01db19ec add lists
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
231 if type(item) == "table" and item.name == "item" then
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
232 %><li><% to_html(item.contents,options) %></li><%
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
233 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
234 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
235 options.strip_newline = true
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
236 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
237
48
4e1a01db19ec add lists
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
238 function html.list(bbcode,options)
4e1a01db19ec add lists
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
239 local tag = bbcode.param == "1" and "ol" or "ul"
4e1a01db19ec add lists
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
240 %><<%=tag%>><%
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
241 list_to_html(bbcode,options)
48
4e1a01db19ec add lists
Franklin Schmidt <fschmidt@gmail.com>
parents: 45
diff changeset
242 %></<%=tag%>><%
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
243 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
244
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
245 function to_html(bbcode,options)
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
246 if options.strip_newline then
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
247 if type(bbcode) == "string" then
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
248 bbcode = starting_cr_regex.gsub(bbcode,"")
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
249 end
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
250 options.strip_newline = false
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
251 end
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
252 if type(bbcode) == "string" then
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
253 %><%= html_encode(bbcode) %><%
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
254 else
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
255 type(bbcode) == "table" or error()
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
256 if is_list(bbcode) then
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
257 for _, v in ipairs(bbcode) do
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
258 to_html(v,options)
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
259 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
260 else
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
261 local fn = html[bbcode.name] or error(bbcode.name.." not handled")
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
262 fn(bbcode,options)
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
263 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
264 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
266
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267 function Bbcode.to_html(bbcode)
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
268 bbcode = bbcode_parse(bbcode)
49
f225e82b2bf8 add code bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
269 %><div from_bbcode><%
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
270 to_html(bbcode,{strip_newline=false})
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
271 %></div><%
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
272 end
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
274
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
275 local doesnt_nest = list_to_set{
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
276 "url"
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
277 "code"
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
278 "img"
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
279 "video"
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
280 }
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
281
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
282 local url_regex = regex[[(^|\s)(https?://\S+)]]
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
283 local img_regex
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
284 do
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
285 local endings = {
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
286 "jpg"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
287 "jpeg"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
288 "png"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
289 "gif"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
290 "svg"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
291 }
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
292 local t = {}
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
293 for _, ending in ipairs(endings) do
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
294 t[#t+1] = [[\.]]..ending..[[$]]
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
295 end
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
296 img_regex = regex(concat(t,"|"))
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
297 end
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
298
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
299 local function preprocess(bbcode)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
300 if type(bbcode) == "string" then
53
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
301 bbcode = url_regex.gsub( bbcode, function(prefix,url)
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
302 if video_regex.matches(url) then
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
303 return prefix.."[video]"..url.."[/video]"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
304 elseif img_regex.matches(url) then
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
305 return prefix.."[img]"..url.."[/img]"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
306 else
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
307 return prefix.."[url]"..url.."[/url]"
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
308 end
cac477dd1f82 convert image and video urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 49
diff changeset
309 end )
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
310 %><%= bbcode %><%
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
311 else
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
312 type(bbcode) == "table" or error()
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
313 if is_list(bbcode) then
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
314 for _, v in ipairs(bbcode) do
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
315 preprocess(v)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
316 end
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
317 else
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
318 local name = bbcode.name
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
319 local param = bbcode.param
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
320 %>[<%=name%><%
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
321 if param ~= nil then
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
322 %>=<%=param%><%
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
323 end
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
324 %>]<%
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
325 if doesnt_nest[name] then
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
326 %><%=bbcode.contents%><%
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
327 else
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
328 preprocess(bbcode.contents)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
329 end
20
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
330 if name == "code" and param ~= nil then
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
331 %>[/<%=name%>=<%=param%>]<%
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
332 else
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
333 %>[/<%=name%>]<%
3ea49246d6a7 bbcode work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
334 end
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
335 end
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
336 end
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
337 end
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
338
43
298c71e0c854 caching
Franklin Schmidt <fschmidt@gmail.com>
parents: 30
diff changeset
339 -- url handling
13
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
340 function Bbcode.preprocess(bbcode)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
341 bbcode = bbcode_parse(bbcode)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
342 return output_of(function()
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
343 preprocess(bbcode)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
344 end)
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
345 end
24668255cede preprocess urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
346
21
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
347 function Bbcode.remove_html(text)
29
a1db5223ced1 luan changes
Franklin Schmidt <fschmidt@gmail.com>
parents: 28
diff changeset
348 local ends_with_newline = ends_with(text,"\n")
21
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
349 local t = {}
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
350 local html = html_parse(text)
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
351 local is_first = true
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
352 for _, v in ipairs(html) do
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
353 if type(v) == "string" then
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
354 t[#t+1] = v
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
355 else
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
356 local name = v.name
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
357 if name == "div" then
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
358 if not is_first then
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
359 t[#t+1] = "\n"
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
360 end
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
361 elseif name == "/div" or name == "br" then
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
362 -- ignore
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
363 else
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
364 error("unexpected tag: "..name)
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
365 end
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
366 end
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
367 is_first = false
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
368 end
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
369 if not ends_with_newline then
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
370 t[#t+1] = "\n"
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
371 end
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
372 return concat(t)
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
373 end
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
374
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
375
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
376 return Bbcode