-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMarkdownSlideshow.py
71 lines (57 loc) · 2.13 KB
/
MarkdownSlideshow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sublime
import sublime_plugin
import os
import sys
import tempfile
import webbrowser
def is_v3():
return sys.version_info >= (3, 0)
if is_v3():
from .lib.mcider import converter
from .lib.mcider import util
else:
from lib.mcider import converter
from lib.mcider import util
class MarkdownSlideshowCommand(sublime_plugin.TextCommand):
""" slideshow in your web browser from file contents """
def run(self, edit):
settings = sublime.load_settings('MarkdownSlideshow.sublime-settings')
themes = settings.get('themes', None)
theme = settings.get('theme', 'io2012')
extensions = settings.get('extensions', [])
output_file = settings.get('output_file', None)
clean = settings.get('clean', False)
browser = settings.get('browser', True)
presenter = settings.get('presenter', False)
# slide options
opts = {
'themes': themes,
'theme': theme,
'contents': self.view.substr(sublime.Region(0, self.view.size())),
'extensions': extensions,
'clean': clean
}
# custom themes or default themes
if opts['themes'] is None or not os.path.isdir(opts['themes']):
pkg_path = os.path.abspath(os.path.dirname(__file__))
opts['themes'] = os.path.join(pkg_path, 'themes')
# path of the output file
if output_file is None:
output_path = None
else:
output_path = os.path.abspath(os.path.dirname(output_file))
if not os.path.isdir(output_path):
output_path = None
if output_path is None:
output_path = tempfile.mkdtemp()
output_file = os.path.join(output_path, 'slide.html')
# slide maker
slide = converter.Slide(opts)
html = slide.maker(output_path)
util.fs_writer(output_file, html)
if browser:
url = 'file://' + output_file
if slide.options['theme'] == 'io2012':
url += '?presentme='
url += 'true' if presenter else 'false'
webbrowser.open_new_tab(url)