diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..70ff744 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,3 @@ +export function replaceNewlineWithBr(str) { + return str.replace(/\r?\n/g, '
') +} diff --git a/src/v-editor.vue b/src/v-editor.vue index fb69121..99e50a1 100644 --- a/src/v-editor.vue +++ b/src/v-editor.vue @@ -2,7 +2,7 @@
{ - expect(sum(1, 2)).toBe(3) +test('replaceNewlineWithBr', () => { + const strInWindows = '1.登录平台,选择需求池tab\r\n2.需求列表有需求' + const strInUnix = '1.登录平台,选择需求池tab\n2.需求列表有需求' + const normalStr = `1.登录平台,选择需求池tab
2.需求列表有需求` + expect(replaceNewlineWithBr(strInWindows)).toBe(normalStr) + expect(replaceNewlineWithBr(strInUnix)).toBe(normalStr) })