首页 > 解决方案 > Markdown 文件无法与 js 库一起正常工作,换行问题

问题描述

我正在使用 react-markdown 来呈现降价。我将 .md 文件的内容传递给它,但它无法正常工作,换行符有问题。但它在这样的在线降价查看工具中运行良好

我的降价看起来像这样:

  - Type some Markdown on the left
  - See HTML in the right
  - Magic

# New Features!

  - Import a HTML file and watch it magically convert to Markdown
  - Drag and drop images (requires your Dropbox account be linked)

标签: javascriptmarkdown

解决方案


这里降价的问题是,它应该是一个单行字符串,其中换行符由 \n 表示。

那就是上面的降价应该是这样的。

  - Type some Markdown on the left\n  - See HTML in the right  \n  - Magic  \n  \n# New Features!  \n  \n  - Import a HTML file and watch it magically convert to Markdown  \n  - Drag and drop images (requires your Dropbox account be linked)

您可以通过此代码实现此格式

mardownContent.replace(/\n/g,'  \\n')

或者来自下面的 vscode

在此处输入图像描述


推荐阅读