slim templateのパイプで改行したいとき
計測系のサービスで「スクリプトをそのまま貼り付けてください」みたいな依頼があったときに必要なのでメモ。
なにも考えずパイプ(|
)でさくっと対応すると、
sample.slim
| <script language='javascript' src='https://hogehoge.com/path/to/file.js'></script>
| <script language='javascript'><!--
| do_something('*****');
| //--></script>
| <noscript>
| <img src="https://hogehoge.com/path/to/action?hoge=1&fuga=2" width="1" height="1">
| </noscript>
変換時、改行がすべてなくなってしまう。
出力結果
<script language='javascript' src='https://hogehoge.com/path/to/file.js'></script><script language='javascript'><!--do_something('*****');//--></script><noscript><img src="https://hogehoge.com/path/to/action?hoge=1&fuga=2" width="1" height="1"></noscript>
ので、パイプは最初の行1つだけに挿入して、インデントを整えると、見た目どおりに変換される。
sample.slim
| <script language='javascript' src='https://hogehoge.com/path/to/file.js'></script>
<script language='javascript'><!--
do_something('*****');
//--></script>
<noscript>
<img src="https://hogehoge.com/path/to/action?hoge=1&fuga=2" width="1" height="1">
</noscript>
slimの仕様だけど地味に知らんかったやつ
追記
こういう書き方もできます (こっちのほうがまるっとコピペしやすいので良さそう)
|
foo
bar
参考
Author And Source
この問題について(slim templateのパイプで改行したいとき), 我々は、より多くの情報をここで見つけました https://qiita.com/paranishian/items/8aa6bb292b2e1aee309a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .