view src/bbcode/preview.js.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents 9f8ebc757814
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Parsers = require "luan:Parsers.luan"
local json_string = Parsers.json_string or error()
local Io = require "luan:Io.luan"
local output_of = Io.output_of or error()
local Http = require "luan:http/Http.luan"
local Bbcode = require "site:/bbcode/Bbcode.luan"
local preprocess = Bbcode.preprocess or error()
local bbcode_to_html = Bbcode.to_html or error()


return function()
	local text = Http.request.parameters.text or error()
	local convert_urls = Http.request.parameters.convert_urls or error()
	if convert_urls == "true" then
		text = preprocess(text)
	end
	local html = output_of(function() bbcode_to_html(text) end)
	Io.stdout = Http.response.text_writer()
%>
	context.preview( <%= json_string(text) %>, <%= json_string(html) %> );
<%
end