n1k0 / sublimehighlight Goto Github PK
View Code? Open in Web Editor NEWA humble SublimeText package for exporting highlighted code as RTF or HTML
Home Page: https://github.com/n1k0/SublimeHighlight
License: MIT License
A humble SublimeText package for exporting highlighted code as RTF or HTML
Home Page: https://github.com/n1k0/SublimeHighlight
License: MIT License
I have a strange error with Sublime Text 3. I'm not at all a Python guy, so I hope you can help me.
Here is the console output:
reloading plugin SublimeHighlight.SublimeHighlight
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 73, in reload_plugin
m = importlib.import_module(modulename)
File "X/importlib/__init__.py", line 88, in import_module
File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1023, in load_module
File "<frozen importlib._bootstrap>", line 1004, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 869, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "/Users/Pym/Library/Application Support/Sublime Text 3/Packages/SublimeHighlight/SublimeHighlight.py", line 8, in <module>
import desktop
ImportError: No module named 'desktop'
I'm on the latest OS X, I use brew
for everything and I installed Pygments by doing $ easy_install Pygments
on line 138 of HighlightLib/desktop/init.py,
return _readfrom(_get_x11_vars() + "xprop -root _DT_SAVE_MODE", shell=1).strip().endswith(' = "xfce4"')
should perhaps be
return _readfrom(_get_x11_vars() + "xprop -root _DT_SAVE_MODE", shell=1).decode(errors="ignore").strip().endswith(' = "xfce4"')
:)
Using non-ASCII symbols, e.g. Cyrillic symbols results in UTF-8 being treated as ASCII.
For example, comment in C++ source file:
// проверка
becomes
// п€“Ñšро€“ÐŠв€“â‰¤е€“Âµрк€“Ð‡а€“âˆž
The line has proper color and font face, but essentially is a garbage :)
HTML conversion works fine.
Instead of "theme": "monokai"
let me do "theme": "default"
or something and it should be exported in the same theme I'm using in sublime text.
The win32 port currently exposes two separate commands to copy highlighted text as HTML or RTF. Most of the time, this is a needless and arbitrary distinction. I propose that we [talk about] combining them.
The Windows clipboard can store multiple versions of the same content, and allow the "pasting" application to specify the format that it prefers, to most closely match its own capabilities (WordPad will prefer RTF over HTML; Outlook will accept either).
Given that this functionality exists, it seems as though we could combine the two copy commands, put both HTML and RTF on the clipboard, and allow the system to determine the "better" version to paste. While Pygments' RTF and HTML output is not 100% equivalent, it's usually pretty close, and I'm not sure that we need to expose this distinction to our users.
We also need to talk about how we handle plaintext. Currently, SublimeHighlight passes the unformatted source text to the clipboard as the highlighted text's plaintext equivalent. This likely makes sense for most users, as the copied code can be pasted into a text editor without being mangled. It also allows our 'Copy Highlighted Text' command to be used as a drop-in substitute for Sublime's built-in 'Copy' command.
However, some users will likely want to access Pygments' raw output, and paste it into a text editor (ie. if they're authoring HTML in a text editor). What's the most elegant way to deal with that scenario?
I'm using S3 on x64 Win7. For some reason certain blocks of text fail to copy to the clipboard as RTF. View or convert to RTF both work, as does HTML. If I select fewer or more lines of text, then sometimes it will work. But selecting the same text again (even much later) still fails. I've tried to figure out if there is a pattern with beginning or ending characters in the selection, but if there is a pattern, I haven't found it.
Here's the traceback:
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_
return self.run(edit, **args)
File "C:\Users\chrisg\AppData\Roaming\Sublime Text 3\Packages\Highlight\SublimeHighlight.py", line 143, in run
winclip.Paste(pygmented, output_type, plaintext)
File "C:\Users\chrisg\AppData\Roaming\Sublime Text 3\Packages\Highlight\HighlightLib\winclip\__init__.py", line 47, in Paste
Put(data, CF_RTF)
File "C:\Users\chrisg\AppData\Roaming\Sublime Text 3\Packages\Highlight\HighlightLib\winclip\__init__.py", line 68, in Put
raise Exception('Failed to lock: %r' % code)
Exception: Failed to lock: 6
If you use the copy to clipboard command on Mac OS X, then paste into a typical Mac application such as Mail.app, you won't see styled text, but rather the raw RTF or HTML.
Perhaps there is some flag on the clipboard or mime-type that must be set so the OS understands that this is styled text?
When I use the theme of vim such as black background ,I found that the exported html has wrong with highlight linenumbers .Those line numbers can't be seen cleary because
the color is not perfect,Can the theme be change perfect?
I'm using Sublime Text 2.0.2 build 2221 on Windows 8 x64, and when I select "Copy as HTML" or "Copy as RTF", nothing happens. My clipboard seems to be clear, and nothing is added to it. I don't see any errors. Any idea?
I click [Edit] -> [Highlight] -> [...]
And all those command such as "copy to clipboard as rtf" is grey, I am not allowed to click. Could you please tell me why is that?
When exporting to RTF, with monokai
theme for example, background color is not preserved on paste. Using SublimeText 3 on Mac.
Hi there,
When highlight and Copy to clipboard RTF doesn't show anything at console, and the clipboard turns empty.
When highlight and Copy to clipboard HTML shows this error on console:
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 543, in run_
return self.run(edit, **args)
File "C:\Users\raguilar\AppData\Roaming\Sublime Text 3\Packages\Highlight\SublimeHighlight.py", line 143, in run
winclip.Paste(pygmented, output_type, plaintext)
File "C:\Users\raguilar\AppData\Roaming\Sublime Text 3\Packages\Highlight\HighlightLib\winclip\__init__.py", line 46, in Paste
data = EncodeHTML(data)
File "C:\Users\raguilar\AppData\Roaming\Sublime Text 3\Packages\Highlight\HighlightLib\winclip\__init__.py", line 99, in EncodeHTML
fragmentStart = html.index(fragment)
TypeError: Can't convert 'bytes' object to str implicitly
_The other options: View as *, works correctly.
*_Sublime Text 3: build 3047
SublimeHighlight-python3 branch
HTML copy/paste gives you HTML in your Gmail message in Chrome.
RTF gives you some bold words, but no colors, and double spacing.
When I copy this code as RTF to my clipboard:
https://gist.github.com/3824127
The white space between some keywords and their name value lose the white space that should be there. Ex:
module ValidationSkipper
becomes
moduleValidationSkipper
FYI, I'm seeing this behavior when trying to paste to Evernote. I haven't tried pasting elsewhere.
请问这是为什么呢?
This happened to me with Sublime Text 3, build 3047 (on Windows) and the python3 branch of this package
reloading plugin SublimeHighlight.SublimeHighlight
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 73, in reload_plugin
m = importlib.import_module(modulename)
File "X/importlib/__init__.py", line 88, in import_module
File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1023, in load_module
File "<frozen importlib._bootstrap>", line 1004, in load_module
File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 869, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "C:\Users\Matthew.Hickford\AppData\Roaming\Sublime Text 3\Packages\SublimeHighlight\SublimeHighlight.py", line 11, in <module>
from .HighlightLib import pygments
ImportError: cannot import name pygments
I know relative imports are a pain in Python, and that Sublime recently made a change about them. Maybe that's the problem?
API: Supporting a distinction between Python modules and packages, to ensure relative imports work as expected
Fresh install of plugin via package control on MacOS Mountain Lion
Traceback (most recent call last):
File "./sublime_plugin.py", line 356, in run_
File "./SublimeHighlight.py", line 97, in run
File "./SublimeHighlight.py", line 92, in highlight
File "./SublimeHighlight.py", line 82, in get_lexer
File "./pygments/lexers/__init__.py", line 121, in get_lexer_for_filename
File "./pygments/lexer.py", line 470, in __call__
File "./pygments/lexers/web.py", line 870, in __init__
ImportError: No module named _phpbuiltins
I can see that the _phpbuiltins.py file exists in the pygments/lexers subdirectory but it hasn't been compiled into a .pyc file. Any suggestions for next steps to take?
Whenever I used the copy to clipboard as rtf and paste into an application like word or powerpoint, it pastes as raw, unformatted data.
Using win7 64bits + sublime text 3.
When I try to copy the following line of code in RTF the plugin_host hangs using all the cpu (thread).
printf("%d meters= %.3f km\n", m, km);
At least here it seems to be caused by the usage of the "%.3f", since it works with just the usual %f.
When I use this to copy to HTML and paste on my blog, all the line breaks are gone. After I read the HTML source, I find the reason is that there is no
tags after each line break.
Can someone fix this? Thanks a lot!
copy to clipboard as HTML
copy to clipboard as RTF
this two section don't appear on sublime 3 \win 7
and also copy as HTML and copy as RTH doesn't work too.
Hi,
as I go through the setup of ST2 I noticed that while all other options work great, "View as RTF" does not work on my Mac (10.7.4).
Instead of opening the rtf
file generated nothing at all happens. My default app for rtf
is TextEdit and creating a new .rtf
file then double clicking this file will open TextEdit as expected.
Here is the output I get from ST2:
Would love to get this to work, happy to help debug this if you have any specific questions.
Thanks for this awesome plugin!
Windows 64-bit OK, but 32-bit "copy as HTML" and "copy as RTF" does not work ><"
Copy as RTF is disabled in contax menu. I think that syntax error causes that.
Reloading plugin C:\Users\SemihFatih\AppData\Roaming\Sublime Text 2\Packages\SublimeHighlight\SublimeHighlight.py
Traceback (most recent call last):
File ".\sublime_plugin.py", line 62, in reload_plugin
File ".\SublimeHighlight.py", line 15, in <module>
import pygments.formatters
File "./HighlightLib\pygments\formatters\__init__.py", line 14, in <module>
from pygments.formatters._mapping import FORMATTERS
File "./HighlightLib\pygments\formatters\_mapping.py", line 18, in <module>
from pygments.formatters.html import HtmlFormatter
File "./HighlightLib\pygments\formatters\html.py", line 509
'using current directory as base for the CSS file name', file=sys.stderr)
^
SyntaxError: invalid syntax
on MacOS
I'd like to produce the HTML with styles inlined (instead of CSS with class refs). Pygments provides this option through the formatter.noclasses
property.
I would nice to able to specify any of the formatter options in the Sublime Text settings (but at least noclasses
:))
Stack Overflow has a snippet of how to do this in the Python:
http://stackoverflow.com/questions/624345/how-can-i-customize-the-output-from-pygments
My environment is win7-32, st 3 build3047. I cloned the branch "python3" into the package directory, but seems can't work well:
get_formatter()
in SublimeHighlight.py
, then the setting options can be obtained.tmp_file.write(contents.encode(...))
in function write_file()
should be changed to tmp_file.write(contents)
.After the 2 steps above, the "view as HTML" command works. But, "view as RTF" still can't work, seems the settings is ineffectual. And, "Copy to clipboard" can't work. The error exists in winclip library according to my python console:
Traceback (most recent call last):
File "D:\Tools\Sublime Text 3\sublime_plugin.py", line 543, in run_
return self.run(edit, **args)
File "D:\Tools\Sublime Text 3\Data\Packages\SublimeHighlight\SublimeHighlight.py", line 143, in run
winclip.Paste(pygmented, output_type, plaintext)
File "D:\Tools\Sublime Text 3\Data\Packages\SublimeHighlight\HighlightLib\winclip\__init__.py", line 60, in Paste
Put(data, CF_HTML)
File "D:\Tools\Sublime Text 3\Data\Packages\SublimeHighlight\HighlightLib\winclip\__init__.py", line 83, in Put
scd(c_int(format), hCd, 0, False)
ValueError: Procedure probably called with too many arguments (8 bytes in excess)
Seems the winclip doesn't support win7 well? I don't know...
I think, it would be useful
Installed it ok, package shows up in the "list packages", folder is there, but no trace of it in SublimeText - not in the Preferences> Package Settings, not in the command pellete.
Using windows 8 (x64) All the other packages are working fine..
Sublime 2.0.2 2221 on OSX 10.8.5
I have
"linenos": "inline"
in both my Default and User settings. It seems to work with HTML, but not RTF. Am I doing something wrong?
Does not find it in the list
Use a mac so trying to manually install but that is not working either
Installed SublimeHighlight from https://github.com/n1k0/SublimeHighlight/tree/python3 and get following error when package is loading. https://github.com/n1k0/SublimeHighlight does not work either, ends with error Package desktop missing.
It is installed on Sublime3, running on Linux.
reloading plugin SublimeHighlight.SublimeHighlight
Traceback (most recent call last):
File "/opt/sublime_text_3/sublime_plugin.py", line 73, in reload_plugin
m = importlib.import_module(modulename)
File "./importlib/__init__.py", line 90, in import_module
File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1022, in load_module
File "<frozen importlib._bootstrap>", line 1003, in load_module
File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
File "<frozen importlib._bootstrap>", line 868, in _load_module
File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
File "/home/michael/.config/sublime-text-3/Packages/SublimeHighlight/SublimeHighlight.py", line 17, in <module>
if desktop.get_desktop() == 'Windows':
File "/home/michael/.config/sublime-text-3/Packages/SublimeHighlight/HighlightLib/desktop/__init__.py", line 167, in get_desktop
elif _is_xfce():
File "/home/michael/.config/sublime-text-3/Packages/SublimeHighlight/HighlightLib/desktop/__init__.py", line 138, in _is_xfce
return _readfrom(_get_x11_vars() + "xprop -root _DT_SAVE_MODE", shell=1).strip().endswith(' = "xfce4"')
TypeError: endswith first arg must be bytes or a tuple of bytes, not str
ST3, W10 1607. Removed and reinstalled SublimeHighlight multiple times, both from master and python3 tree.
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 812, in run_
return self.run(edit, **args)
File "C:\Users\natsu\AppData\Roaming\Sublime Text 3\Packages\SublimeHighlight\SublimeHighlight.py", line 117, in run
pygmented = self.highlight(output_type, full)
File "C:\Users\natsu\AppData\Roaming\Sublime Text 3\Packages\SublimeHighlight\SublimeHighlight.py", line 105, in highlight
return pygments.highlight(self.code, self.get_lexer(),
File "C:\Users\natsu\AppData\Roaming\Sublime Text 3\Packages\SublimeHighlight\SublimeHighlight.py", line 88, in get_lexer
lexer = pygments.lexers.guess_lexer(code)
File "C:\Users\natsu\AppData\Roaming\SUBLIM~1\Packages\pygments\all\pygments\lexers\__init__.py", line 252, in guess_lexer
raise ClassNotFound('no lexer matching the text found')
pygments.util.ClassNotFound: no lexer matching the text found
Although the Code is syntax highlighted in subline with the VB script Addin - It is not being carried across in Highlight. Is this not setting the language in Pygments?
Win a try to copy as HTML,I could not paste anything.I got the error form the console:
Traceback (most recent call last):
File ".\sublime_plugin.py", line 356, in run_
return self.run(edit, **args)
File ".\SublimeHighlight.py", line 152, in run
File ".\winclip__init__.py", line 57, in Paste
File ".\winclip__init__.py", line 80, in Put
ValueError: Procedure probably called with too many arguments (8 bytes in excess)
The following commands do not work on Sublime Text 2 (Windows 7):
If I select and export a portion of code, can I preserve the line numbers? For now the starting number always reset to 1. Thanks.
When I use SublimeHighlight with Lua files and try to copy as HTML or RTF to the clipboard, it fails with the following error:
Traceback (most recent call last):
File "./sublime_plugin.py", line 356, in run_
File "./SublimeHighlight.py", line 111, in run
File "./SublimeHighlight.py", line 106, in highlight
File "./SublimeHighlight.py", line 83, in get_lexer
File "./pygments/lexers/__init__.py", line 121, in get_lexer_for_filename
File "./pygments/lexer.py", line 470, in __call__
File "./pygments/lexers/agile.py", line 1116, in __init__
ImportError: No module named _luabuiltins
This is in Sublime Text 2 version 2.0.1 (build 2217).
Refer http://imageshack.us/photo/my-images/834/28370817.png/.
If seanliang / HighlightWords is installed Highlight appears twice under Edit in Sublime Text 2.
Is there an option to change font size? Thanks.
Is there a way to set it up to either copy to clipboard by default with style, or to set a keyboard shortcut?
Using sublime.set_clipboard(pygmented)
stores the formatted output, but doesn't store mimetype details so when I paste I get the raw RTF output.
Currently working round like so:
filename = '%s.%s' % (self.view.id(), output_type,)
tmp_file = self.write_file(filename, pygmented)
subprocess.call("cat %s | pbcopy -prefer %s" % (tmp_file, output_type), shell=True)
os.remove(tmp_file)
But that mac only...
It would be nice to have a fontsize
option in addition to the existing fontface
to define a default font size (in pt
) for HTML/RTF export.
I tried installing it via package control, via the repo and via git clone, but none works. I get the menu settings and and the right click options, however right click options are disabled, and commands do not show up.
It also seems that when using the repo (or git clone), if I try to go to default settings, it's looking under the Highlight folder, and not SublimeHighlight.
Ubuntu 16.04.1 LTS 64-bit
Sublime Text Build 3114
That's already been done here, in Ruby
I am using Sublime Text 3 on Mac OSX 10.7.5 (Lion). I have checked out the python3
branch.
Syntax highlighting is working fine, but when I change the theme from default
, nothing changes.
On Linux (not tested on mac or windows)
It just open a new empty tab
Same problem with convert to rtf
All others options are ok.
Thanks for this package
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.