Stop Sparkview escaping html

…衆ロ難τιáo~ 提交于 2019-12-12 01:52:14

问题


I am trying to output some HTML video tags park of which include

<source src="${Model.WebMFilename}" type='video/webm; codecs="vp8, vorbis"' />

However in the browser this renders as

<source vorbis""="" vp8,="" type="video/webm; codecs=" src="VP8_645001.webm"></source>

Any idea how I stop Sparkview reformatting the output?


回答1:


Are you sure about your output? I ran this exact scenario through a unit test in the source code and I got the following:

Input:

<source src="${Model.WebMFilename}" type='video/webm; codecs="vp8, vorbis"' />

Result:

<source src="VP8_645001.webm"  type="video/webm; codecs="vp8, vorbis"" />

This looks like a "feature" in Spark is getting in the way here, and this is becoming more prevalent with client side frameworks, json popularity and HTML5 attributes usage.

The "feature" I speak of is that Spark can read your input and you can have single or double quotes surrounding your attributes and it will understand the value inside the attribute without an issue, but there is a current side effect of view compilation that automatically (and incorrectly) replaces the surrounding attributes with double quote instead of the quote type you actually used.

I am currently working on a fix for this in the source code. In the mean time, you could try and place your double quotes on the outside of the attribute and try single quotes on the inside although I know this does break some of the client side frameworks since they don't expect that. Can you try this instead (Note: single quote on the inside):

<source src="${Model.WebMFilename}" type="video/webm; codecs='vp8, vorbis'" />

Hope that helps,
Rob




回答2:


I managed to get the desired output by wrapping the single quote !{"'"} so

<source src="${Model.WebMFilename}" type=!{"'"}video/webm; codecs="vp8, vorbis"!{"'"} />

Rendered

<source src="VP8_645001.webm" type='video/webm; codecs="vp8, vorbis"' />


来源:https://stackoverflow.com/questions/6329666/stop-sparkview-escaping-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!