我正在寻找可能提供与以下相关的替代方法/修改的答案:
这可能会解决以下问题......
我的目标是能够通过某些进程将原始python
发送到我的剪贴板,以便我可以将其直接粘贴到Microsoft应用程序(例如Outlook)中作为格式化文本,如下所示
我只能实现以下原始pygments
输出。 RtfFormatter
显示HtmlFormatter
但copy
我使用帖子https://stackoverflow.com/a/27291478/4013571中的import ctypes
def copy(text):
"""Copies a string, ``text``, to Windows Clipboard (https://stackoverflow.com/a/27291478/4013571)"""
GMEM_DDESHARE = 0x2000
CF_UNICODETEXT = 13
d = ctypes.windll # cdll expects 4 more bytes in user32.OpenClipboard(None)
try: # Python 2
if not isinstance(text, unicode):
text = text.decode('mbcs')
except NameError:
if not isinstance(text, str):
text = text.decode('mbcs')
d.user32.OpenClipboard(0)
d.user32.EmptyClipboard()
hCd = d.kernel32.GlobalAlloc(GMEM_DDESHARE, len(text.encode('utf-16-le')) + 2)
pchData = d.kernel32.GlobalLock(hCd)
ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
d.kernel32.GlobalUnlock(hCd)
d.user32.SetClipboardData(CF_UNICODETEXT, hCd)
d.user32.CloseClipboard()
func
如
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import RtfFormatter # Same occurs using HtmlFormatter
raw_python = '''
def merge_two_dicts(x, y):
"""Given two dicts, merge them into a new dict as a shallow copy."""
z = x.copy()
z.update(y)
return z
'''
highlighted = highlight(raw_python, PythonLexer(), RtfFormatter())
copy(highlighted)
我也试过pyperclip.copy
但没有成功
gs -q -dBATCH -dSAFER -dNOPAUSE \
-sDEVICE=tiff32nc \
-sDefaultRGBProfile=sRGB2014.icc \
-dOverrideICC \
-sOutputICCProfile=PSOcoated_v3.icc \
-sProcessColorModel=DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sOutputFile=rgb.pdf \
cmyk.tiff