Sublime Text 3 - 清洁粘贴

Zac*_*ach 5 python sublimetext3

Sublime Text 3看起来很棒,但是阻止我切换的一个项目是剪贴板命令的兼容性.我唯一使用这个插件的是"clean_paste"函数,它基本上粘贴了从Microsoft Word(或任何其他文本编辑器)复制的内容,剥离了它通常带来的有趣角色.有没有人知道ST3提供的本机功能,我可以将键绑定映射到?这是ClipboardCommand所做的(在ST2版本中):

class ClipboardCommandsPastePlainText(sublime_plugin.TextCommand):
    def run(self, edit):
        copy(clean_paste(clipboard()))
        self.view.run_command('paste')
Run Code Online (Sandbox Code Playgroud)

一般来说可能更多的是Python问题,但你也可以创建自己的键绑定,这个基本上只引用该命令:

"caption": "Clipboard: Paste Plain Text",
"command": "clipboard_commands_paste_plain_text"
Run Code Online (Sandbox Code Playgroud)

所以,如果command我能把这个功能放到那个很棒的东西,但不确定它在Python中是如何工作的.谢谢你的帮助!

Noe*_*lkd 4

不需要太多工作就可以使 python 3 兼容:

\n\n
# coding=utf8\nimport sublime_plugin, sublime, re, html\n\ndef clipboard():\n    return sublime.get_clipboard()\n\ndef copy(data):\n    sublime.set_clipboard(data)\n\n# to transfer data to sublime text\ndef clean_paste(data):\n    # clean word\n    data = str(data)\n    data = data.replace(u\'\xe2\x80\x9d\', \'"\').replace(u\'\xe2\x80\x9c\', \'"\').replace(u\'\xe2\x80\x99\', "\'")\n    data = data.replace(\'________________________________________\', \'\\n\')\n    # clean htmlentities\n    data = re.sub(\'&([^;]+);\', lambda m: unichr(html.entities.name2codepoint[m.group(1)]), data)\n    return data;\n\n# to transfer data from sublime text\ndef clean_copy(data):\n    # clean html\n    data = str(data)\n    data = re.sub(r\'<br ?/?>\', \'\\n\', data, re.I);\n    data = re.sub(r\'<[^>]*>\', \'\', data);\n    # clean htmlentities\n    data = re.sub(\'&([^;]+);\', lambda m: unichr(html.entities.name2codepoint[m.group(1)]), data)\n    return data;\n
Run Code Online (Sandbox Code Playgroud)\n\n

我已经分叉了链接的插件并在此处上传了更改

\n\n

在 sublime3 中测试了它,它似乎可以工作,但是如果没有测试用例,我将把这个留给你。

\n