Skip to content

Commit bff6967

Browse files
Merge pull request #52 from contentstack/next
JSON RTE changes
2 parents 50d4d42 + 1aedaee commit bff6967

File tree

8 files changed

+343
-6
lines changed

8 files changed

+343
-6
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
# Changelog
22

3+
## [1.3.2](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.2) (2024-02-14)
4+
- Added style attribute fragment as
5+
36
## [1.3.1](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.1) (2023-12-13)
47
- Text level rendering suppport
58
- Dependencies update
69
- Multiple array support
710

11+
## [1.3.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.0) (2023-05-02)
12+
- JSON RTE asset nested in reference field
13+
- Bug fixes
14+
15+
## [1.2.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.2.0) (2023-02-27)
16+
- Added Dom parser for HTML parsing
17+
18+
## [1.1.3](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.1.3) (2022-10-19)
19+
- Resolving embedded items in Json RTE without include Embedded query
20+
21+
## [1.1.2](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.1.2) (2022-04-21)
22+
- Image link and embed tag support for attribute url
23+
24+
## [1.1.1](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.1.1) (2021-12-08)
25+
- Render option support added for new tags
26+
827
## [1.1.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.1.0) (2021-10-19)
928
- Live preview edit tags support added
1029

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22

33

4-
Copyright (c) 2016-2023 Contentstack
4+
Copyright (c) 2016-2024 Contentstack
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

__test__/json-to-html.test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import {
2525
entryJsonRteWithId,
2626
entryJsonRteWithIdinAttrs,
2727
jsonRteClassAndIdAttrs,
28-
styleObj} from './mock/json-element-mock'
28+
styleObj,
29+
unorderListJson1,
30+
unorderListJson2,
31+
orderListJson2,} from './mock/json-element-mock'
2932
import {
3033
blockquoteHtml,
3134
codeHtml,
@@ -338,7 +341,21 @@ describe('Node parse list content', () => {
338341
expect(entry.supercharged_rte).toEqual(orderListHtml)
339342
done()
340343
})
344+
it('Should return order list html content for updated json rte', done => {
345+
const entry = {
346+
uid: 'entry_uid_19',
347+
supercharged_rte: {
348+
...orderListJson2
349+
},
350+
_embedded_items: {}
351+
}
352+
const paths = ['supercharged_rte']
353+
354+
jsonToHTML({ entry, paths})
341355

356+
expect(entry.supercharged_rte).toEqual('<ol><li><fragment>One</fragment><ol><li><strong>nested</strong> one</li><li>nested two</li></ol></li><li>Two</li></ol>')
357+
done()
358+
})
342359
it('Should return un-order list html content', done => {
343360
const entry = {
344361
uid: 'entry_uid_19',
@@ -354,6 +371,36 @@ describe('Node parse list content', () => {
354371
expect(entry.supercharged_rte).toEqual(unorderListHtml)
355372
done()
356373
})
374+
it('Should return unorder list html content for previous json rte ', done => {
375+
const entry = {
376+
uid: 'entry_uid_19',
377+
supercharged_rte: {
378+
...unorderListJson1
379+
},
380+
_embedded_items: {}
381+
}
382+
const paths = ['supercharged_rte']
383+
384+
jsonToHTML({ entry, paths})
385+
386+
expect(entry.supercharged_rte).toEqual('<ul><li>One</li><ul><li>nested one</li><li>nested two</li></ul><li>Two</li></ul>')
387+
done()
388+
})
389+
it('Should return unorder list html content for updated json rte', done => {
390+
const entry = {
391+
uid: 'entry_uid_19',
392+
supercharged_rte: {
393+
...unorderListJson2
394+
},
395+
_embedded_items: {}
396+
}
397+
const paths = ['supercharged_rte']
398+
399+
jsonToHTML({ entry, paths})
400+
401+
expect(entry.supercharged_rte).toEqual('<ul><li><fragment>One</fragment><ul><li>nested one </li><li>nested two </li></ul></li><li>Two</li></ul>')
402+
done()
403+
})
357404
})
358405

359406
describe('Node parse image content', () => {

__test__/mock/json-element-mock.ts

Lines changed: 268 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,270 @@ const orderListJson = {
266266
type: "doc"
267267
}
268268

269+
const unorderListJson1 = {
270+
uid: "rte1",
271+
_version: 1,
272+
attrs: {},
273+
children: [
274+
{
275+
"uid": "uid",
276+
"type": "ul",
277+
"children": [
278+
{
279+
"type": "li",
280+
"attrs": {
281+
"style": {},
282+
"redactor-attributes": {},
283+
"dir": "ltr"
284+
},
285+
"uid": "uid",
286+
"children": [
287+
{
288+
"text": "One"
289+
}
290+
]
291+
},
292+
{
293+
"uid": "uid",
294+
"type": "ul",
295+
"attrs": {
296+
"style": {}
297+
},
298+
"children": [
299+
{
300+
"type": "li",
301+
"attrs": {
302+
"style": {},
303+
"redactor-attributes": {},
304+
"dir": "ltr"
305+
},
306+
"uid": "uid",
307+
"children": [
308+
{
309+
"text": "nested one"
310+
}
311+
]
312+
},
313+
{
314+
"type": "li",
315+
"attrs": {
316+
"style": {},
317+
"redactor-attributes": {},
318+
"dir": "ltr"
319+
},
320+
"uid": "uid",
321+
"children": [
322+
{
323+
"text": "nested two"
324+
}
325+
]
326+
}
327+
]
328+
},
329+
{
330+
"type": "li",
331+
"attrs": {
332+
"style": {},
333+
"redactor-attributes": {},
334+
"dir": "ltr"
335+
},
336+
"uid": "uid",
337+
"children": [
338+
{
339+
"text": "Two"
340+
}
341+
]
342+
}
343+
],
344+
"id": "id",
345+
"attrs": {
346+
"style": {},
347+
"redactor-attributes": {},
348+
"dir": "ltr"
349+
}
350+
}
351+
],
352+
type: "doc"
353+
}
354+
355+
const unorderListJson2 = {
356+
uid: "rte1",
357+
_version: 2,
358+
attrs: {},
359+
children: [
360+
{
361+
"uid": "uid",
362+
"type": "ul",
363+
"children": [
364+
{
365+
"uid": "uid",
366+
"type": "li",
367+
"attrs": {
368+
"style": {},
369+
"redactor-attributes": {},
370+
"dir": "ltr"
371+
},
372+
"children": [
373+
{
374+
"type": "fragment",
375+
"children": [
376+
{
377+
"text": "One"
378+
}
379+
],
380+
"uid": "uid"
381+
},
382+
{
383+
"uid": "uid",
384+
"type": "ul",
385+
"attrs": {
386+
"style": {}
387+
},
388+
"children": [
389+
{
390+
"type": "li",
391+
"attrs": {
392+
"style": {},
393+
"redactor-attributes": {},
394+
"dir": "ltr"
395+
},
396+
"uid": "uid",
397+
"children": [
398+
{
399+
"text": "nested one "
400+
}
401+
]
402+
},
403+
{
404+
"type": "li",
405+
"attrs": {
406+
"style": {},
407+
"redactor-attributes": {},
408+
"dir": "ltr"
409+
},
410+
"uid": "uid",
411+
"children": [
412+
{
413+
"text": "nested two "
414+
}
415+
]
416+
}
417+
]
418+
}
419+
]
420+
},
421+
{
422+
"type": "li",
423+
"attrs": {
424+
"style": {},
425+
"redactor-attributes": {},
426+
"dir": "ltr"
427+
},
428+
"uid": "uid",
429+
"children": [
430+
{
431+
"text": "Two"
432+
}
433+
]
434+
}
435+
],
436+
"id": "uid",
437+
"attrs": {
438+
"style": {},
439+
"redactor-attributes": {},
440+
"dir": "ltr"
441+
}
442+
}
443+
],
444+
type: "doc"
445+
}
446+
447+
const orderListJson2 = {
448+
uid: "rte1",
449+
_version: 2,
450+
attrs: {},
451+
children: [
452+
{
453+
"uid": "uid",
454+
"type": "ol",
455+
"children": [
456+
{
457+
"type": "li",
458+
"uid": "uid",
459+
"attrs": {
460+
"style": {},
461+
"redactor-attributes": {},
462+
"dir": "ltr"
463+
},
464+
"children": [
465+
{
466+
"uid": "uid",
467+
"type": "fragment",
468+
"children": [
469+
{
470+
"text": "One"
471+
}
472+
]
473+
},
474+
{
475+
"uid": "uid",
476+
"type": "ol",
477+
"children": [
478+
{
479+
"uid": "uid",
480+
"type": "li",
481+
"children": [
482+
{
483+
"text": "nested",
484+
"bold": true
485+
},
486+
{
487+
"text": " one"
488+
}
489+
],
490+
"attrs": {
491+
"style": {},
492+
"redactor-attributes": {},
493+
"dir": "ltr"
494+
}
495+
},
496+
{
497+
"uid": "uid",
498+
"type": "li",
499+
"children": [
500+
{
501+
"text": "nested two"
502+
}
503+
],
504+
"attrs": {}
505+
}
506+
],
507+
"attrs": {}
508+
}
509+
]
510+
},
511+
{
512+
"uid": "uid",
513+
"type": "li",
514+
"children": [
515+
{
516+
"text": "Two"
517+
}
518+
],
519+
"attrs": {}
520+
}
521+
],
522+
"id": "uid",
523+
"attrs": {
524+
"style": {},
525+
"redactor-attributes": {},
526+
"dir": "ltr"
527+
}
528+
}
529+
],
530+
type: "doc"
531+
}
532+
269533
const unorderListJson = {
270534
uid: "0e5481190849a",
271535
_version: 13,
@@ -1393,5 +1657,8 @@ export {
13931657
entryJsonRteWithId,
13941658
entryJsonRteWithIdinAttrs,
13951659
jsonRteClassAndIdAttrs,
1396-
styleObj
1660+
styleObj,
1661+
unorderListJson1,
1662+
unorderListJson2,
1663+
orderListJson2,
13971664
}

0 commit comments

Comments
 (0)