我正在使用json2html,并试图解决一个问题,在这个问题上,我想要编写转换代码,以给我以下HTML:
<html>
<body>
<div><b>Bold text</b> plus plain text</div>
</body>
</html>结果是:粗体文本加纯文本
我现在的情况是:
{"tag":"div","children":[
{"tag":"b","html":"Bold text"}
],"html":" plus plain text"}但这与我的文本顺序相反:加上纯文本Bold text
我试图将转换代码的位置切换到以下位置:
{"tag":"b","children":[
{"tag":"div","html":" plus plain text"}
],"html":"Bold text"}这纠正了定位问题,但所有的文本都是粗体,而不仅仅是其中的一部分。对于如何重新排列事物以获得所需的输出,有什么建议吗?
发布于 2013-12-03 20:50:01
json2html还不支持将标记与纯文本混合,换句话说,在纯文本之外的粗体标记,如下所示:
<div><b>Bold text</b> plus plain text</div>但是,您可以轻松地将纯文本包装在如下span元素中。
<div><b>Bold text</b><span>plus plain text</span></div>在一个变换中它看起来像这样
{"tag":"div","children":[
{"tag":"b","html":"Bold text"},
{"tag":"span","html":" plus plain text"}
]}发布于 2013-12-03 20:49:47
如果您希望b标记和随后的纯文本成为div标记的子元素,则应该使它们都是div标记的子元素:
{"tag":"div","children":[
{"tag":"b","html":"Bold text"},
{"tag": "span", "html":" plus plain text"}
]}https://stackoverflow.com/questions/20361071
复制相似问题