Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
Cleaned up code based on @n1k0's suggestions.
  • Loading branch information
schmod committed Feb 21, 2013
1 parent 5f490d2 commit 32fd417
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions SublimeHighlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import sublime_plugin
import subprocess
import tempfile
if desktop.get_desktop() == 'Windows':
import winclip

from pygments import highlight
from pygments.lexers import *
from pygments.formatters import *
from pygments.styles import STYLE_MAP

if desktop.get_desktop() == 'Windows':
import winclip

# Don't judge me. Just don't. If you knew, you wouldn't.
__lexers = ['_asybuiltins', '_clbuiltins', '_lassobuiltins', '_luabuiltins',
'_mapping', '_openedgebuiltins', '_phpbuiltins', '_postgres_builtins',
Expand All @@ -32,6 +33,7 @@

DEFAULT_STYLE = "default"
FORMATS = ('html', 'rtf',)
WIN_CR_RE = re.compile(r"\r(?!\n)|(?<!\r)\n")

settings = sublime.load_settings('%s.sublime-settings' % __name__)

Expand Down Expand Up @@ -115,10 +117,11 @@ def run(self, edit, target='external', output_type='html'):
output_type = output_type if output_type in FORMATS else 'html'
platform = desktop.get_desktop()

if platform == 'Windows' and output_type == 'html' and target == 'clipboard': # Windows HTML Clipboard should be a document fragment
full = False
else:
full = settings.get('full', True)
# html clipboard output on windows should not be self-contained
win = all([platform == 'Windows', output_type == 'html',
target == 'clipboard'])
full = False if win else settings.get('full', True)

pygmented = self.highlight(output_type, full)

if target == 'external':
Expand All @@ -141,8 +144,8 @@ def run(self, edit, target='external', output_type='html'):
os.remove(tmp_file)
elif platform == 'Windows':
if self.view.line_endings != 'Windows':
pygmented = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", pygmented)
plaintext = re.sub("\r(?!\n)|(?<!\r)\n", "\r\n", self.code)
pygmented = WIN_CR_RE.sub("\r\n", pygmented)
plaintext = WIN_CR_RE.sub("\r\n", self.code)
else:
plaintext = self.code
winclip.Paste(pygmented, output_type, plaintext)
Expand Down

0 comments on commit 32fd417

Please sign in to comment.