C# 或 javascript 代码格式化程序
我目前正在使用语法荧光笔在页面上显示 XML 或 SOAP 消息。这对于已经正确格式化的消息(换行符、缩进等)来说效果很好。但是,如果我有一个像这样的 XML 字符串:
string xml = "<doc><object><first>Joe</first><last>Smith</last></object></doc>";
我会将字符串写入页面,并且 javascript 荧光笔会正确地语法突出显示该字符串,但它会全部在一行上。
是否有 C# 字符串格式化程序或某些语法突出显示库具有“智能”缩进功能,可以插入换行符、缩进等...?
I'm currently using Syntax Highlighter to show a XML or SOAP messages on a page. That works fine for messages that are already formatted correctly (line breaks, indents, etc). But if I had a XML string like:
string xml = "<doc><object><first>Joe</first><last>Smith</last></object></doc>";
I would write the string to the page and the javascript highlighter would correctly syntax highlight the string, but it would be all on a single line.
Is there a C# string formatter or some syntax highlighting library that has a "smart" indent feature that would insert line breaks, indents, etc... ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于这是一个字符串,因此添加换行符和缩进将更改变量
xml
的实际值,这不是您想要的代码格式化程序来做!请注意,您可以在写入页面之前用 C# 格式化 XML,如下所示:
Since this is a string, adding line breaks and indents would be changing the actual value of variable
xml
, which is not what you want your code formatter to do!Note that you can format the XML in C# before writing to the page, like this: