Skip to content

Instantly share code, notes, and snippets.

@codeslubber
Forked from aslakknutsen/Asciidoctor.py
Created September 11, 2013 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeslubber/6528201 to your computer and use it in GitHub Desktop.
Save codeslubber/6528201 to your computer and use it in GitHub Desktop.
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))
[
{"keys": ["super+a"], "command": "asciidoc_browser" }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment