1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

slim templateのパイプで改行したいとき

Last updated at Posted at 2019-01-25

計測系のサービスで「スクリプトをそのまま貼り付けてください」みたいな依頼があったときに必要なのでメモ。

なにも考えずパイプ(|)でさくっと対応すると、

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の仕様だけど地味に知らんかったやつ :joy:

追記

こういう書き方もできます :point_down: (こっちのほうがまるっとコピペしやすいので良さそう)

|
  foo
  bar

参考

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?