Code Monkey home page Code Monkey logo

Comments (9)

imzbf avatar imzbf commented on July 24, 2024

看下你对应的html是怎样的,正常的是这样

<p data-line="0">fas<br>
asd<br>
sasdd</p>

from md-editor-v3.

HDP2017 avatar HDP2017 commented on July 24, 2024

html是这样的
image
但是我选中里面的文字,这个地方好像前面多了个换行
image
但是我得山上应该就是只有一个\n

from md-editor-v3.

HDP2017 avatar HDP2017 commented on July 24, 2024

或许是因为,在替换为<br>标签的时候,文本里面的\n还存在?

from md-editor-v3.

imzbf avatar imzbf commented on July 24, 2024

查了下文档,这是有些 Markdown 解析器在生成 HTML 时,为了保持与原始 Markdown 文件的最大兼容性和可读性,选择保留原始的换行符。而 markdown-it 和 marked 在设置 breaks 为 true,有上面相同的行为。

如果不希望使用的话,可以从这里参考设置它的值。

由于\n在html中并不会起到真实的换行行为,所以你需要参考下面的语法编写你的内容:

https://github.github.com/gfm/#example-673

from md-editor-v3.

HDP2017 avatar HDP2017 commented on July 24, 2024

问题是我现在需要在输入框借助\n换行,其实就是输入框默认的换行行为是在字符串添加\n,而我们后端也需要这个来表示换行。渲染的时候就用的咱们的插件,所有下面的markdown语法应该不行。
上面那个配置可以解决这个问题吗,文档看的不是很清晰,可否提供一个示例代码,麻烦大佬

from md-editor-v3.

imzbf avatar imzbf commented on July 24, 2024

问题是我现在需要在输入框借助\n换行,其实就是输入框默认的换行行为是在字符串添加\n,而我们后端也需要这个来表示换行。渲染的时候就用的咱们的插件,所有下面的markdown语法应该不行。 上面那个配置可以解决这个问题吗,文档看的不是很清晰,可否提供一个示例代码,麻烦大佬

如果确实要使用\n换行,那不用做任何修改,目前没有办法移除保留的\n

from md-editor-v3.

HDP2017 avatar HDP2017 commented on July 24, 2024

那中间空了一行的问题就解决不掉了嘛0.0

from md-editor-v3.

imzbf avatar imzbf commented on July 24, 2024

从编译规则上去处理挺麻烦的,通过组件提供的预处理html的方法sanitize,你可以把它替换掉,像下面:

<MdPreview sanitize={(h) => h.replace(/<br>\n/g, '<br>')} />

from md-editor-v3.

HDP2017 avatar HDP2017 commented on July 24, 2024

加上这个可以了,感谢老哥

from md-editor-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.