├── messages
├── 2.0.1.txt
└── 2.0.0.txt
├── messages.json
├── ViewInBrowser.sublime-commands
├── Context.sublime-menu
├── Default (Linux).sublime-keymap
├── Default (OSX).sublime-keymap
├── Default (Windows).sublime-keymap
├── Main.sublime-menu
├── LICENSE
├── View In Browser.sublime-settings
├── README.md
└── ViewInBrowserCommand.py
/messages/2.0.1.txt:
--------------------------------------------------------------------------------
1 | Fixed issue where parenthesis in paths would cause a failure to load.
--------------------------------------------------------------------------------
/messages.json:
--------------------------------------------------------------------------------
1 | {
2 | "2.0.0": "messages/2.0.0.txt",
3 | "2.0.1": "messages/2.0.1.txt"
4 | }
--------------------------------------------------------------------------------
/ViewInBrowser.sublime-commands:
--------------------------------------------------------------------------------
1 | [
2 | { "caption": "View In Browser", "command": "view_in_browser" }
3 | ]
4 |
--------------------------------------------------------------------------------
/Context.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "id": "adampresley",
4 | "command": "view_in_browser",
5 | "caption": "View in Browser"
6 | }
7 | ]
8 |
--------------------------------------------------------------------------------
/messages/2.0.0.txt:
--------------------------------------------------------------------------------
1 | This version is reworked to address issues where Sublime would hang when opening new browser windows. The format for the sublime-settings file is also new and more compact and efficient. Please note that if you had any customization against this they may no longer function. User settings files may need to be redone against the new format.
2 |
3 | I apologize for any inconvenience and thank you for using View In Browser!
--------------------------------------------------------------------------------
/Default (Linux).sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 | { "keys": [ "ctrl+alt+v" ], "command": "view_in_browser" },
3 | { "keys": [ "ctrl+alt+f" ], "command": "view_in_browser", "args": { "browser": "firefox" } },
4 | { "keys": [ "ctrl+alt+c" ], "command": "view_in_browser", "args": { "browser": "chrome" } },
5 | { "keys": [ "ctrl+alt+i" ], "command": "view_in_browser", "args": { "browser": "iexplore" } },
6 | { "keys": [ "ctrl+alt+s" ], "command": "view_in_browser", "args": { "browser": "safari" } }
7 | ]
--------------------------------------------------------------------------------
/Default (OSX).sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 | { "keys": [ "ctrl+alt+v" ], "command": "view_in_browser" },
3 | { "keys": [ "ctrl+alt+f" ], "command": "view_in_browser", "args": { "browser": "firefox" } },
4 | { "keys": [ "ctrl+alt+c" ], "command": "view_in_browser", "args": { "browser": "chrome" } },
5 | { "keys": [ "ctrl+alt+i" ], "command": "view_in_browser", "args": { "browser": "iexplore" } },
6 | { "keys": [ "ctrl+alt+s" ], "command": "view_in_browser", "args": { "browser": "safari" } }
7 | ]
--------------------------------------------------------------------------------
/Default (Windows).sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 | { "keys": [ "ctrl+alt+v" ], "command": "view_in_browser" },
3 | { "keys": [ "ctrl+alt+f" ], "command": "view_in_browser", "args": { "browser": "firefox" } },
4 | { "keys": [ "ctrl+alt+c" ], "command": "view_in_browser", "args": { "browser": "chrome" } },
5 | { "keys": [ "ctrl+alt+i" ], "command": "view_in_browser", "args": { "browser": "iexplore" } },
6 | { "keys": [ "ctrl+alt+s" ], "command": "view_in_browser", "args": { "browser": "safari" } }
7 | ]
--------------------------------------------------------------------------------
/Main.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "caption": "Tools",
4 | "mnemonic": "T",
5 | "id": "tools",
6 | "children": [
7 | {
8 | "command": "view_in_browser",
9 | "caption": "View in Browser"
10 | }
11 | ]
12 | },
13 | {
14 | "caption": "Preferences",
15 | "mnemonic": "n",
16 | "id": "preferences",
17 | "children": [
18 | {
19 | "caption": "Package Settings",
20 | "mnemonic": "P",
21 | "id": "package-settings",
22 | "children": [
23 | {
24 | "caption": "View in Browser",
25 | "children": [
26 | {
27 | "command": "open_file",
28 | "args": {"file": "${packages}/View In Browser/View In Browser.sublime-settings"},
29 | "caption": "Settings – Default"
30 | },
31 | {
32 | "command": "open_file",
33 | "args": {"file": "${packages}/User/View In Browser.sublime-settings"},
34 | "caption": "Settings – User"
35 | },
36 | { "caption": "-" }
37 | ]
38 | }
39 | ]
40 | }
41 | ]
42 | }
43 | ]
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2012 Adam Presley
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5 | to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 |
8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 |
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
13 | IN THE SOFTWARE.
--------------------------------------------------------------------------------
/View In Browser.sublime-settings:
--------------------------------------------------------------------------------
1 | {
2 | "posix": {
3 | "linux": {
4 | "firefox": "firefox -new-tab",
5 | "chrome": "google-chrome",
6 | "chrome64": "google-chrome",
7 | "chromium": "chromium"
8 | },
9 | "linux2": {
10 | "firefox": "firefox -new-tab",
11 | "chrome": "google-chrome",
12 | "chrome64": "google-chrome",
13 | "chromium": "chromium"
14 | },
15 | "darwin": {
16 | "firefox": "open -a \"/Applications/Firefox.app\"",
17 | "safari": "open -a \"/Applications/Safari.app\"",
18 | "chrome": "open -a \"/Applications/Google Chrome.app\"",
19 | "chrome64": "open -a \"/Applications/Google Chrome.app\"",
20 | "yandex": "open -a \"/Applications/Yandex.app\""
21 | }
22 | },
23 | "nt": {
24 | "win32": {
25 | "firefox": "C:\\Program Files\\Mozilla Firefox\\firefox.exe -new-tab",
26 | "iexplore": "C:\\Program Files\\Internet Explorer\\iexplore.exe",
27 | "chrome": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
28 | "chrome64": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
29 | "yandex": "%Local AppData%\\Yandex\\YandexBrowser\\browser.exe"
30 | }
31 | },
32 |
33 | "browser": "firefox"
34 | }
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sublime Text - View In Browser
2 |
3 | *View In Browser* is a Sublime Text plugin that will open whatever is in your
4 | current view/tab. If the file current open is new and has not been saved a temporary file is created (in your default temp directory for your OS) with the extension of **.htm** and your browser will open it. However if the current open file is saved and has a name this plugin will open it in whatever you have set to handle its type.
5 |
6 | By default the keystroke assigned to this plugin is *CTRL + ALT + V*.
7 |
8 | ## Installation
9 | Using the Sublime Text Package Control plugin (http://wbond.net/sublime_packages/package_control) press *CTRL + SHIFT + P* and find **Package Control: Install Package** and press *Enter*. Find this plugin in the list by name **View In Browser**.
10 |
11 | ## Configuring Browsers
12 | By default this plugin will open files in Firefox. You can configure it to open
13 | using another browser of your choice. To do this, choose *Settings - User* from *Preferences > Package Settings > View In Browser*.
14 |
15 | The browser you wish to use to open files is set in the key named **browser**. The following is a list of browsers configured for use out of the box.
16 |
17 | * Firefox - Mac OS, Linux, Windows
18 | * Chrome - Mac OS, Linux, Windows
19 | * Chrome64 - Windows
20 | * Yandex - Windows
21 | * Safari - Mac OS
22 | * Internet Explorer - Windows
23 | * Chromium - Linux
24 |
25 | ## Other Browsers
26 | View In Browser also provides key bindings to open your current view in browser other than your **browser** setting. Below is a listing of the keys and what browser open with those key bindings.
27 |
28 | * *CTRL + ALT + F* - Firefox
29 | * *CTRL + ALT + C* - Chrome
30 | * *CTRL + ALT + I* - Internet Explorer
31 | * *CTRL + ALT + S* - Safari
32 |
33 | Like any other key binding in Sublime these can be changed. Below is an example of the key configuration. You can remap these in your User key bindings configuration file.
34 |
35 | ```javascript
36 | [
37 | { "keys": [ "ctrl+alt+v" ], "command": "view_in_browser" },
38 | { "keys": [ "ctrl+alt+f" ], "command": "view_in_browser", "args": { "browser": "firefox" } },
39 | { "keys": [ "ctrl+alt+c" ], "command": "view_in_browser", "args": { "browser": "chrome" } },
40 | { "keys": [ "ctrl+alt+i" ], "command": "view_in_browser", "args": { "browser": "iexplore" } },
41 | { "keys": [ "ctrl+alt+s" ], "command": "view_in_browser", "args": { "browser": "safari" } }
42 | ]
43 | ```
44 |
45 | ### Windows Considerations
46 | One of the things you may notice in the Windows configuration for *chrome* is a variable in the command path that looks like: **%Local AppData%**. This is a reference to your Windows installation's **AppData** folder in your user profile directory. There is a variable there because this value will differ for each user on your computer, and Chrome installs to your **AppData** folder.
47 |
48 | Here is a list of supported variables:
49 |
50 | * **AppData** - Your main application data folder for your profile (usually roaming)
51 | * **Personal** - Your documents location
52 | * **Desktop** - The path to your Desktop location (may be unreliable)
53 | * **Start Menu** - The path to your Start Menu items location
54 | * **Local AppData** - Your local application data folder for your profile
55 | * **My Video** - Path to your videos location
56 | * **My Pictures** - Path to your pictures location
57 | * **My Music** - Path to your music location
58 |
59 | Note that many of these are not terribly useful for determining browser location, unless you have decided to install Firefox in your My Music folder.
60 |
61 | ## Configure to View on Local Server
62 | The View In Browser plugin also supports the ability to view files in the context of a local server. So if you have a local Apache, Tomcat, or some other server application running you can configure this plugin to open your file prefixed with a URL.
63 |
64 | To configure this the View In Browser plugin reads the configuration of your currently loaded project. You can edit a project file by opening the *sublime-project* file by choosing **Project** -> **Edit Project**. In your project file you will need to specify two things:
65 |
66 | * **baseUrl** - The root URL to prefix files with
67 | * **basePath** - The base path where your site/application lives
68 |
69 | Here's how that looks.
70 |
71 | ```javascript
72 | {
73 | "folders":
74 | [
75 | {
76 | "path": "/home//code/python/my-cool-website"
77 | }
78 | ],
79 | "settings": {
80 | "sublime-view-in-browser": {
81 | "baseUrl": "http://localhost:8080",
82 | "basePath": "/home//code/python/my-cool-website"
83 | }
84 | }
85 | }
86 | ```
87 |
88 | Notice the key named **settings** which is a dictionary that contains another key named **sublime-view-in-browser**. This is where you will put your **baseUrl** and **basePath** settings.
89 |
90 | Now when you activate View In Browser your file will open with the HTTP protocol instead of the FILE protocol.
91 |
92 | ## Change History
93 |
94 | * 03/11/2016:
95 | * Fix issue where parenthesis in paths would cause a failure to load. Solves #52
96 | * 10/06/2014:
97 | * Rewrite for version 2.0.0
98 | * Using subprocess instead of webbrowser. Seems to solve #19
99 | * Smaller, simplier sublime-settings file
100 | * 05/15/2014:
101 | * Current view only saves if there are modifications
102 | * 07/03/2013:
103 | * Changes to support Sublime Text 3 and Python 3
104 | * 06/15/2013:
105 | * Backslashes in Windows are now converted to forward slashes when using
106 | a local server configuration. Closes #16
107 | * 04/16/2013:
108 | * Added support for muliple paths per browser configuration (jadient
109 | #14)
110 | * 03/08/2013:
111 | * Avoid loading Windows special folder references when on a Mac
112 | * Added Mac Chrome to the supported browsers list
113 | * 02/18/2013:
114 | * Added ability to use Windows special folder references to browser commands. Closes
115 | #10
116 | * 01/30/2013:
117 | * All settings for this plugin now live in the file **View In Browser.sublime-settings**.
118 | This allows for a user to override them in their *User* directory. The old
119 | **settings.json** file is no longer used.
120 | * 01/28/2013:
121 | * Merged in change from imaginationac to remove menu nesting
122 | * 12/26/2012:
123 | * Added Linux Chromium to the supported browsers list
124 | * 11/01/2012:
125 | * Altered command to open Safari on Mac
126 | * When invoked the current view is auto-saved
127 | * 10/25/2012:
128 | * New settings.json file to map browser/commands to OSes
129 | * Plugin will use the specified browser to open files, or default to OS default when browser is unsupported
130 | * Addressed encoding issue when calling open_new_tab
131 | * Added ability to specify and respect local server config per project
132 | * 05/21/2012:
133 | * Temp file only created if view is unsaved
134 | * 05/18/2012:
135 | * Initial code
136 |
137 | ## Contributors
138 | * Dorian Patterson - imaginationac
139 | * Neil Freeman - fitnr
140 | * Michael MacDonald - schlick
141 | * Jadient - jadient
142 |
143 | ## License
144 | The MIT License (MIT)
145 | Copyright (c) 2012 Adam Presley
146 |
147 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
148 | to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
149 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
150 |
151 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
152 |
153 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
154 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
155 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
156 | IN THE SOFTWARE.
157 |
--------------------------------------------------------------------------------
/ViewInBrowserCommand.py:
--------------------------------------------------------------------------------
1 | #
2 | # History:
3 | #
4 | # 03/11/2016:
5 | # - Fix issue where parenthesis in paths would cause a failure to load. Solves #52
6 | #
7 | # 10/06/2014:
8 | # - Rewrite for version 2.0.0
9 | # - Using subprocess instead of webbrowser. Seems to solve #19
10 | # - Smaller, simplier sublime-settings file
11 | #
12 | # 05/15/2014:
13 | # - Current view only saves if there are modifications
14 | #
15 | # 07/03/2013:
16 | # - Changes to support Sublime Text 3 and Python 3
17 | #
18 | # 06/15/2013:
19 | # - Forward slashes in paths on Windows are now converted prior to opening using local server path
20 | #
21 | # 03/07/2013:
22 | # - Changed loading of settings so that getting shell folders for Windows is only called on a Windows platform
23 | #
24 | # 01/30/2013:
25 | # - Changed to use the sublime-setting tiered loading scheme. This allow users to override
26 | # settings in their own user file in the User directory
27 | #
28 | # 11/01/2012:
29 | # - Altered command to open Safari on Mac
30 | # - When invoked the current view is auto-saved
31 | #
32 | # 10/25/2012:
33 | # - New settings.json file to map browser/commands to OSes
34 | # - Plugin will use the specified browser to open files, or default to OS default when browser is unsupported
35 | # - Addressed encoding issue when calling open_new_tab
36 | # - Added ability to specify and respect local server config per project
37 | #
38 | # 05/21/2012:
39 | # - Temp file only created if view is unsaved
40 | #
41 | # 05/18/2012:
42 | # - Initial code
43 | #
44 | import os
45 | import sys
46 | import re
47 | import json
48 | import urllib
49 | import sublime
50 | import tempfile
51 | import subprocess
52 | import sublime_plugin
53 | import webbrowser
54 |
55 | PLUGIN_VERSION = "2.0.0"
56 |
57 | class ViewInBrowserCommand(sublime_plugin.TextCommand):
58 | _pythonVersion = sys.version_info[0]
59 |
60 | #
61 | # Takes a Windows variable, such as %APPDATA% and get the
62 | # proper path.
63 | #
64 | def expandWindowsUserShellFolder(self, command):
65 | browserCommand = ""
66 |
67 | windowsFolders = self.getWindowsUserShellFolders()
68 | specialFolder = re.sub(r"%([A-Za-z\s]+)%.*", "\\1", command)
69 |
70 | if specialFolder != command:
71 | expandedFolder = windowsFolders[specialFolder].replace("\\", "\\\\")
72 | browserCommand = re.sub(r"%[A-Za-z\s]+%(.*)", "%s\\1" % expandedFolder, command)
73 | else:
74 | browserCommand = command
75 |
76 | return browserCommand.encode("ascii", "ignore") if self._pythonVersion < 3 else browserCommand
77 |
78 | #
79 | # Returns the correct base command.
80 | #
81 | def getBaseCommand(self, command, osName):
82 | baseCommand = command
83 |
84 | if osName == "nt":
85 | baseCommand = self.expandWindowsUserShellFolder(baseCommand)
86 |
87 | return baseCommand
88 |
89 | #
90 | # Return the name of the running operating system.
91 | # i.e. darwin, nt, linux
92 | #
93 | def getOsName(self):
94 | return os.name
95 |
96 | #
97 | # Get the current running platform. i.e.
98 | # posix, win32
99 | #
100 | def getPlatform(self):
101 | return sys.platform
102 |
103 | #
104 | # Thanks to the Python for Windows site for this snippet.
105 | # http://win32com.goermezer.de/content/view/221/285/
106 | #
107 | def getWindowsUserShellFolders(self):
108 | # Routine to grab all the Windows Shell Folder locations from the registry. If successful, returns dictionary
109 | # of shell folder locations indexed on Windows keyword for each; otherwise, returns an empty dictionary.
110 | if self._pythonVersion < 3:
111 | import _winreg
112 | else:
113 | import winreg as _winreg
114 |
115 | return_dict = {}
116 |
117 | # First open the registry hive
118 | try:
119 | Hive = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
120 | except WindowsError:
121 | print("Can't connect to registry hive HKEY_CURRENT_USER.")
122 | return return_dict
123 |
124 | # Then open the registry key where Windows stores the Shell Folder locations
125 | try:
126 | Key = _winreg.OpenKey(Hive, "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
127 | except WindowsError:
128 | print("Can't open registry key Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders.")
129 | _winreg.CloseKey(Hive)
130 | return return_dict
131 |
132 | # Nothing failed above, so enumerate through all the Shell Folder values and return in a dictionary
133 | # This relies on error at end of
134 | try:
135 | for i in range(0, _winreg.QueryInfoKey(Key)[1]):
136 | name, value, val_type = _winreg.EnumValue(Key, i)
137 | return_dict[name] = value.encode("ascii")
138 | i += 1
139 | _winreg.CloseKey(Key) # Only use with for loop
140 | _winreg.CloseKey(Hive) # Only use with for loop
141 | return return_dict # Only use with for loop
142 |
143 | except WindowsError:
144 | # In case of failure before read completed, don't return partial results
145 | _winreg.CloseKey(Key)
146 | _winreg.CloseKey(Hive)
147 | return {}
148 |
149 | def giveFileAProjectPath(self, fileToOpen, basePath, baseUrl):
150 | return re.sub(r"\\", "/", fileToOpen.replace(basePath, baseUrl)).replace(" ", "%20").replace("(", "%28").replace(")", "%29")
151 |
152 | def loadPluginSettings(self, defaultBrowser):
153 | result = {
154 | "browser": "",
155 | "baseCommand": ""
156 | }
157 |
158 | #
159 | # Load default/user settings. The browser choice may
160 | # be overridden by custom commands.
161 | #
162 | settings = sublime.load_settings("View In Browser.sublime-settings")
163 |
164 | if not defaultBrowser:
165 | result["browser"] = settings.get("browser")
166 | else:
167 | result["browser"] = defaultBrowser
168 |
169 | #
170 | # Get the correct command based on platform and OS
171 | #
172 | osName = self.getOsName()
173 | platform = self.getPlatform()
174 |
175 | selectedOs = settings.get(osName)
176 | result["baseCommand"] = self.getBaseCommand(selectedOs[platform][result["browser"]], osName)
177 |
178 | return result
179 |
180 | def loadProjectSettings(self, view):
181 | return view.settings().get("sublime-view-in-browser")
182 |
183 | def normalizePath(self, fileToOpen):
184 | fileToOpen = fileToOpen.replace("\\", "/")
185 | fileToOpen = "file:///%s" % fileToOpen.replace(" ", "%20").replace("(", "%28").replace(")", "%29")
186 |
187 | return fileToOpen
188 |
189 | def openBrowser(self, command, osName):
190 | useShell = False if osName != "posix" else True
191 | subprocess.Popen(command, shell=useShell)
192 |
193 | def run(self, edit, browser=None):
194 | print("View In Browser plugin v{0}, Python {1}".format(PLUGIN_VERSION, self._pythonVersion))
195 |
196 | #
197 | # Load plugin settings and project settings, if any. A project settings may
198 | # affect the file to open based on local server
199 | # environment settings.
200 | #
201 | pluginSettings = self.loadPluginSettings(browser)
202 | projectSettings = self.loadProjectSettings(self.view)
203 |
204 | fileToOpen = self.view.file_name()
205 |
206 | #
207 | # If we've specified settings for a local server environment
208 | # use them
209 | #
210 | if projectSettings:
211 | fileToOpen = self.giveFileAProjectPath(fileToOpen, projectSettings["basePath"], projectSettings["baseUrl"])
212 |
213 | #
214 | # If the current view has not been saved, put it into
215 | # a temp file and open that instead. If the view
216 | # DOES have a name make sure it is save before
217 | # opening.
218 | #
219 | if fileToOpen == None:
220 | fileToOpen = self.normalizePath(self.saveCurrentViewInTempFile(self.view))
221 |
222 | else:
223 | if self.view.is_dirty():
224 | print("File %s is dirty. Saving..." % (fileToOpen,))
225 | self.view.window().run_command("save")
226 |
227 | if not projectSettings:
228 | fileToOpen = self.normalizePath(fileToOpen)
229 |
230 | #
231 | # And open. If the settings file contains a valid selected browser use that
232 | # command to open this file. Otherwise use the system default.
233 | #
234 | if pluginSettings["baseCommand"]:
235 | command = "%s %s" % (pluginSettings["baseCommand"], fileToOpen.decode().encode(sys.getfilesystemencoding()) if self._pythonVersion < 3 else fileToOpen,)
236 |
237 | print(command)
238 | self.openBrowser(command, self.getOsName())
239 |
240 | else:
241 | if self._pythonVersion < 3:
242 | webbrowser.open_new_tab(fileToOpen.encode(sys.getfilesystemencoding()))
243 | else:
244 | webbrowser.open_new_tab(fileToOpen)
245 |
246 | def saveCurrentViewInTempFile(self, view):
247 | #
248 | # Create a temporary file to hold our contents
249 | #
250 | tempFile = tempfile.NamedTemporaryFile(suffix = ".htm", delete = False)
251 |
252 | #
253 | # Get the contents of the current view
254 | #
255 | region = sublime.Region(0, view.size())
256 | text = view.substr(region)
257 |
258 | tempFile.write(text.encode("utf-8"))
259 | tempFile.close()
260 |
261 | return tempFile.name
262 |
--------------------------------------------------------------------------------