2017-01-26 1 views
0

나는 Twitter의 부트 스트랩으로 popover로 사용되는 버튼이 있습니다.scatatags atribute에 html 코드를 삽입하는 방법은 무엇입니까?

button(data.content := h1("an example of html").render, data.toggle="popover")("click here") 

가 나는 팝 오버의 내용에 일부 HTML 코드를 갖고 싶어, 그래서 때문에 XSS를 방지 scalatags의, 그러나이 밖으로 일반 HTML 코드를 인쇄는 data.toggle atribute에 HTML을 통과해야합니다. 이 효과를 어떻게 막을 수 있습니까?

+0

http://www.lihaoyi.com/scalatags/#Auto-escapingandunsanitizedInput을 읽으셨습니까? – danielnixon

+0

@ danielnixon 아직 내 질문에 명시된 바와 같이 속성 내에서이를 사용하는 방법을 찾지 못했습니다. – rusins

답변

0

이것은 뻔뻔 스럽지만 원하는대로 할 수 있습니다. 나는 더 좋은 방법이 있는지 확신하지 못한다.

import scalatags.Text.{Attr, TypedTag} 
import scalatags.Text.all._ 
import scalatags.text.Builder 

// Warning: this extends a "more-or-less internal trait" so may stop working after a ScalaTags update. 
final case class RawValueSource(v: String) extends Builder.ValueSource { 
    override def appendAttrValue(strb: StringBuilder): Unit = strb.append(v) 
} 

// We need an AttrValue for tags. This one just renders the tag *without* escaping the result. 
class TagAttrValue extends AttrValue[TypedTag[String]] { 
    override def apply(t: Builder, a: Attr, v: TypedTag[String]): Unit = { 
    t.setAttr(a.name, RawValueSource(v.render)) 
    } 
} 

// We need this implicit in scope so that we can use tags on the rhs of the := operator. 
implicit val tagAttr = new TagAttrValue() 

button(data.content := h1("an example of html"), data.toggle := "popover")("click here") 
관련 문제