Skip to content

Commit 96b41ee

Browse files
authored
Merge pull request #1 from shopsmart/highlight
Add highlight text transform
2 parents c1a84e6 + 69e5509 commit 96b41ee

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

__test__/text-node-to-html.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,18 @@ describe('Text Node To HTML', () => {
212212
expect(resultHtml).toEqual(`<strong><em><br />${node.text}</em></strong>`)
213213
done()
214214
})
215+
216+
it('Should return Highlighted string text', done => {
217+
const node = {
218+
...textNode,
219+
highlight: true
220+
}
221+
222+
const resultHtml = textNodeToHTML(node, {
223+
...defaultNodeOption
224+
})
225+
226+
expect(resultHtml).toEqual(`<mark>${textNode.text}</mark>`)
227+
done()
228+
})
215229
})

src/helper/enumerate-entries.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export function textNodeToHTML(node: TextNode, renderOption: RenderOption): stri
8585
text = (renderOption[MarkType.BOLD] as RenderMark)(text);
8686
hasMarks = true;
8787
}
88+
if (node.highlight) {
89+
text = (renderOption[MarkType.HIGHLIGHT] as RenderMark)(text);
90+
hasMarks = true;
91+
}
8892

8993
// If no marks were applied, but text contains newlines, convert them to <br />
9094
if (!hasMarks && text.includes('\n')) {

src/nodes/mark-type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum MarkType {
66

77
STRIKE_THROUGH = 'strikethrough',
88
INLINE_CODE = 'inlineCode',
9+
HIGHLIGHT = 'highlight',
910

1011

1112
SUBSCRIPT = 'subscript',

src/nodes/text-node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class TextNode extends Node {
99
superscript?: boolean
1010
subscript?: boolean
1111
break?: boolean
12+
highlight?: boolean
1213
classname?: string
1314
id?: string
1415

src/options/default-node-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ export const defaultNodeOption: RenderOption = {
251251
[MarkType.INLINE_CODE]:(text: string) => {
252252
return `<span data-type='inlineCode'>${sanitizeHTML(text)}</span>`
253253
},
254+
[MarkType.HIGHLIGHT]:(text: string) => {
255+
return `<mark>${sanitizeHTML(text)}</mark>`
256+
},
254257
[MarkType.SUBSCRIPT]:(text: string) => {
255258
return `<sub>${sanitizeHTML(text)}</sub>`
256259
},

0 commit comments

Comments
 (0)