comparison src/bbcode/preview.js.luan @ 52:9f8ebc757814

add convert urls
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 23 Nov 2022 23:29:16 -0700
parents 78b2d6995244
children
comparison
equal deleted inserted replaced
51:78b2d6995244 52:9f8ebc757814
4 local json_string = Parsers.json_string or error() 4 local json_string = Parsers.json_string or error()
5 local Io = require "luan:Io.luan" 5 local Io = require "luan:Io.luan"
6 local output_of = Io.output_of or error() 6 local output_of = Io.output_of or error()
7 local Http = require "luan:http/Http.luan" 7 local Http = require "luan:http/Http.luan"
8 local Bbcode = require "site:/bbcode/Bbcode.luan" 8 local Bbcode = require "site:/bbcode/Bbcode.luan"
9 local preprocess = Bbcode.preprocess or error()
9 local bbcode_to_html = Bbcode.to_html or error() 10 local bbcode_to_html = Bbcode.to_html or error()
10 11
11 12
12 return function() 13 return function()
13 local text = Http.request.parameters.text or error() 14 local text = Http.request.parameters.text or error()
15 local convert_urls = Http.request.parameters.convert_urls or error()
16 if convert_urls == "true" then
17 text = preprocess(text)
18 end
14 local html = output_of(function() bbcode_to_html(text) end) 19 local html = output_of(function() bbcode_to_html(text) end)
15 Io.stdout = Http.response.text_writer() 20 Io.stdout = Http.response.text_writer()
16 %> 21 %>
17 context.preview(<%= json_string(html) %>); 22 context.preview( <%= json_string(text) %>, <%= json_string(html) %> );
18 <% 23 <%
19 end 24 end