def md2html(text, work_full_path = None, static_file_prefix = None): assert text is not None buf = text if work_full_path and tex2png: try: buf = trac_wiki_tex2md(buf, save_to_prefix = work_full_path) except Exception: msg = "it seems that latex or dvipng doesn't works well on your box, or source code is invalid" sys.stderr.write("\n" + msg + "\n") buf = text if work_full_path and dot2png: try: buf = trac_wiki_dot2md(buf, save_to_prefix = work_full_path) except Exception: msg = "it seems that graphviz doesn't works well on your box, or source code is invalid" sys.stderr.write("\n" + msg + "\n") buf = text if static_file_prefix: buf = convert_static_file_url(buf, static_file_prefix) buf = md_table.md_table2html(buf) buf = code_block_to_md_code(buf) buf = trac_wiki_code_block_to_md_code(buf) buf = markdown.markdown(buf) return buf
def md2html(config_agent, req_path, text, **view_settings): folder_pages_full_path = config_agent.get_full_path("paths", "pages_path") req_full_path = req_path_to_local_full_path(req_path = req_path, folder_pages_full_path = folder_pages_full_path) static_file_prefix = os.path.dirname(req_full_path) buf = text if tex2png: try: buf = macro_tex2md(buf, save_to_prefix = static_file_prefix, **view_settings) except Exception: msg = "it seems that latex or dvipng doesn't works well on your box, or source code is invalid" sys.stderr.write("\n" + msg + "\n") buf = text if graphviz2png: try: buf = macro_graphviz2md(buf, save_to_prefix = static_file_prefix, **view_settings) except Exception: msg = "it seems that graphviz doesn't works well on your box, or source code is invalid" sys.stderr.write("\n" + msg + "\n") buf = text if static_file_prefix: buf = convert_static_file_url(buf, static_file_prefix) buf = zw_macro2md(buf, folder_pages_full_path = folder_pages_full_path, **view_settings) buf = md_table.md_table2html(buf) buf = code_block_to_md_code(buf) buf = trac_wiki_code_block_to_md_code(buf) buf = markdown.markdown(buf) return buf
try: buf = macro_graphviz2md(buf, save_to_prefix = save_to_prefix, **view_settings) except Exception, ex: logging.error(str(ex)) msg = "it seems that graphviz doesn't works well on your box, or source code is invalid" logging.error(msg) buf = text if static_file_prefix: buf = convert_static_file_url(buf, static_file_prefix) buf = zw_macro2md(buf, folder_pages_full_path = folder_pages_full_path, req_path = req_path, **view_settings) buf = md_table.md_table2html(buf) buf = code_block_to_md_code(buf) buf = trac_wiki_code_block_to_md_code(buf) buf = markdown.markdown(buf) return buf def test_path2hierarchy(): for i in [ ("/", [("index", "/~index")]), # name, link pairs ("/system-management/gentoo/abc", [("system-management", "/system-management"),("gentoo", "/system-management/gentoo"),("abc", "/system-management/gentoo/abc"),]),