我JSON.stringify是一个json对象
result = JSON.stringify(message, my_json, 2)
在2上面的说法应该是相当打印结果.如果我这样做,它会这样做alert(result).但是,我想通过将其附加到div中来将其输出给用户.当我这样做时,我只会出现一行.(我不认为它有效,因为中断和空格不被解释为html?)
{ "data": { "x": "1", "y": "1", "url": "http://url.com" }, "event": "start", "show": 1, "id": 50 }
有没有办法以JSON.stringify漂亮的打印方式将结果输出到div?
我该怎么做才能使它像在Web浏览器中的HTML文档中一样打印?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Example</title>
    </head>
    <body>
        ###### #    #   ##   #    # #####  #      ######
        #       #  #   #  #  ##  ## #    # #      #      
        #####    ##   #    # # ## # #    # #      ##### 
        #        ##   ###### #    # #####  #      #      
        #       #  #  #    # #    # #      #      #      
        ###### #    # #    # #    # #      ###### ######
    </body>
</html>
得到:
#### ####### ####### …
我有一些代码示例,我想在HTML文档中发布.我用<code>标签包装它们但是我希望它们的样式可以保留换行符.我可以用<pre>标签封装它们但我更喜欢使用CSS.
我在IE7中尝试了以下内容(根据此引用应该可以工作)但没有快乐(删除换行符):
code {
    white-space: pre;
}
这可能吗?
我尝试将其分成两行:
const templateString = `this is my template 
                        string`
我也尝试过:
const templateString = `this is my template\n string`
但这些都不起作用。仍然显示templateString为一行。如何创建多行模板字符串?
@app.get('/status')
def get_func(request: Request):
  output = 'this output should have a line break'
  return output
我尝试过的事情:
output = this output should \n have a line breakoutput = this output should <br /> have a line break文本本身被返回,但我没有得到换行符。
html ×2
javascript ×2
ascii-art ×1
css ×1
ecmascript-6 ×1
fastapi ×1
json ×1
pretty-print ×1
python ×1
python-3.x ×1
stringify ×1