forked from SublimeText-Markdown/MarkdownEditing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.py
158 lines (114 loc) · 4.89 KB
/
bootstrap.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import sys
import sublime
import sublime_plugin
import re
try:
from MarkdownEditing.mdeutils import *
except ImportError:
from mdeutils import *
package_name = 'MarkdownEditing'
def get_ingored_packages():
settings = sublime.load_settings('Preferences.sublime-settings')
return settings.get('ignored_packages', [])
def save_ingored_packages(ignored_packages):
settings = sublime.load_settings('Preferences.sublime-settings')
settings.set('ignored_packages', ignored_packages)
sublime.save_settings('Preferences.sublime-settings')
def disable_native_markdown_package():
ignored_packages = get_ingored_packages()
if 'Markdown' not in ignored_packages:
ignored_packages.append('Markdown')
save_ingored_packages(ignored_packages)
def enable_native_markdown_package():
ignored_packages = get_ingored_packages()
if 'Markdown' in ignored_packages:
ignored_packages.remove('Markdown')
save_ingored_packages(ignored_packages)
def choose_color_theme(window):
window = window or sublime.active_window()
view = window.new_file()
view.run_command('append', {'characters': '''# A sample Markdown document
This is a sample document so you can preview the color themes.
## I am a second-level header
Markdown supports _italics_, __bold__, and ___bold italics___ style.
There are also inline styles like `inline code in monospace font` and ~~strikethrough style~~. __There may be ~~strikethroughed text~~ or `code text` inside bold text.__ _And There may be ~~strikethroughed text~~ or `code text` inside italic text._
To reference something from a URL, [Named Links][links] and [Inline links](https://example.com/index.html) are of great help. Sometimes ![A picture][sample image] is worth a thousand words.
There are two types of lists, numbered and unnumbered.
1. Item 1
2. Item 2
3. Item 3
* Item A
- Sub list
+ Sub sub list
+ Sub sub list 2
- Sub list 2
* Item B
* Item C
## Fenced code
You can write fenced code inside three backticks.
```javascript
function fibo(n) {
fibo.mem = fibo.mem || []; // I am some comment
return fibo.mem[n] || fibo.mem[n] = n <= 1 ? 1 : fibo(n - 1) + fibo(n - 2);
}
```
## The following section is used to define named links
[links]: https://example.com/index.html
[sample image]: https://example.com/sample.png
## Wiki links
This [[SamplePage]] is a wiki link
---
'''})
view.set_syntax_file('Packages/MarkdownEditing/Markdown.tmLanguage')
default_mde_scheme = sublime.load_settings('Markdown.sublime-settings').get('color_scheme') or 'Packages/MarkdownEditing/MarkdownEditor.tmTheme'
print(default_mde_scheme)
view.settings().set('color_scheme', default_mde_scheme)
view.set_read_only(True)
view.set_scratch(True)
global_scheme = sublime.load_settings('Preferences.sublime-settings').get('color_scheme')
themes = ['Packages/MarkdownEditing/MarkdownEditor.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-Focus.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-Yellow.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-Dark.tmTheme',
'Packages/MarkdownEditing/MarkdownEditor-ArcDark.tmTheme',
global_scheme]
themes_display = [re.search('[^/]+(?=\.tmTheme$)', s).group(0) + (' (Current)' if s == default_mde_scheme else '') + (' (Global)' if s == global_scheme else '') for s in themes]
def set_scheme(scheme):
view.settings().set('color_scheme', scheme)
sublime.load_settings('Markdown.sublime-settings').set('color_scheme', scheme)
def on_done(index):
if index == -1:
set_scheme(default_mde_scheme)
elif index == len(themes) - 1:
set_scheme(global_scheme)
else:
set_scheme(themes[index])
sublime.save_settings('Markdown.sublime-settings')
view.close()
def on_highlighted(index):
if index == len(themes) - 1:
set_scheme(global_scheme)
else:
set_scheme(themes[index])
window.show_quick_panel(themes_display, on_done, flags=sublime.KEEP_OPEN_ON_FOCUS_LOST, on_highlight=on_highlighted)
def plugin_loaded():
if "package_control" in sys.modules:
from package_control import events
if events.install(package_name):
# Native package causes some conflicts.
disable_native_markdown_package()
# Prmopts to select a color theme
choose_color_theme()
def plugin_unloaded():
if "package_control" in sys.modules:
from package_control import events
if events.remove(package_name):
# Native package causes some conflicts.
enable_native_markdown_package()
# Compat with ST2
if sys.version_info < (3,):
plugin_loaded()
unload_handler = plugin_unloaded
class MdeColorActivateCommand(MDETextCommand):
def run(self, edit):
choose_color_theme(self.view.window())