-
-
Save codeslubber/6528201 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sublime | |
import sublime_plugin | |
import webbrowser | |
REG_RENAME = re.compile("\.(asciidoc|adoc|asc|ad)$") | |
EXT = re.compile(".*\.(asciidoc|adoc|asc|ad)$") | |
COMMAND = "asciidoctor -b html5" | |
def is_asciidoc_file(file_name): | |
return EXT.match(file_name) is not None | |
class AsciidocSaveListener(sublime_plugin.EventListener): | |
def on_post_save(self, view): | |
file_name = view.file_name() | |
if is_asciidoc_file(file_name): | |
sublime.status_message("Asciidoctor regenerating " + file_name) | |
self.run_shell_command(view, COMMAND + " " + file_name) | |
def run_shell_command(self, view, command): | |
if not command: | |
return False | |
view.window().run_command("exec", { | |
"cmd": [command], | |
"shell": True, | |
"quiet": True | |
}) | |
return True | |
class AsciidocBrowserCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
file_name = self.view.file_name() | |
if is_asciidoc_file(file_name): | |
webbrowser.open_new(REG_RENAME.sub('.html', file_name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{"keys": ["super+a"], "command": "asciidoc_browser" } | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment