如何在svg中显示html编码的值? [英] How do I display html encoded values in svg?

查看:455
本文介绍了如何在svg中显示html编码的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用d3来生成svg并以标记结束,类似于以下内容:

I am using d3 to generate svg and end up with markup similar to the following:

<text class="rule" text-anchor="middle">&amp;pound;10K</text>

与预期呈现的类似html比较。

Compare to similar html that renders as expected.

<div>
    &pound;20,160 - &pound;48,069
</div>

我需要在svg标签上设置一个属性来获得类似的编码类型吗?我尝试在网页< meta name =contentcontent =application / xhtml + xml; charset = utf-8/> 中添加元标记,没有工作。

Is there a property I need to set on the svg tag to get a similar type of encoding? I tried adding a meta tag to the page <meta name="content" content="application/xhtml+xml; charset=utf-8" /> but this did not work.

推荐答案

HTML实体未在SVG中定义。您可以使用实际的unicode字符,也可以使用 foreignObject 元素将HTML嵌入到您的SVG中。

HTML entities are not defined in SVG. You can either use the actual unicode character or use the foreignObject element to embed HTML into your SVG.

这篇关于如何在svg中显示html编码的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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