textParser.ts 384 B

12345678910111213
  1. /**
  2. * 将普通文本转为带段落信息的HTML字符串
  3. * @param text 文本
  4. */
  5. export const parseText2Paragraphs = (text: string) => {
  6. const htmlText = text.replace(/[\n\r]+/g, '<br>')
  7. const paragraphs = htmlText.split('<br>')
  8. let string = ''
  9. for (const paragraph of paragraphs) {
  10. if (paragraph) string += `<div>${paragraph}</div>`
  11. }
  12. return string
  13. }