如何解决格式onsave在带有Prettier的VS Code中不起作用
我在ES Lint和Prettier上使用了VS Code,它们运行良好。
但是今天我注意到,Prettier不会像以前那样在保存时格式化代码。我尚未进行任何更新或更改,所以我不知道为什么会这样。
当我进入“设置”时,它已经被选中:
如果我删除了;
或在代码中添加了多余的空格,它会在Prettier中显示为错误,但我必须右键单击并选择解决问题。我不知道为什么不像以前那样自动完成。
settings.json:
{
"explorer.confirmDelete": false,"javascript.preferences.quoteStyle": "single","typescript.preferences.quoteStyle": "single","prettier.jsxSingleQuote": true,"prettier.singleQuote": true,"javascript.updateImportsOnFileMove.enabled": "always","window.zoomLevel": 0,"editor.formatOnSave": true
}
关于如何解决这个烦人的问题的任何想法?
解决方法
xml = str(start_doc._element.xml) #this gets the full XML using docx
tree = etree.fromstring(xml)
WORD_NAMESPACE='{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
TEXT = WORD_NAMESPACE + 't'
PARA = WORD_NAMESPACE + 'p'
SECT = WORD_NAMESPACE + 'sectPr'
sectionLoc = []
for item in tree.iter(PARA):
for node in item.iter(TEXT):
if 'Section' in node.text: #this is how I am identifying which headers I need to edit
print(node.text)
sectionLoc.append(node.text)
for sect in item.iter(SECT):
print(sect)
sectionLoc.append('section')
# print(etree.tostring(sect))
counter =0
sectionLocs = []
for index,item in enumerate(sectionLoc): #just some logic to get the correct section number from the xml parse
if 'Section' in item:
sectionLocs.append(counter)
continue
counter += 1
#ok now use those locations with docx to adjust the headers
#remember that start_doc here needs to be the new result from win32 process-
#so start_doc = Document('C:\path to\combined.docx') in this case
for item in sectionLocs:
section = start_doc.sections[item]
header = section.header
para_new = header.paragraphs[0]
para_new.text = 'TEST!'
start_doc.save('willthiswork.docx')
将其添加到settings.json对我有用
完整的settings.json:
"editor.defaultFormatter": "esbenp.prettier-vscode",
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。