annotate src/bbcode/preview.js.luan @ 60:8b5b1bce7d6b

bcode menus
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 30 Nov 2022 23:50:52 -0700
parents 9f8ebc757814
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Parsers = require "luan:Parsers.luan"
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local json_string = Parsers.json_string or error()
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local output_of = Io.output_of or error()
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Bbcode = require "site:/bbcode/Bbcode.luan"
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
9 local preprocess = Bbcode.preprocess or error()
51
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local bbcode_to_html = Bbcode.to_html or error()
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 return function()
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local text = Http.request.parameters.text or error()
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
15 local convert_urls = Http.request.parameters.convert_urls or error()
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
16 if convert_urls == "true" then
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
17 text = preprocess(text)
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
18 end
51
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local html = output_of(function() bbcode_to_html(text) end)
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 Io.stdout = Http.response.text_writer()
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 %>
52
9f8ebc757814 add convert urls
Franklin Schmidt <fschmidt@gmail.com>
parents: 51
diff changeset
22 context.preview( <%= json_string(text) %>, <%= json_string(html) %> );
51
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 <%
78b2d6995244 add preview
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 end