说明:加号+居然要加斜杠才能find到(\+)
find \" 要写成 \\\\\"
command 名字大小写 不区分
以下这段 插件 是 专门转换 WCF Test Client(VS官方提供的wcf测试程序) 程序所提取的json数据
配置了热键后可一键转换
import sublime
import sublime_plugin
class autoreplaceformatjsonCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in reversed(self.view.find_all('''\" \+\n \"''')):
if not region.empty():
print(region)
self.view.replace(edit, region, '')
for region in reversed(self.view.find_all('\\\\\"')):
if not region.empty():
print(region)
self.view.replace(edit, region, '\"')
self.view.replace(edit, sublime.Region(0, 1), '')
self.view.replace(edit, sublime.Region(self.view.size() - 1, self.view.size()), '')
self.view.run_command('pretty_json')