使用JavaScript删除多行

    技术2022-07-11  137

    I'm blessed in that lots of people want to guest post on this blog.  It's really flattering and I love seeing writers get a bunch of attention after writing.  My task is converting the blog post, in whatever format it's provided in (HTML, Markdown, PDF, Google Doc, etc.), to HTML for my blog, which can sometimes get messy.  I employ a host of regular expressions to fix these formatting issues.  And the number one problem?  Loads of extra new lines (\n).

    我很幸运,有很多人想在此博客上发表客座文章。 这真的很讨人喜欢,我喜欢看到作家在写作后得到了很多关注。 我的任务是将博客文章(以HTML,Markdown,PDF,Google Doc等提供的任何格式)转换为我博客HTML,有时可能会变得凌乱。 我使用了许多正则表达式来解决这些格式问题。 还有头号问题吗? 加载额外的新行( \n )。

    正则表达式 (The Regular Expression)

    The regular expression is actually quite simple:

    正则表达式实际上非常简单:

    content.replace(/[\r\n]+/g, '\n'); // Just one new line content.replace(/[\r\n]+/g, '\n\n'); // "document" formatting, more elegant

    With the dozens of extra lines gone it's much easier to work with the content!

    随着数十行多余内容的流逝,使用内容变得更加容易!

    翻译自: https://davidwalsh.name/remove-multiple-new-lines

    相关资源:JS实现表格选中多行变色,修改和删除多行
    Processed: 0.013, SQL: 9