Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
added highlighting (<mark> tag) to draft js html to content block con…
Browse files Browse the repository at this point in the history
…verter

Summary:
Added mark tag as recognizable tag used for styling in HTML conversion.

We need this because we need a way to include a custom style for highlighted text (via `span`), which there currently seems to be no support for.

Reference to similar open source pull request with same change: 638f686

Reviewed By: claudiopro

Differential Revision: D13573448

fbshipit-source-id: a72716dd39870d9db8cc0b13d8fcbed683e49063
  • Loading branch information
Isaiah Solomon authored and facebook-github-bot committed Jan 5, 2019
1 parent 585af35 commit 37f2f2a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,44 @@ Array [
]
`;

exports[`highlighted text should be recognized and considered styled characters 1`] = `
Array [
Immutable.Record {
"key": "key0",
"type": "unstyled",
"text": "test",
"characterList": Immutable.List [
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
],
"depth": 0,
"data": Immutable.Map {},
},
]
`;

exports[`img with data protocol should be correctly parsed 1`] = `"📷"`;

exports[`img with http protocol should have camera emoji content 1`] = `"📷"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,44 @@ lorem ipsum
]
`;

exports[`highlighted text should be recognized and considered styled characters 1`] = `
Array [
Immutable.Record {
"key": "key0",
"type": "unstyled",
"text": "test",
"characterList": Immutable.List [
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
Immutable.Record {
"style": Immutable.OrderedSet [
"HIGHLIGHT",
],
"entity": null,
},
],
"depth": 0,
"data": Immutable.Map {},
},
]
`;

exports[`img with data protocol should be correctly parsed 1`] = `"📷"`;

exports[`img with http protocol should have camera emoji content 1`] = `"📷"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ test('img with role presentation should not be rendered', () => {
expect(blocks.contentBlocks).toMatchSnapshot();
});

test('highlighted text should be recognized and considered styled characters', () => {
const blocks = convertFromHTMLToContentBlocks(`<mark>test</mark>`);
expect(blocks.contentBlocks).toMatchSnapshot();
});

test('converts nested html blocks when experimentalTreeDataSupport is enabled', () => {
const html_string = `
<blockquote>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ test('img with role presentation should not be rendered', () => {
expect(blocks.contentBlocks).toMatchSnapshot();
});

test('highlighted text should be recognized and considered styled characters', () => {
const blocks = convertFromHTMLToContentBlocks(`<mark>test</mark>`);
expect(blocks.contentBlocks).toMatchSnapshot();
});

test('converts nested html blocks when experimentalTreeDataSupport is enabled', () => {
const html_string = `
<blockquote>
Expand Down
1 change: 1 addition & 0 deletions src/model/encoding/convertFromHTMLToContentBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const inlineTags = {
strike: 'STRIKETHROUGH',
strong: 'BOLD',
u: 'UNDERLINE',
mark: 'HIGHLIGHT',
};

const knownListItemDepthClasses = {
Expand Down
1 change: 1 addition & 0 deletions src/model/encoding/convertFromHTMLToContentBlocks2.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const HTMLTagToInlineStyleMap: Map<string, string> = Map({
strike: 'STRIKETHROUGH',
strong: 'BOLD',
u: 'UNDERLINE',
mark: 'HIGHLIGHT',
});

type BlockTypeMap = Map<string, string | Array<string>>;
Expand Down

0 comments on commit 37f2f2a

Please sign in to comment.