Mercurial Hosting > freedit
comparison src/lib/Bbcode.luan @ 21:33731231093a
fix bbcode editing
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 17 Jul 2022 08:24:52 -0600 |
parents | 3ea49246d6a7 |
children | cdcd1b70c15e |
comparison
equal
deleted
inserted
replaced
20:3ea49246d6a7 | 21:33731231093a |
---|---|
7 local output_of = Io.output_of or error() | 7 local output_of = Io.output_of or error() |
8 local Parsers = require "luan:Parsers.luan" | 8 local Parsers = require "luan:Parsers.luan" |
9 local bbcode_parse = Parsers.bbcode_parse or error() | 9 local bbcode_parse = Parsers.bbcode_parse or error() |
10 local Html = require "luan:Html.luan" | 10 local Html = require "luan:Html.luan" |
11 local html_encode = Html.encode or error() | 11 local html_encode = Html.encode or error() |
12 local html_parse = Html.parse or error() | |
12 local Table = require "luan:Table.luan" | 13 local Table = require "luan:Table.luan" |
13 local is_list = Table.is_list or error() | 14 local is_list = Table.is_list or error() |
15 local concat = Table.concat or error() | |
14 local String = require "luan:String.luan" | 16 local String = require "luan:String.luan" |
15 local gsub = String.gsub or error() | 17 local gsub = String.gsub or error() |
18 local matches = String.matches or error() | |
16 local User = require "site:/lib/User.luan" | 19 local User = require "site:/lib/User.luan" |
17 local Shared = require "site:/lib/Shared.luan" | 20 local Shared = require "site:/lib/Shared.luan" |
18 local list_to_set = Shared.list_to_set or error() | 21 local list_to_set = Shared.list_to_set or error() |
19 local to_list = Shared.to_list or error() | 22 local to_list = Shared.to_list or error() |
20 local Logging = require "luan:logging/Logging.luan" | 23 local Logging = require "luan:logging/Logging.luan" |
210 return output_of(function() | 213 return output_of(function() |
211 preprocess(bbcode) | 214 preprocess(bbcode) |
212 end) | 215 end) |
213 end | 216 end |
214 | 217 |
218 function Bbcode.remove_html(text) | |
219 local ends_with_newline = matches(text,[[\n$]]) | |
220 local t = {} | |
221 local html = html_parse(text) | |
222 local is_first = true | |
223 for _, v in ipairs(html) do | |
224 if type(v) == "string" then | |
225 t[#t+1] = v | |
226 else | |
227 local name = v.name | |
228 if name == "div" then | |
229 if not is_first then | |
230 t[#t+1] = "\n" | |
231 end | |
232 elseif name == "/div" or name == "br" then | |
233 -- ignore | |
234 else | |
235 error("unexpected tag: "..name) | |
236 end | |
237 end | |
238 is_first = false | |
239 end | |
240 if not ends_with_newline then | |
241 t[#t+1] = "\n" | |
242 end | |
243 return concat(t) | |
244 end | |
245 | |
246 | |
215 return Bbcode | 247 return Bbcode |