Skip to content
Open
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 src/toRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const toRedactor = (jsonValue: any,options?:IJsonToHtmlOptions) : string
text = text.replace(/\n/g, '<br/>')
}
Object.entries(jsonValue).forEach(([key, value]) => {
if(localTextWrappers.hasOwnProperty(key)){
if(localTextWrappers.hasOwnProperty(key) && value){
text = localTextWrappers[key](text,value)
}
})
Expand Down
22 changes: 22 additions & 0 deletions test/toRedactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ describe("Testing json to html conversion", () => {
expect(htmlValue).toBe(expectedValue["inline-classname-and-id"].html)
})

describe("Falsy text marks", () => {
it("does not wrap text when bold/italic/underline are false", () => {
const jsonValue = [{
type: "p",
attrs: {},
children: [{ text: "Plain text", bold: false, italic: false, underline: false }]
}]
const htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
expect(htmlValue).toBe("<p>Plain text</p>")
})

it("wraps only the marks whose value is true", () => {
const jsonValue = [{
type: "p",
attrs: {},
children: [{ text: "Mixed", bold: true, italic: false, underline: true }]
}]
const htmlValue = toRedactor({ type: "doc", attrs: {}, children: jsonValue })
expect(htmlValue).toBe("<p><u><strong>Mixed</strong></u></p>")
})
})

describe("Nested attrs", () => {

test("should have stringified attrs for nested json", () => {
Expand Down