Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fileignoreconfig:
ignore_detectors:
- filecontent
- filename: package-lock.json
checksum: 29476e419f64cdf5cb6a41033148dae3eaacde840e0da8fdcf3690cf59b31899
checksum: 85c2c0c45183180b6793501e09529c5396a66a73e876ade9a80f625b8d174102
- filename: __test__/find-render-content.test.ts
checksum: c2508ae1fb2b20f6fe3d354558704076ecdcbe7e1ece46addaa5eb8354e60233
- filename: __test__/json-to-html.test.ts
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [1.8.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.8.0)
- 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).

## [1.7.1](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.7.1)
- Fix: Guard against null/undefined in getTag to prevent TypeError when addEditableTags/addTags processes entries with null content (Issue #193)

Expand Down
59 changes: 58 additions & 1 deletion __test__/json-to-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
jsonRteClassAndIdAttrs,
styleObj,
unorderListJson1,
nestedOrderedListJson,
nestedOrderedListSiblingStructureJson,
nestedUnorderedListSiblingStructureJson,
unorderListJson2,
orderListJson2,
testJsonRte,
Expand Down Expand Up @@ -566,9 +569,63 @@ describe('Node parse list content', () => {

jsonToHTML({ entry, paths})

expect(entry.supercharged_rte).toEqual('<ul><li>One</li><ul><li>nested one</li><li>nested two</li></ul><li>Two</li></ul>')
expect(entry.supercharged_rte).toEqual('<ul><li>One<ul><li>nested one</li><li>nested two</li></ul></li><li>Two</li></ul>')
done()
})
it('should return valid HTML5 nested list when JSON RTE has sibling-structure', done => {
const entry = {
uid: 'entry_uid_19',
supercharged_rte: {
...nestedOrderedListJson
},
_embedded_items: {}
}
const paths = ['supercharged_rte']

jsonToHTML({ entry, paths})

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>`)
done()
})

it('should return valid HTML5 for ordered list when JSON RTE has nested ol as SIBLING of li', done => {
const entry = {
uid: 'entry_uid_19',
supercharged_rte: {
...nestedOrderedListSiblingStructureJson
},
_embedded_items: {}
}
const paths = ['supercharged_rte']

jsonToHTML({ entry, paths })

// Valid HTML5: nested <ol> must be inside the preceding <li>, not a direct child of parent <ol>
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>'
)
done()
})

it('should return valid HTML5 for unordered list when JSON RTE has nested ul as SIBLING of li', done => {
const entry = {
uid: 'entry_uid_19',
supercharged_rte: {
...nestedUnorderedListSiblingStructureJson
},
_embedded_items: {}
}
const paths = ['supercharged_rte']

jsonToHTML({ entry, paths })

// Valid HTML5: nested <ul> must be inside the preceding <li>, not a direct child of parent <ul>
expect(entry.supercharged_rte).toEqual(
'<ul><li>Item A</li><li>Item B<ul><li>Nested A</li><li>Nested B</li></ul></li></ul>'
)
done()
})

it('Should return unorder list html content for updated json rte', done => {
const entry = {
uid: 'entry_uid_19',
Expand Down
Loading
Loading