只要在结果所在的 div 的 css 设置:
white-space: pre-line;
然后页面就能成功识别 '\n' 并整齐的显示结果了。
参考:https://www.jianshu.com/p/a580568e0055