My idea is like this: string render_math(string text) { tree parse_tree = parse_and_validate (text); if (parse_tree != NULL) { string new_text = render_tex(parse_tree); string hash = md5(new_text); string file_name = file_prefix + hash; if (file_exists(file_name)) return "<img ... alt=" + htmlattr_escape(text) + ">"; else if (tex_render(new_text, file_name)) return "<img ... alt=" + htmlattr_escape(text) + ">"; else return "<b>Warning: couldn't render: " + wiki_escape(text) + "</b>"; } else { return text; } }
Where: md5() - obvious file_prefix - obvious httmlattr_espace() - obvious wiki_escape() - obvious file_exists() - obvious tex_render() - call external tex rendering program parse_and_validate() - generated LALR parser which checks if TeX is safe. If it doesn't understand it, then it's NOT safe. render_tex() - render TeX string from tree. Place to add all extra features, alternative syntaxes etc. In easiest version just copies first text.
What do you think ?
wikitech-l@lists.wikimedia.org