annotate env/format/wiki_text.lua @ 1517:4f182720a2ec
Automatically fix inconsistent session cookies
author |
bsw |
date |
Thu Aug 20 14:25:34 2020 +0200 (2020-08-20) |
parents |
701a5cf6b067 |
children |
|
rev |
line source |
bsw/jbe@4
|
1 function format.wiki_text(wiki_text, formatting_engine)
|
bsw@1045
|
2
|
bsw@1045
|
3 if not formatting_engine then
|
bsw@1045
|
4 error("Formatting engine identifier required")
|
bsw@1045
|
5 end
|
bsw@1045
|
6
|
bsw@1045
|
7 local fe
|
bsw@1045
|
8
|
bsw@1045
|
9 for i, fe_entry in ipairs(config.formatting_engines) do
|
bsw@1045
|
10 if fe_entry.id == formatting_engine then
|
bsw@1045
|
11 fe = fe_entry
|
bsw@1045
|
12 break
|
bsw@1045
|
13 end
|
bsw@1045
|
14 end
|
bsw@1045
|
15
|
bsw@1045
|
16 if not fe then
|
bsw@1045
|
17 error("Formatting engine not found")
|
bsw@1045
|
18 end
|
bsw@1045
|
19
|
bsw@2
|
20 local html, errmsg, exitcode = assert(
|
bsw@1045
|
21 extos.pfilter(wiki_text, fe.executable, table.unpack(fe.args or {}))
|
bsw@2
|
22 )
|
bsw@1045
|
23
|
bsw@2
|
24 if exitcode > 0 then
|
bsw@1045
|
25 trace.debug(html, errmsg)
|
bsw@2
|
26 error("Wiki parser process returned with error code " .. tostring(exitcode))
|
bsw@2
|
27 elseif exitcode < 0 then
|
bsw@1045
|
28 trace.debug(html, errmsg)
|
bsw@2
|
29 error("Wiki parser process was terminated by signal " .. tostring(-exitcode))
|
bsw@2
|
30 end
|
bsw@1045
|
31
|
bsw@1045
|
32 if fe.remove_images then
|
bsw@1045
|
33 html = string.gsub(html, '<img [^>]*>', '')
|
bsw@1045
|
34 end
|
bsw@1045
|
35
|
bsw@2
|
36 return html
|
bsw@1045
|
37
|
bsw@2
|
38 end
|