def run(self): view = self.window.active_view() if not view: return file_name = view.file_name() if not file_name: return contents = view.substr(sublime.Region(0, view.size())) md = markdown_python.markdown(contents) html = '<html><meta charset="UTF-8">' css = os.path.join(sublime.packages_path(), 'MarkdownBuild', 'markdown.css') if (os.path.isfile(css)): styles = open(css, 'r').read() html += '<style>' + styles + '</style>' html += "<body>" html += md html += "</body></html>" s = sublime.load_settings("Preferences.sublime-settings") output_in_same_dir = s.get("markdownbuild_output_same_dir", 0) if output_in_same_dir: path = os.path.dirname(file_name) file_name = os.path.basename(file_name) base_name = os.path.splitext(file_name)[0] html_file = path + "/" + base_name + ".html" f = open(html_file, 'w') f.write(html.encode('UTF-8')) f.close() webbrowser.open("file://" + html_file) else: output = tempfile.NamedTemporaryFile(delete=False, suffix='.html') output.write(html.encode('UTF-8')) output.close() webbrowser.open("file://" + output.name)
def run(self): #hwnd = sublime.active_window().hwnd() s = sublime.load_settings("MarkdownBuild.sublime-settings") output_html = s.get("output_html", False) open_html_in = s.get("open_html_in", "browser") use_css = s.get("use_css", True) charset = s.get("charset", "UTF-8") markdown_extensions = s.get("extensions", []) markdown_version = s.get("markdown_implementation", 2) # Default version [1] view = self.window.active_view() if not view: return file_name = view.file_name() if not file_name: return contents = view.substr(sublime.Region(0, view.size())) # Use the proper markdown version if(markdown_version == 2): md = markdown2.markdown(contents, extras=markdown_extensions) elif (markdown_version == 1): md = markdown.markdown(contents) else: # Invalid Version Number, notify user to update the sublime-settings file sublime.message_dialog("The markdown version in \"MarkdownBuild.sublime-settings\" is invalid.\nAvailable versions: 1, 2") return html = '<html><meta charset="' + charset + '">' if use_css: css = os.path.join(sublime.packages_path(), 'MarkdownBuild', 'markdown.css') if (os.path.isfile(css)): styles = open(css, 'r').read() html += '<style>' + styles + '</style>' html += "<body>" + md + "</body></html>" if output_html: html_name = os.path.splitext(file_name)[0] html_name = html_name + ".html" output = open(html_name, 'w') else: output = tempfile.NamedTemporaryFile(delete=False, suffix='.html') output.write(html.encode('UTF-8')) output.close() if open_html_in == "both": webbrowser.open("file://" + output.name) self.window.open_file(output.name) elif open_html_in == "sublime": self.window.open_file(output.name) else: webbrowser.open("file://" + output.name)
def run(self): #hwnd = sublime.active_window().hwnd() s = sublime.load_settings("MarkdownBuild.sublime-settings") output_html = s.get("output_html", False) open_html_in = s.get("open_html_in", "browser") use_css = s.get("use_css", True) charset = s.get("charset", "UTF-8") file_path = s.get("file_path","c:\\") output_same_dir = s.get("output_same_dir", False) view = self.window.active_view() if not view: return file_name = view.file_name() if not file_name: return contents = view.substr(sublime.Region(0, view.size())) md = markdown_python.markdown(contents) html = '<html><meta charset="' + charset + '">' if use_css: css = os.path.join(sublime.packages_path(), 'MarkdownBuild', 'markdown.css') if (os.path.isfile(css)): styles = open(css, 'r').read() html += '<style>' + styles + '</style>' html += "<body>" + md + "</body></html>" if output_html: if output_same_dir: html_name = os.path.splitext(file_name)[0] html_name = html_name + ".html" output = open(html_name, 'w') else: html_name = os.path.splitext(file_name)[0] fn = html_name.split("\\") html_name = fn[len(fn)-1] + ".html" output = open(file_path+html_name, 'w') else: output = tempfile.NamedTemporaryFile(delete=False, suffix='.html') output.write(html.encode('UTF-8')) output.close() if open_html_in == "both": webbrowser.open("file://" + output.name) self.window.open_file(output.name) elif open_html_in == "sublime": self.window.open_file(output.name) else: webbrowser.open("file://" + output.name)
def run(self): #hwnd = sublime.active_window().hwnd() s = sublime.load_settings("MarkdownBuild.sublime-settings") output_html = s.get("output_html", False) open_html_in = s.get("open_html_in", "browser") use_css = s.get("use_css", True) charset = s.get("charset", "UTF-8") view = self.window.active_view() if not view: return file_name = view.file_name() if not file_name: return contents = view.substr(sublime.Region(0, view.size())) md = markdown_python.markdown(contents) html = '<html><meta charset="' + charset + '">' if use_css: css = os.path.join(sublime.packages_path(), 'MarkdownBuild', 'markdown.css') if (os.path.isfile(css)): styles = open(css, 'r').read() html += '<style>' + styles + '</style>' html += "<body>" + md + "</body></html>" if output_html: html_name = os.path.splitext(file_name)[0] html_name = html_name + ".html" output = open(html_name, 'w') else: output = tempfile.NamedTemporaryFile(delete=False, suffix='.html') output.write(html.encode('UTF-8')) output.close() if open_html_in == "both": webbrowser.open("file://" + output.name) self.window.open_file(output.name) elif open_html_in == "sublime": self.window.open_file(output.name) else: webbrowser.open("file://" + output.name)