bsw/jbe@4: function format.wiki_text(wiki_text, formatting_engine) bsw@1045: bsw@1045: if not formatting_engine then bsw@1045: error("Formatting engine identifier required") bsw@1045: end bsw@1045: bsw@1045: local fe bsw@1045: bsw@1045: for i, fe_entry in ipairs(config.formatting_engines) do bsw@1045: if fe_entry.id == formatting_engine then bsw@1045: fe = fe_entry bsw@1045: break bsw@1045: end bsw@1045: end bsw@1045: bsw@1045: if not fe then bsw@1045: error("Formatting engine not found") bsw@1045: end bsw@1045: bsw@2: local html, errmsg, exitcode = assert( bsw@1045: extos.pfilter(wiki_text, fe.executable, table.unpack(fe.args or {})) bsw@2: ) bsw@1045: bsw@2: if exitcode > 0 then bsw@1045: trace.debug(html, errmsg) bsw@2: error("Wiki parser process returned with error code " .. tostring(exitcode)) bsw@2: elseif exitcode < 0 then bsw@1045: trace.debug(html, errmsg) bsw@2: error("Wiki parser process was terminated by signal " .. tostring(-exitcode)) bsw@2: end bsw@1045: bsw@1045: if fe.remove_images then bsw@1045: html = string.gsub(html, ']*>', '') bsw@1045: end bsw@1045: bsw@2: return html bsw@1045: bsw@2: end