资源简介
一个sublime XML的插件,可以让大家很方便对XML内容进行格式化操作。
代码片段和文件信息
import sublime
import sublime_plugin
import re
import json
from xml.dom.minidom import parseString
from xml.parsers.expat import ExpatError errors
from os.path import basename splitext
class baseIndentCommand(sublime_plugin.TextCommand):
def __init__(self view):
self.view = view
self.language = self.get_language()
def get_language(self):
syntax = self.view.settings().get(‘syntax‘)
language = splitext(basename(syntax))[0].lower() if syntax is not None else “plain text“
return language
def check_enabled(self lang):
return True
def is_enabled(self):
“““
Enables or disables the ‘indent‘ command. Command will be disabled if
there are currently no text selections and current file is not ‘xml‘ or
‘Plain Text‘. This helps clarify to the user about when the command can
be executed especially useful for UI controls.
“““
if self.view is None:
return False
return self.check_enabled(self.get_language())
def run(self edit):
“““
Main plugin logic for the ‘indent‘ command.
“““
view = self.view
regions = view.sel()
# if there are more than 1 region or region one and it‘s not empty
if len(regions) > 1 or not regions[0].empty():
for region in view.sel():
if not region.empty():
s = view.substr(region).strip()
s = self.indent(s)
view.replace(edit region s)
else: # format all text
alltextreg = sublime.Region(0 view.size())
s = view.substr(alltextreg).strip()
s = self.indent(s)
if s:
view.replace(edit alltextreg s)
def indent(self s):
return s
class AutoIndentCommand(baseIndentCommand):
def get_text_type(self s):
language = self.language
if language == ‘xml‘:
return ‘xml‘
if language == ‘json‘:
return ‘json‘
if language == ‘plain text‘ and s:
if s[0] == ‘<‘:
return ‘xml‘
if s[0] == ‘{‘ or s[0] == ‘[‘:
return ‘json‘
return ‘notsupported‘
def indent(self s):
text_type = self.get_text_type(s)
if text_type == ‘xml‘:
command = IndentxmlCommand(self.view)
if text_type == ‘json‘:
command = IndentJsonCommand(self.view)
if text_type == ‘notsupported‘:
return s
return command.indent(s)
def check_enabled(self lang):
return True
class IndentxmlCommand(baseIndentCommand):
def indent(self s):
# figure out encoding
utfEncoded = s.encode(“utf-8“)
encoding = “utf-8“
encoding_match = re.compile(b“<\?.*encoding=\“(.*?)\“.*\?>“).match(utfEncoded)
if encoding_match:
encoding = encoding_match.group(1).decode(“utf-8“).lower()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-12 13:41 sublimetext_indentxm
文件 7 2018-04-12 13:41 sublimetext_indentxm
文件 64 2018-04-12 13:41 sublimetext_indentxm
文件 66 2018-04-12 13:41 sublimetext_indentxm
文件 64 2018-04-12 13:41 sublimetext_indentxm
文件 257 2018-04-12 13:41 sublimetext_indentxm
文件 1101 2018-04-12 13:41 sublimetext_indentxm
文件 704 2018-04-12 13:41 sublimetext_indentxm
文件 1995 2018-04-12 13:41 sublimetext_indentxm
文件 36 2018-04-12 13:41 sublimetext_indentxm
文件 4199 2018-04-12 13:41 sublimetext_indentxm
文件 129 2018-04-12 13:41 sublimetext_indentxm
文件 1317 2018-04-12 13:41 sublimetext_indentxm
目录 0 2018-04-12 13:41 sublimetext_indentxm
文件 769 2018-04-12 13:41 sublimetext_indentxm
目录 0 2018-04-12 13:41 sublimetext_indentxm
文件 95 2018-04-12 13:41 sublimetext_indentxm
文件 92 2018-04-12 13:41 sublimetext_indentxm
文件 53 2018-04-12 13:41 sublimetext_indentxm
文件 61 2018-04-12 13:41 sublimetext_indentxm
文件 8 2018-04-12 13:41 sublimetext_indentxm
文件 7 2018-04-12 13:41 sublimetext_indentxm
文件 64 2018-04-12 13:41 sublimetext_indentxm
文件 68 2018-04-12 13:41 sublimetext_indentxm
文件 1494 2018-04-12 13:41 sublimetext_indentxm
文件 144 2018-04-12 13:41 sublimetext_indentxm
相关资源
-
TreeView&xm
l递归实现无限分级 -
xm
l留言版,数据库留言板 -
xm
l操作DLL -
xm
l无刷新留言板+无刷新删除留言 - XQUERY的好
-
解决打开Dreamweaver出错,menus.xm
l创建 -
cascadexm
l.rar -
Openxm
l操作Excel封装类 -
使用xslt转化xm
l数据形成word文档导出 - Sublime仿HBuilder绿柔主题
- Sublime豆沙绿护眼主题
-
flash+xm
l多级可扩展导航菜单动画源 - OgreCommandLineTools、torchlight-to-blender 2
-
xm
l实现学生信息的增删改查 -
一个炫目的3d照片墙flash+xm
l -
xm
l转XSD\\DTD工具 -
xsdxm
lhtmxsldom -
xm
l做的网页绝对好看 - sublime markdown 插件
-
xm
l增删改查 不用数据库,直接用 -
讲xm
l中的数据写入网页 -
车辆识别 xm
l文件 HOG特征 LEVEL=16 -
unity3d读取xm
l插件Mono.xm l -
firstob
ject xm l Editor -
Openxm
l白皮书译文 - sublime verilog插件
-
xm
l+XSL树形菜单 -
图书管理系统xm
l - win7下如何安装Office2010提示安装MSxm<
-
xm
l增删改查操作
评论
共有 条评论