使用 ruby​​ 在 yaml 中输出折叠文本块

发布于 2024-08-29 10:08:54 字数 413 浏览 2 评论 0原文

当我执行 message.to_yaml 时,我得到以下输出,

mainText: "<h3 class=\"right_column\">Mark</h3> ... "

但我希望输出采用以下格式:

mainText: |
     <h3 class="right_column">Mark</h3>  
     ... 

如何强制 ruby​​ 使用管道来折叠多行字符串。

我尝试过

message.to_yaml(:UseFold => true, :UseBlock => true)

,但不起作用,

谢谢

when I do message.to_yaml I am getting the following output

mainText: "<h3 class=\"right_column\">Mark</h3> ... "

but I want the output in the following format

mainText: |
     <h3 class="right_column">Mark</h3>  
     ... 

How do you force ruby to use pipe to fold multiple lines of string.

I tried

message.to_yaml(:UseFold => true, :UseBlock => true)

but it is not working

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2024-09-05 10:08:54
irb(main):011:0> puts "Hi!\nIf your string has newlines...\nfolding is by default".to_yaml
--- |-
Hi!
If your string has newlines...
folding is by default
irb(main):011:0> puts "Hi!\nIf your string has newlines...\nfolding is by default".to_yaml
--- |-
Hi!
If your string has newlines...
folding is by default
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文