From 2e8970f386eec1271785cf07445501d0cb0350ee Mon Sep 17 00:00:00 2001
From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com>
Date: Sat, 8 Feb 2025 11:34:10 +0530
Subject: [PATCH] chore: Added support of \n after just enter (#133)
* chore: Added support of \n after just enter
* chore: Updated changelog
---
CHANGELOG.md | 1 +
__test__/json-to-html.test.ts | 9 +++++
__test__/mock/json-element-mock-result.ts | 2 ++
__test__/mock/json-element-mock.ts | 41 ++++++++++++++++++++++-
src/helper/sanitize.ts | 4 +++
5 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5458fb..4bd1d00 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## [1.3.17](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.17) (2025-02-11)
- Enh: updateAssetURLForGQL update for multilpe entries
+ - Fix: Added support of br tag (\n) after just enter
## [1.3.16](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.16) (2025-01-27)
- Enh: Added support for colgroup and col tags inside table tag
diff --git a/__test__/json-to-html.test.ts b/__test__/json-to-html.test.ts
index f72fd4d..720feac 100644
--- a/__test__/json-to-html.test.ts
+++ b/__test__/json-to-html.test.ts
@@ -17,6 +17,7 @@ import {
linkInPJsonUrl,
orderListJson,
paragraphEntry,
+ paragraphEntryWithNewline,
paragraphJsonArrayEntry,
plainTextJson,
styleinPJson,
@@ -47,6 +48,7 @@ import {
linkInPURLHtml,
orderListHtml,
paragraphHtml,
+ paragraphHtmlWithNewLine,
plainTextHtml,
styleinPHtml,
tableHtml,
@@ -87,6 +89,13 @@ describe('Node parser paragraph content', () => {
done()
})
+ it('Should render Json To html with newline after single enter', done => {
+ const entry = {...paragraphEntryWithNewline}
+ jsonToHTML({entry, paths: ['rich_text_editor']})
+ expect(entry.rich_text_editor).toEqual(paragraphHtmlWithNewLine)
+ done()
+ })
+
it('Should render Json To html for Array of Entries', done => {
const entry = {...paragraphEntry}
diff --git a/__test__/mock/json-element-mock-result.ts b/__test__/mock/json-element-mock-result.ts
index a4fab81..7b1b349 100644
--- a/__test__/mock/json-element-mock-result.ts
+++ b/__test__/mock/json-element-mock-result.ts
@@ -1,5 +1,6 @@
const plainTextHtml = "Aliquam sit amet libero dapibus, eleifend ligula at, varius justoLorem ipsumdolor sit ametSed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. "
const paragraphHtml = "
consectetur adipiscing elit.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem.
" +const paragraphHtmlWithNewLine = "Ritesh test
Shift enter
single enter