This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

initial import

  • Loading branch information...
1 parent c86235c commit ed32ca442e8568643d49550aa4585a8460f4c625 @n1k0 committed May 13, 2012
Showing with 35,748 additions and 3 deletions.
  1. +53 −0 Default.sublime-commands
  2. +67 −0 Highlight.py
  3. +21 −0 Main.sublime-menu
  4. +4 −3 README.md
  5. +281 −0 desktop/__init__.py
  6. +549 −0 desktop/dialog.py
  7. +273 −0 desktop/windows.py
  8. +91 −0 pygments/__init__.py
  9. +433 −0 pygments/cmdline.py
  10. +74 −0 pygments/console.py
  11. +74 −0 pygments/filter.py
  12. +357 −0 pygments/filters/__init__.py
  13. +92 −0 pygments/formatter.py
  14. +68 −0 pygments/formatters/__init__.py
  15. +92 −0 pygments/formatters/_mapping.py
  16. +109 −0 pygments/formatters/bbcode.py
  17. +750 −0 pygments/formatters/html.py
  18. +553 −0 pygments/formatters/img.py
  19. +378 −0 pygments/formatters/latex.py
  20. +117 −0 pygments/formatters/other.py
  21. +136 −0 pygments/formatters/rtf.py
  22. +154 −0 pygments/formatters/svg.py
  23. +112 −0 pygments/formatters/terminal.py
  24. +222 −0 pygments/formatters/terminal256.py
  25. +697 −0 pygments/lexer.py
  26. +229 −0 pygments/lexers/__init__.py
  27. +1,645 −0 pygments/lexers/_asybuiltins.py
  28. +232 −0 pygments/lexers/_clbuiltins.py
  29. +249 −0 pygments/lexers/_luabuiltins.py
  30. +295 −0 pygments/lexers/_mapping.py
  31. +3,787 −0 pygments/lexers/_phpbuiltins.py
  32. +232 −0 pygments/lexers/_postgres_builtins.py
  33. +29 −0 pygments/lexers/_scilab_builtins.py
  34. +3 −0 pygments/lexers/_vimbuiltins.py
  35. +1,803 −0 pygments/lexers/agile.py
  36. +360 −0 pygments/lexers/asm.py
  37. +2,891 −0 pygments/lexers/compiled.py
  38. +636 −0 pygments/lexers/dotnet.py
  39. +1,802 −0 pygments/lexers/functional.py
  40. +356 −0 pygments/lexers/hdl.py
  41. +847 −0 pygments/lexers/jvm.py
  42. +1,072 −0 pygments/lexers/math.py
  43. +3,339 −0 pygments/lexers/other.py
  44. +695 −0 pygments/lexers/parsers.py
  45. +361 −0 pygments/lexers/shell.py
  46. +100 −0 pygments/lexers/special.py
  47. +559 −0 pygments/lexers/sql.py
  48. +1,630 −0 pygments/lexers/templates.py
  49. +1,753 −0 pygments/lexers/text.py
  50. +2,851 −0 pygments/lexers/web.py
  51. +74 −0 pygments/plugin.py
  52. +104 −0 pygments/scanner.py
  53. +117 −0 pygments/style.py
  54. +70 −0 pygments/styles/__init__.py
  55. +65 −0 pygments/styles/autumn.py
  56. +51 −0 pygments/styles/borland.py
  57. +49 −0 pygments/styles/bw.py
  58. +81 −0 pygments/styles/colorful.py
  59. +73 −0 pygments/styles/default.py
  60. +72 −0 pygments/styles/emacs.py
  61. +72 −0 pygments/styles/friendly.py
  62. +42 −0 pygments/styles/fruity.py
  63. +75 −0 pygments/styles/manni.py
  64. +106 −0 pygments/styles/monokai.py
  65. +80 −0 pygments/styles/murphy.py
  66. +65 −0 pygments/styles/native.py
  67. +75 −0 pygments/styles/pastie.py
  68. +69 −0 pygments/styles/perldoc.py
  69. +33 −0 pygments/styles/rrt.py
  70. +141 −0 pygments/styles/tango.py
  71. +63 −0 pygments/styles/trac.py
  72. +63 −0 pygments/styles/vim.py
  73. +38 −0 pygments/styles/vs.py
  74. +195 −0 pygments/token.py
  75. +130 −0 pygments/unistring.py
  76. +232 −0 pygments/util.py
View
@@ -0,0 +1,53 @@
+[
+ /* in SublimeText conversions */
+ {
+ "caption": "Highlight: convert to HTML",
+ "command": "highlight_export",
+ "args": {
+ "target": "sublime",
+ "output_type": "html"
+ }
+ },
+ {
+ "caption": "Highlight: convert to RTF",
+ "command": "highlight_export",
+ "args": {
+ "target": "sublime",
+ "output_type": "rtf"
+ }
+ },
+ /* in SublimeText rendering */
+ {
+ "caption": "Highlight: view as HTML",
+ "command": "highlight_export",
+ "args": {
+ "target": "external",
+ "output_type": "html"
+ }
+ },
+ {
+ "caption": "Highlight: view as RTF",
+ "command": "highlight_export",
+ "args": {
+ "target": "external",
+ "output_type": "rtf"
+ }
+ },
+ /* Clipboard exports */
+ {
+ "caption": "Highlight: copy to clipboard as HTML",
+ "command": "highlight_export",
+ "args": {
+ "target": "clipboard",
+ "output_type": "html"
+ }
+ },
+ {
+ "caption": "Highlight: copy to clipboard as RTF",
+ "command": "highlight_export",
+ "args": {
+ "target": "clipboard",
+ "output_type": "rtf"
+ }
+ }
+]
View
@@ -0,0 +1,67 @@
+import desktop
+import os
+import pygments
+import sublime
+import sublime_plugin
+import tempfile
+
+from pygments.lexers import get_lexer_for_filename, guess_lexer
+from pygments.formatters import get_formatter_by_name
+
+
+FORMATS = ('html', 'rtf',)
+HTML_TEMPLATE = u"""<!DOCTYPE html>
+<html>
+<meta charset="%(encoding)s">
+<title>%(title)s</title>
+<style>%(styles)s</style>
+<pre>%(highlighted)s</pre>
+"""
+
+
+def get_template(**kwargs):
+ return HTML_TEMPLATE % dict(**kwargs)
+
+
+class HighlightExportCommand(sublime_plugin.TextCommand):
+ """Code highlighter command."""
+
+ def run(self, edit, target='external', output_type='html'):
+ region = sublime.Region(0, self.view.size())
+ encoding = self.view.encoding()
+ if encoding == 'Undefined':
+ encoding = 'utf-8'
+ elif encoding == 'Western (Windows 1252)':
+ encoding = 'windows-1252'
+ code = self.view.substr(region)
+
+ # pygmentize the code
+ output_type = output_type if output_type in FORMATS else 'html'
+ formatter = get_formatter_by_name(output_type, style='vim', full=True)
+ if self.view.file_name():
+ lexer = get_lexer_for_filename(self.view.file_name(), code)
+ if not lexer:
+ lexer = guess_lexer(code)
+ pygmented = pygments.highlight(code, lexer, formatter)
+
+ if target == 'external':
+ tmp_file = self.write_file('%s.%s' % (self.view.id(), pygmented, encoding), output_type)
+ sublime.status_message(tmp_file)
+ desktop.open(tmp_file)
+ elif target == 'clipboard':
+ sublime.set_clipboard(pygmented)
+ elif target == 'sublime':
+ new_view = self.view.window().new_file()
+ if output_type == 'html':
+ new_view.set_syntax_file('Packages/HTML/HTML.tmLanguage')
+ new_edit = new_view.begin_edit()
+ new_view.insert(new_edit, 0, pygmented)
+ new_view.end_edit(new_edit)
+
+ def write_file(self, filename, contents, encoding='utf-8'):
+ """Writes highlighted contents onto the filesystem."""
+ tmp_fullpath = os.path.join(tempfile.gettempdir(), filename)
+ tmp_file = open(tmp_fullpath, 'w')
+ tmp_file.write(contents.encode(encoding))
+ tmp_file.close()
+ return tmp_fullpath
View
@@ -0,0 +1,21 @@
+[
+ {
+ "id": "edit",
+ "children":
+ [
+ { "id": "highlight_export" },
+ { "children":
+ [
+ { "id": "highligh_export_browser_html" },
+ {
+ "command": "highlight_export",
+ "args": {
+ "target": "browser",
+ "output_type": "html"
+ }
+ }
+ ]
+ }
+ ]
+ }
+]
View
@@ -1,4 +1,5 @@
-SublimeHighlight
-================
+SublimeText2 Highlight Export
+=============================
-An humble SublimeText2 package which export highlighted code
+This SublimeText2 plugin allows to export current editeds code as highlighted
+code using Pygments.
Oops, something went wrong.

0 comments on commit ed32ca4

Please sign in to comment.