Skip to content

fix: 🐛 add data type attr for inline code #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 7, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [1.3.14](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.14) (2024-11-12)
- Fix: Add data-type attr to inlineCode

## [1.3.13](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.13) (2024-10-22)
- Enh: Node version bump

Expand Down
8 changes: 4 additions & 4 deletions __test__/default-node-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ describe('Default node render options', () => {
expect(renderString).toEqual('<strike>text</strike>')
done()
})
it('Should return bold string', done => {
it('Should return inline code string', done => {
const renderString = (defaultNodeOption[MarkType.INLINE_CODE] as RenderMark)(text)
expect(renderString).toEqual('<span>text</span>')
expect(renderString).toEqual(`<span data-type='inlineCode'>text</span>`)
done()
})
it('Should return bold string', done => {
it('Should return subscript string', done => {
const renderString = (defaultNodeOption[MarkType.SUBSCRIPT] as RenderMark)(text)
expect(renderString).toEqual('<sub>text</sub>')
done()
})
it('Should return bold string', done => {
it('Should return superscript string', done => {
const renderString = (defaultNodeOption[MarkType.SUPERSCRIPT] as RenderMark)(text)
expect(renderString).toEqual('<sup>text</sup>')
done()
Expand Down
4 changes: 2 additions & 2 deletions __test__/mock/json-element-mock-result.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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>"
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 data-type='inlineCode'>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>"
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>"
const h1Html = "<h1><strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong></h1>"
const h2Html = "<h2><strong><em><u><sub>Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. </sub></u></em></strong></h2>"
Expand All @@ -14,7 +14,7 @@ const blockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</
const codeHtml = "<code>Code template.</code>"
const linkInPHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a>"
const linkInPURLHtml = "<strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\" target=\"_blank\">LINK</a>"
const styleinPHtml = "<p style=\"text-align:right;\">This is <span>second</span> <u>JSON</u> entry</p><p style=\"text-align:left;\"><a class=\"class\" href=\"example.com\" target=\"_blank\">Example</a></p>"
const styleinPHtml = "<p style=\"text-align:right;\">This is <span data-type='inlineCode'>second</span> <u>JSON</u> entry</p><p style=\"text-align:left;\"><a class=\"class\" href=\"example.com\" target=\"_blank\">Example</a></p>"
const plainTextHtmlWithClass = "<p class=\"class_p\"><span class=\"yellow\">abc</span><u><span class=\"blue\">ghi</span></u><strong><em><u><span class=\"orange\" id=\"blue\">Basic</span></u></em></strong><h1><span class=\"purple\">abc</span></h1></p>"
const plainTextHtmlWithId = "<p class=\"class_p\"><em><u><span id=\"blue\">data</span></u></em></p>"
const htmlTextIdInAttrs = "<p id=\"id_p\"><em><u>data</u></em></p>"
Expand Down
7 changes: 3 additions & 4 deletions __test__/reference-to-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { defaultOptions } from '../src/options/default-options'
import { assetReferenceJson, embeddedAssetJsonEntry, embeddedEntryJsonEntry, entryReferenceBlockJson, entryReferenceInlineJson, entryReferenceLinkJson } from './mock/json-element-mock'
import { embeddedAssetWithRenderOption, embeddedObjectDefaultRender, embeddedObjectWithRenderOption } from './mock/render-options'
describe('Reference Node To HTML', () => {
it.skip('Should return blank for undefined entry', done => {
it('Should return blank for undefined entry', done => {
const node = assetReferenceJson.children[0] as unknown as Node
console.log('Node attributes:', node.attrs);
const renderOption = {}

const resultHTML = referenceToHTML(node, renderOption)
Expand Down Expand Up @@ -49,7 +48,7 @@ describe('Reference Node To HTML', () => {
done()
})

it.skip('Should return HTML for embedded asset', done => {
it('Should return HTML for embedded asset', done => {
const node = assetReferenceJson.children[0] as unknown as Node
const renderOption = {}

Expand Down Expand Up @@ -95,7 +94,7 @@ describe('Reference Node To HTML', () => {
})

// Custom render option
it.skip('Should return custom HTML for embedded asset', done => {
it('Should return custom HTML for embedded asset', done => {
const node = assetReferenceJson.children[0] as unknown as Node
const renderOption = embeddedAssetWithRenderOption.renderOption as RenderOption

Expand Down
4 changes: 2 additions & 2 deletions __test__/text-node-to-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Text Node To HTML', () => {
...defaultNodeOption
})

expect(resultHtml).toEqual(`<span>${textNode.text}</span>`)
expect(resultHtml).toEqual(`<span data-type='inlineCode'>${textNode.text}</span>`)
done()
})
it('Should return Subscript string text', done => {
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Text Node To HTML', () => {
...defaultNodeOption
})

expect(resultHtml).toEqual(`<strong><em><u><strike><span><sub><sup>${textNode.text}</sup></sub></span></strike></u></em></strong>`)
expect(resultHtml).toEqual(`<strong><em><u><strike><span data-type='inlineCode'><sub><sup>${textNode.text}</sup></sub></span></strike></u></em></strong>`)
done()
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/utils",
"version": "1.3.13",
"version": "1.3.14",
"description": "Contentstack utilities for Javascript",
"main": "dist/index.es.js",
"types": "dist/types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/options/default-node-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const defaultNodeOption: RenderOption = {
return `<strike>${sanitizeHTML(text)}</strike>`
},
[MarkType.INLINE_CODE]:(text: string) => {
return `<span>${sanitizeHTML(text)}</span>`
return `<span data-type='inlineCode'>${sanitizeHTML(text)}</span>`
},
[MarkType.SUBSCRIPT]:(text: string) => {
return `<sub>${sanitizeHTML(text)}</sub>`
Expand Down
Loading