Skip to content

Commit 942f566

Browse files
authored
Merge pull request #25 from contentstack/next
fix: 🐛 asset in nested reference with json rte
2 parents 4648e5b + b86005b commit 942f566

File tree

11 files changed

+34
-9
lines changed

11 files changed

+34
-9
lines changed

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- uses: actions/setup-node@v3
2727
with:
2828
node-version: '12.x'
29-
registry-url: 'https://registry.npmjs.org'
29+
registry-url: 'https://npm.pkg.github.com'
3030
scope: '@contentstack'
3131
- run: npm ci
3232
- run: npm publish

__test__/json-to-html.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
h6Html,
3232
imgHtml,
3333
linkInPHtml,
34+
linkInPURLHtml,
3435
orderListHtml,
3536
paragraphHtml,
3637
plainTextHtml,
@@ -488,7 +489,7 @@ describe('Node parse link in paragraph content', () => {
488489

489490
jsonToHTML({ entry, paths})
490491

491-
expect(entry.supercharged_rte).toEqual([linkInPHtml])
492+
expect(entry.supercharged_rte).toEqual([linkInPURLHtml])
492493
done()
493494
})
494495
})

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const plainTextHtml = "<strong>Aliquam sit amet libero dapibus, eleifend ligula at, varius justo</strong><strong><em>Lorem ipsum</em></strong><strong><em><u>dolor sit amet</u></em></strong><strong><em><u><strike>consectetur adipiscing elit.</strike></u></em></strong><strong><em><u><span>Sed condimentum iaculis magna in vehicula. </span></u></em></strong><strong><em><u><sup> Vestibulum vitae convallis </sup></u></em></strong><strong><em><u><sub> lacus. </sub></u></em></strong>"
1+
const plainTextHtml = "<strong>Aliquam sit amet libero dapibus, eleifend ligula at, varius justo</strong><strong><em>Lorem ipsum</em></strong><strong><em><u>dolor sit amet</u></em></strong><strong><em><u><strike><br />consectetur adipiscing elit.</strike></u></em></strong><strong><em><u><span>Sed condimentum iaculis magna in vehicula. </span></u></em></strong><strong><em><u><sup> Vestibulum vitae convallis </sup></u></em></strong><strong><em><u><sub> lacus. </sub></u></em></strong>"
22
const paragraphHtml = "<p>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.</p>"
33
const h1Html = "<h1><strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong></h1>"
44
const h2Html = "<h2><strong><em><u><sub>Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. </sub></u></em></strong></h2>"
@@ -13,6 +13,7 @@ const tableHtml = "<table><thead><tr><th><p>Header 1</p></th><th><p>Header 2</p>
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>"
1617

1718
export {
1819
h1Html,
@@ -28,6 +29,7 @@ export {
2829
orderListHtml,
2930
paragraphHtml,
3031
plainTextHtml,
32+
linkInPURLHtml,
3133
blockquoteHtml,
3234
unorderListHtml,
3335
}

__test__/mock/json-element-mock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const plainTextJson = {
2424
"bold": true,
2525
"italic": true,
2626
"underline": true,
27-
"strikethrough": true
27+
"strikethrough": true,
28+
"break": true
2829
},
2930
{
3031
"text": "Sed condimentum iaculis magna in vehicula. ",
@@ -618,8 +619,7 @@ const linkInPJson = {
618619
"uid": "0d06598201aa8b47",
619620
"type": "a",
620621
"attrs": {
621-
"href": "LINK.com",
622-
"target": "_self"
622+
"href": "LINK.com"
623623
},
624624
"children": [
625625
{

__test__/reference-to-html.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Metadata } from '../src/Models/metadata-model'
55
import Node from '../src/nodes/node'
66
import NodeType from '../src/nodes/node-type'
77
import { Next, RenderOption } from '../src/options'
8+
import { defaultNodeOption } from '../src/options/default-node-options'
89
import { defaultOptions } from '../src/options/default-options'
910
import { assetReferenceJson, embeddedAssetJsonEntry, embeddedEntryJsonEntry, entryReferenceBlockJson, entryReferenceInlineJson, entryReferenceLinkJson } from './mock/json-element-mock'
1011
import { embeddedAssetWithRenderOption, embeddedObjectDefaultRender, embeddedObjectWithRenderOption } from './mock/render-options'
@@ -152,6 +153,13 @@ describe('Reference Node To HTML', () => {
152153
expect(resultHTML).toEqual('<img src=https://image.url/11.jpg>')
153154
done()
154155
})
156+
it('Should return image for undefined node asset from default node option', done => {
157+
const node = assetReferenceJson.children[0] as unknown as Node
158+
159+
const resultHTML = referenceToHTML(node, defaultNodeOption)
160+
expect(resultHTML).toEqual('<img src="https://image.url/11.jpg" />')
161+
done()
162+
})
155163

156164
it('Should return HTML for embedded link entry', done => {
157165
const node = entryReferenceLinkJson.children[0] as unknown as Node

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/utils",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Contentstack utilities for Javascript",
55
"main": "dist/index.es.js",
66
"types": "dist/types/index.d.ts",

src/helper/enumerate-entries.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export function enumerateContents(
4343

4444
export function textNodeToHTML(node: TextNode, renderOption: RenderOption): string {
4545
let text = node.text
46+
if (node.break) {
47+
text = (renderOption[MarkType.BREAK] as RenderMark)(text)
48+
}
4649
if (node.superscript) {
4750
text = (renderOption[MarkType.SUPERSCRIPT] as RenderMark)(text)
4851
}

src/nodes/mark-type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ enum MarkType {
88

99

1010
SUBSCRIPT = 'subscript',
11-
SUPERSCRIPT = 'superscript'
11+
SUPERSCRIPT = 'superscript',
12+
BREAK = 'break'
1213
}
1314

1415
export default MarkType

src/nodes/text-node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default class TextNode extends Node {
88
inlineCode?: boolean
99
superscript?: boolean
1010
subscript?: boolean
11+
break?: boolean
1112

1213
text: string
1314

0 commit comments

Comments
 (0)