简体   繁体   English

如何使用json2html排列标签

[英]How to arrange tags with json2html

I'm using json2html and trying to work out an issue where I want to write transform code to give me the following HTML: 我正在使用json2html并试图解决一个问题,在该问题中我想编写转换代码以提供以下HTML:

<html>
<body>
    <div><b>Bold text</b> plus plain text</div>
</body>
</html>

Which results in this output: Bold text plus plain text 结果为: 粗体加纯文本

What I have currently is this: 我目前所拥有的是:

{"tag":"div","children":[
    {"tag":"b","html":"Bold text"}
],"html":" plus plain text"}

But this reverses the order of my text: plus plain text Bold text 但这会颠倒我的文本顺序:加纯文本加粗文本

I tried to switch the positioning of my transform code to this: 我试图将转换代码的位置切换为此:

{"tag":"b","children":[
    {"tag":"div","html":" plus plain text"}
],"html":"Bold text"}

This corrected the positioning problem, but all of the text was bold instead of just part of it. 这解决了定位问题,但所有文本均以粗体显示,而不仅仅是其中一部分。 Any suggestions for how I can rearrange things to get the desired output? 关于如何重新排列以获得所需输出的任何建议?

json2html doesn't have support (yet) for mixing markup with plain text, in other words a bold markup beside plain text like so: json2html还不支持将标记与纯文本混合,换句话说,纯文本旁边的粗体标记如下:

<div><b>Bold text</b> plus plain text</div>

however you can easily get around this by wrapping the plain text in a span element like this 但是,您可以通过将纯文本包装在这样的span元素中来轻松解决此问题

<div><b>Bold text</b><span>plus plain text</span></div>

which would look like this in a transform 在转换中看起来像这样

{"tag":"div","children":[
   {"tag":"b","html":"Bold text"},
   {"tag":"span","html":" plus plain text"}
]}

If you want the b tag and the subsequent plain text to be children of the div tag, you should make them both children of the div tag: 如果希望b标记和后续的纯文本成为div标记的子代,则应使它们都成为div标记的子代:

{"tag":"div","children":[
    {"tag":"b","html":"Bold text"}, 
    {"tag": "span", "html":" plus plain text"}
]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM