Skip to content

Commit 17404fe

Browse files
Merge pull request #256 from contentstack/fix/dx-4946-invalid-HTML-for-nested-lists
fix: implement logic to fold nested lists into their preceding list i…
2 parents c82f06e + 2c7f2b7 commit 17404fe

File tree

7 files changed

+667
-390
lines changed

7 files changed

+667
-390
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: package-lock.json
6-
checksum: 29476e419f64cdf5cb6a41033148dae3eaacde840e0da8fdcf3690cf59b31899
6+
checksum: 85c2c0c45183180b6793501e09529c5396a66a73e876ade9a80f625b8d174102
77
- filename: __test__/find-render-content.test.ts
88
checksum: c2508ae1fb2b20f6fe3d354558704076ecdcbe7e1ece46addaa5eb8354e60233
99
- filename: __test__/json-to-html.test.ts

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.8.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.8.0)
4+
- Fix: JSON-to-HTML now outputs valid HTML for nested lists when JSON RTE exports the nested list as a sibling of the preceding list item (`<li>`). The SDK folds such sibling `<ol>`/`<ul>` nodes into the previous `<li>` so the rendered HTML has the nested list inside the parent list item (PROD-2115).
5+
36
## [1.7.1](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.7.1)
47
- Fix: Guard against null/undefined in getTag to prevent TypeError when addEditableTags/addTags processes entries with null content (Issue #193)
58

__test__/json-to-html.test.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import {
2929
jsonRteClassAndIdAttrs,
3030
styleObj,
3131
unorderListJson1,
32+
nestedOrderedListJson,
33+
nestedOrderedListSiblingStructureJson,
34+
nestedUnorderedListSiblingStructureJson,
3235
unorderListJson2,
3336
orderListJson2,
3437
testJsonRte,
@@ -566,9 +569,63 @@ describe('Node parse list content', () => {
566569

567570
jsonToHTML({ entry, paths})
568571

569-
expect(entry.supercharged_rte).toEqual('<ul><li>One</li><ul><li>nested one</li><li>nested two</li></ul><li>Two</li></ul>')
572+
expect(entry.supercharged_rte).toEqual('<ul><li>One<ul><li>nested one</li><li>nested two</li></ul></li><li>Two</li></ul>')
570573
done()
571574
})
575+
it('should return valid HTML5 nested list when JSON RTE has sibling-structure', done => {
576+
const entry = {
577+
uid: 'entry_uid_19',
578+
supercharged_rte: {
579+
...nestedOrderedListJson
580+
},
581+
_embedded_items: {}
582+
}
583+
const paths = ['supercharged_rte']
584+
585+
jsonToHTML({ entry, paths})
586+
587+
expect(entry.supercharged_rte).toEqual(`<ol><li>Item 1</li><li>Item 2<ol><li>Nested Item 1</li><li>Nested Item 2</li></ol></li></ol>`)
588+
done()
589+
})
590+
591+
it('should return valid HTML5 for ordered list when JSON RTE has nested ol as SIBLING of li', done => {
592+
const entry = {
593+
uid: 'entry_uid_19',
594+
supercharged_rte: {
595+
...nestedOrderedListSiblingStructureJson
596+
},
597+
_embedded_items: {}
598+
}
599+
const paths = ['supercharged_rte']
600+
601+
jsonToHTML({ entry, paths })
602+
603+
// Valid HTML5: nested <ol> must be inside the preceding <li>, not a direct child of parent <ol>
604+
expect(entry.supercharged_rte).toEqual(
605+
'<ol><li>Item 1</li><li>Item 2<ol><li>Nested Item 1</li><li>Nested Item 2</li></ol></li></ol>'
606+
)
607+
done()
608+
})
609+
610+
it('should return valid HTML5 for unordered list when JSON RTE has nested ul as SIBLING of li', done => {
611+
const entry = {
612+
uid: 'entry_uid_19',
613+
supercharged_rte: {
614+
...nestedUnorderedListSiblingStructureJson
615+
},
616+
_embedded_items: {}
617+
}
618+
const paths = ['supercharged_rte']
619+
620+
jsonToHTML({ entry, paths })
621+
622+
// Valid HTML5: nested <ul> must be inside the preceding <li>, not a direct child of parent <ul>
623+
expect(entry.supercharged_rte).toEqual(
624+
'<ul><li>Item A</li><li>Item B<ul><li>Nested A</li><li>Nested B</li></ul></li></ul>'
625+
)
626+
done()
627+
})
628+
572629
it('Should return unorder list html content for updated json rte', done => {
573630
const entry = {
574631
uid: 'entry_uid_19',

0 commit comments

Comments
 (0)