相关疑难解决方法(0)

JSON.stringify以漂亮的打印方式输出到div

JSON.stringify是一个json对象

result = JSON.stringify(message, my_json, 2)
Run Code Online (Sandbox Code Playgroud)

2上面的说法应该是相当打印结果.如果我这样做,它会这样做alert(result).但是,我想通过将其附加到div中来将其输出给用户.当我这样做时,我只会出现一行.(我不认为它有效,因为中断和空格不被解释为html?)

{ "data": { "x": "1", "y": "1", "url": "http://url.com" }, "event": "start", "show": 1, "id": 50 }
Run Code Online (Sandbox Code Playgroud)

有没有办法以JSON.stringify漂亮的打印方式将结果输出到div?

html javascript json pretty-print stringify

141
推荐指数
8
解决办法
17万
查看次数

HTML中的ASCII艺术

我该怎么做才能使它像在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>
Run Code Online (Sandbox Code Playgroud)

得到:

#### ####### ####### …

html ascii-art

34
推荐指数
2
解决办法
4万
查看次数

如何使用CSS来保留HTML <code>块中的换行符?

我有一些代码示例,我想在HTML文档中发布.我用<code>标签包装它们但是我希望它们的样式可以保留换行符.我可以用<pre>标签封装它们但我更喜欢使用CSS.

我在IE7中尝试了以下内容(根据此引用应该可以工作)但没有快乐(删除换行符):

code {
    white-space: pre;
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

css

28
推荐指数
2
解决办法
3万
查看次数

在模板字符串中插入新行?

我尝试将其分成两行:

const templateString = `this is my template 
                        string`
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

const templateString = `this is my template\n string`
Run Code Online (Sandbox Code Playgroud)

但这些都不起作用。仍然显示templateString为一行。如何创建多行模板字符串?

javascript ecmascript-6 template-strings

7
推荐指数
1
解决办法
2万
查看次数

如何使用 FastAPI 返回带换行符的响应?

@app.get('/status')
def get_func(request: Request):
  output = 'this output should have a line break'
  return output
Run Code Online (Sandbox Code Playgroud)

我尝试过的事情:

  • output = this output should \n have a line break
  • output = this output should <br /> have a line break

文本本身被返回,但我没有得到换行符。

python python-3.x fastapi

6
推荐指数
2
解决办法
5482
查看次数