Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Commit

Permalink
Merge pull request #115 from henrahmagix/allow-scripts-in-preview
Browse files Browse the repository at this point in the history
Allow scripts in browser preview.
  • Loading branch information
xpol committed Aug 12, 2013
2 parents 8dfcbab + af26433 commit 456a546
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
23 changes: 21 additions & 2 deletions MarkdownPreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run(self, edit):
class MarkdownPreviewCommand(sublime_plugin.TextCommand):
''' preview file contents with python-markdown and your web browser '''

def getCSsOnSearchPath(self):
def getCSSOnSearchPath(self):
css_name = self.settings.get('css', 'default')
if os.path.isabs(css_name):
return u"<link href='%s' rel='stylesheet' type='text/css'>" % css_name
Expand Down Expand Up @@ -167,7 +167,25 @@ def getOverrideCSS(self):

def getCSS(self):
''' return the correct CSS file based on parser and settings '''
return self.getCSsOnSearchPath() + self.getOverrideCSS()
return self.getCSSOnSearchPath() + self.getOverrideCSS()

def getJS(self):
js_files = settings.get('js')
scripts = ''

if js_files is not None:
# Ensure string values become a list.
if isinstance(js_files, str) or isinstance(js_files, unicode):
js_files = [js_files]
# Only load scripts if we have a list.
if isinstance(js_files, list):
for js_file in js_files:
if os.path.isabs(js_file):
# Load the script inline to avoid cross-origin.
scripts += u"<script>%s</script>" % load_utf8(js_file)
else:
scripts += u"<script type='text/javascript' src='%s'></script>" % js_file
return scripts

def getMathJax(self):
''' return the MathJax script if enabled '''
Expand Down Expand Up @@ -306,6 +324,7 @@ def run(self, edit, target='browser'):
full_html = u'<!DOCTYPE html>'
full_html += '<html><head><meta charset="utf-8">'
full_html += self.getCSS()
full_html += self.getJS()
full_html += self.getHighlight()
full_html += self.getMathJax()
full_html += self.get_title()
Expand Down
9 changes: 9 additions & 0 deletions MarkdownPreview.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@
*/
"allow_css_overrides": true,

/*
Sets the JavaScript files to embed in the HTML
Set an array of URLs or filepaths to JavaScript files. Absolute filepaths will be loaded
into the script tag; others will be set as the `src` attribute. The order of files in the
array is the order in which they are embedded.
*/
// "js": ["http://example.com/script.js", "/path/to/script.js"],

/*
Sets the supported filetypes for auto-reload on save
*/
Expand Down

0 comments on commit 456a546

Please sign in to comment.