Skip to content

Commit 6f9d427

Browse files
committed
fix: 🐛 jsontohtml style attr fix
1 parent 355c0fe commit 6f9d427

File tree

7 files changed

+16458
-236
lines changed

7 files changed

+16458
-236
lines changed

__test__/json-to-html.test.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { jsonToHTML } from '../src/json-to-html'
22
import { embeddedAssetWithRenderOption } from './mock/render-options'
33
import {
4-
plainTextJson,
5-
paragraphEntry,
6-
embeddedAssetJsonEntry,
7-
paragraphJsonArrayEntry,
4+
blockquoteJson,
5+
codeJson,
6+
embeddedAssetJsonEntry,
87
h1Json,
98
h2Json,
109
h3Json,
1110
h4Json,
1211
h5Json,
1312
h6Json,
14-
orderListJson,
15-
unorderListJson,
1613
imgJson,
1714
imgJsonURL,
18-
tableJson,
19-
blockquoteJson,
20-
codeJson,
2115
linkInPJson,
22-
linkInPJsonUrl} from './mock/json-element-mock'
16+
linkInPJsonUrl,
17+
orderListJson,
18+
paragraphEntry,
19+
paragraphJsonArrayEntry,
20+
plainTextJson,
21+
styleinPJson,
22+
tableJson,
23+
unorderListJson} from './mock/json-element-mock'
2324
import {
2425
blockquoteHtml,
2526
codeHtml,
@@ -35,6 +36,7 @@ import {
3536
orderListHtml,
3637
paragraphHtml,
3738
plainTextHtml,
39+
styleinPHtml,
3840
tableHtml,
3941
unorderListHtml} from './mock/json-element-mock-result'
4042
describe('Node parser paragraph content', () => {
@@ -493,3 +495,22 @@ describe('Node parse link in paragraph content', () => {
493495
done()
494496
})
495497
})
498+
499+
500+
describe('Node parse style attribute', () => {
501+
it('Should return style attribute in paragraph html content', done => {
502+
const entry = {
503+
uid: 'entry_uid_19',
504+
supercharged_rte: {
505+
...styleinPJson
506+
},
507+
_embedded_items: {}
508+
}
509+
const paths = ['supercharged_rte']
510+
511+
jsonToHTML({ entry, paths})
512+
513+
expect(entry.supercharged_rte).toEqual(styleinPHtml)
514+
done()
515+
})
516+
})

__test__/mock/json-element-mock-result.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ const h3Html = "<h3><strong><em><u><sub>Mauris venenatis dui id massa sollicitud
66
const h4Html = "<h4><strong><em><u><sub>MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra</sub></u></em></strong></h4>"
77
const h5Html = "<h5>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</h5>"
88
const h6Html = "<h6>Nunc porta diam vitae purus semper, ut consequat lorem vehicula.</h6>"
9-
const orderListHtml = "<ol><li>Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li>Pellentesque mattis lacus in quam aliquam congue</li><li>Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li>Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>"
9+
const orderListHtml = "<ol><li style=\"text-align:justify;\">Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li style=\"text-align:justify;\">Pellentesque mattis lacus in quam aliquam congue</li><li style=\"text-align:justify;\">Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li style=\"text-align:justify;\">Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>"
1010
const unorderListHtml = "<ul><li>Sed quis metus sed mi hendrerit mollis vel et odio.</li><li>Integer vitae sem dignissim, elementum libero vel, fringilla massa.</li><li>Integer imperdiet arcu sit amet tortor faucibus aliquet.</li><li>Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.</li></ul>"
1111
const imgHtml = "<img src=\"https://image.url/Donald.jog.png\" />"
1212
const tableHtml = "<table><thead><tr><th><p>Header 1</p></th><th><p>Header 2</p></th></tr></thead><tbody><tr><td><p>Body row 1 data 1</p></td><td><p>Body row 1 data 2</p></td></tr><tr><td><p>Body row 2 data 1</p></td><td><p>Body row 2 data 2</p></td></tr></tbody></table>"
1313
const blockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>"
1414
const codeHtml = "<code>Code template.</code>"
1515
const linkInPHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a>"
16-
const linkInPURLHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\" target=\"_self\">LINK</a>"
16+
const linkInPURLHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\" target=\"_blank\">LINK</a>"
17+
const styleinPHtml = "<p style=\"text-align:right;\">This is <span>second</span> <u>JSON</u> entry</p><p style=\"text-align:left;\"><a href=\"example.com\" target=\"_blank\">Example</a></p>"
1718

1819
export {
1920
h1Html,
@@ -32,4 +33,5 @@ export {
3233
linkInPURLHtml,
3334
blockquoteHtml,
3435
unorderListHtml,
36+
styleinPHtml,
3537
}

__test__/mock/json-element-mock.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ const linkInPJsonUrl = {
664664
"type": "a",
665665
"attrs": {
666666
"url": "LINK.com",
667-
"target": "_self"
667+
"target": "_blank"
668668
},
669669
"children": [
670670
{
@@ -681,6 +681,53 @@ const linkInPJsonUrl = {
681681
type: "doc"
682682
}
683683

684+
const styleinPJson = {
685+
type: 'doc',
686+
attrs: {},
687+
uid: '7611f269eb4e4f4e9a0c8274decd1e0a',
688+
children: [
689+
{
690+
type: 'p',
691+
attrs: {
692+
style: { 'text-align': 'right' },
693+
'redactor-attributes': {},
694+
dir: 'ltr'
695+
},
696+
uid: '24b09a8e7efa42a2a909cfbc4da403b1',
697+
children: [
698+
{ text: 'This is ' },
699+
{ text: 'second', inlineCode: true },
700+
{ text: ' ' },
701+
{ text: 'JSON', underline: true },
702+
{ text: ' entry' }
703+
]
704+
},
705+
{
706+
type: 'p',
707+
attrs: {
708+
style: { 'text-align': 'left' },
709+
'redactor-attributes': {},
710+
dir: 'ltr'
711+
},
712+
uid: '7eb3984120fe4f3ea18fdeff84326ff4',
713+
children: [
714+
{ text: '' },
715+
{
716+
uid: '76aa06b02ec64a44bd6a0f4ccde11b6a',
717+
type: 'a',
718+
attrs: {
719+
url: 'example.com',
720+
target: '_blank'
721+
},
722+
children: [ { text: 'Example' } ]
723+
},
724+
{ text: '' }
725+
]
726+
}
727+
],
728+
_version: 6
729+
}
730+
684731
const assetReferenceJson = {
685732
uid: "node_uid_12",
686733
_version: 1,
@@ -1030,6 +1077,7 @@ export {
10301077
tableJson,
10311078
linkInPJson,
10321079
linkInPJsonUrl,
1080+
styleinPJson,
10331081
plainTextJson,
10341082
paragraphJson,
10351083
orderListJson,

0 commit comments

Comments
 (0)