丑陋的 xml 输出
我正在使用 HaXml 来转换 XML 文件,一切都运行良好。然而 HaXml 生成的输出看起来非常难看,主要是因为它几乎在每个右括号处插入了换行符。 下面是一些生成 xml 的代码:
writeFile outPath (show . PP.content . head $ test (docContent (posInNewCxt "" Nothing) (xmlParse "" "")))
test =
mkElemAttr "test" [("a", literal "1"), ("b", literal "2")]
[
mkElem "nested" []
]
这是它生成的输出:
<test a="1" b="2"
><nested/></test>
当然,元素越多,情况就越糟糕。
我知道 HaXml 使用 Text.PrettyPrint.HughesPJ 进行渲染,但使用不同的 样式 没有太大变化。
那么,有没有办法改变输出呢?
I'm using HaXml to transform a XML file and it's all quite working nicely. However the output HaXml generates looks really ugly, mainly because it inserts a linebreak at almost every closing bracket.
Here's some code that generates a xml:
writeFile outPath (show . PP.content . head $ test (docContent (posInNewCxt "" Nothing) (xmlParse "" "")))
test =
mkElemAttr "test" [("a", literal "1"), ("b", literal "2")]
[
mkElem "nested" []
]
and here's the output it generates:
<test a="1" b="2"
><nested/></test>
Of course it is worse with more elements.
I know that HaXml uses Text.PrettyPrint.HughesPJ for rendering, but using different styles
didn't change much.
So, is there a way to change the output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您对
show
的调用替换为Text.PrettyPrint.renderStyle
您可以获得一些不同的行为:尝试不同的开箱即用样式:
默认样式
style { mode = OneLineMode }
style { mode = LeftMode, lineLength = 2 }
所以你当然可以做一些不同的事情。
如果您不喜欢其中任何一个,您可以使用
fullRender
:您的自定义行为可以编程到
TextDetails
函数中。Replacing you call to
show
withText.PrettyPrint.renderStyle
you can get a few different behaviors:Experimenting with different out-of-the-box styles:
Default style
style { mode = OneLineMode }
style { mode = LeftMode, lineLength = 2 }
So you can certainly do a few different things.
If you don't like any of these, you can write a custom processors, using
fullRender
:where your custom behavior can be programmed into the
TextDetails
function.