你如何防止添加到Handlebars部分的换行符? [英] How do you prevent newline added to Handlebars partial?

查看:135
本文介绍了你如何防止添加到Handlebars部分的换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:部分用于内联元素的单线手把:



把手模板:

 < a href =#section> {{>局部}}标签和LT; / A> 

部分:

 < svg class =iconviewBox =0 0 65 65>< use xlink:href =#icon>< / use>< / svg> 

汇编结果:

 < a href =#section>< svg class =iconviewBox =0 0 65 65>< use xlink:href =#icon>< /使用>< / SVG> 
标签< / a>

正如你所看到的,部分内容会出现在换行符中。该文件中没有新行。

解决方案

这个问题是由Vim的EOL管理引起的。

为防止换行符出现在Handlebars编译之后,将Vim配置( .vimrc )改为包含:

  au BufWritePre *:设置二进制|设置noeol 
au BufWritePost *:设置nobinary |设置eol


Scenario: one-line Handlebars partial used in an inline element:

Handlebars template:

<a href="#section">{{> partial}}Label</a>

Partial:

<svg class="icon" viewBox="0 0 65 65"><use xlink:href="#icon"></use></svg>

Compilation result:

<a href="#section"><svg class="icon" viewBox="0 0 65 65"><use xlink:href="#icon"></use></svg>
Label</a>

As you see, partial comes across with the newline. There's no newline in the file.

解决方案

The issue was caused by the Vim's EOL management.

To prevent newline appearing after the Handlebars compilation, change Vim configuration (.vimrc) to include:

au BufWritePre * :set binary | set noeol
au BufWritePost * :set nobinary | set eol

这篇关于你如何防止添加到Handlebars部分的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆