Mercurial Hosting > freedit
view src/save_edit.js.luan @ 22:d87a8f9f43d7
tinymce work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 17 Jul 2022 21:47:55 -0600 |
parents | 33731231093a |
children | 66fd3784e60e |
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 Post = require "site:/lib/Post.luan" local Bbcode = require "site:/lib/Bbcode.luan" local remove_html = Bbcode.remove_html or error() local bbcode_to_html = Bbcode.to_html or error() local Db = require "site:/lib/Db.luan" return function() local post = Http.request.parameters.post or error() local text = Http.request.parameters.text or error() text = remove_html(text) Db.run_in_transaction( function() post = Post.get_by_id(post) or error() post.author_is_current() or error() post.content = text post.save() end ) local html = output_of(function() bbcode_to_html(post.content) end) Io.stdout = Http.response.text_writer() %> let postDiv = document.querySelector('[post="<%=post.id%>"]'); cancelEdit(postDiv); postDiv.querySelector('[message]').innerHTML = <%= json_string(html) %>; <% end