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