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 packages/draft-js-export-html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sendgrid/draft-js-export-html",
"version": "1.0.5",
"version": "1.0.7",
"description": "DraftJS: Export ContentState to HTML",
"main": "lib/main.js",
"typings": "typings/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions packages/draft-js-export-html/src/stateToHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ const ENTITY_ATTR_MAP: {[entityType: string]: AttrMap} = {
title: 'title',
className: 'class',
clicktracking: 'clicktracking',
universal: 'universal',
},
[ENTITY_TYPE.IMAGE]: {
src: 'src',
height: 'height',
width: 'width',
alt: 'alt',
className: 'class',
style: 'style',
},
SPAN: {
className: 'class',
style: 'style',
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/draft-js-import-element/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sendgrid/draft-js-import-element",
"version": "1.0.1",
"version": "1.0.3",
"description": "DraftJS: Import Element to ContentState",
"main": "lib/main.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,16 @@ describe('stateFromElement', () => {
});

it('should support images', () => {
let imageNode = new ElementNode('img', [{name: 'src', value: 'imgur.com/asdf.jpg'}]);
let imageNode = new ElementNode(
'img',
[
{name: 'src', value: 'imgur.com/asdf.jpg'},
{name: 'height', value: '40'},
{name: 'width', value: '40'},
{name: 'class', value: 'myClass'},
{name: 'style', value: 'color: red;'},
],
);
let wrapperElement = new ElementNode('div', [], [imageNode]);
let contentState = stateFromElement(wrapperElement);
let rawContentState = removeBlockKeys(convertToRaw(contentState));
Expand All @@ -196,6 +205,10 @@ describe('stateFromElement', () => {
'0': {
data: {
src: 'imgur.com/asdf.jpg',
height: '40',
width: '40',
className: 'myClass',
style: 'color: red;',
},
mutability: 'MUTABLE',
type: 'IMAGE',
Expand Down
13 changes: 11 additions & 2 deletions packages/draft-js-import-element/src/stateFromElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ const DATA_ATTRIBUTE = /^data-([a-z0-9-]+)$/;

// Map element attributes to entity data.
const ELEM_ATTR_MAP = {
a: {href: 'url', rel: 'rel', target: 'target', title: 'title', clicktracking: 'clicktracking'},
img: {src: 'src', alt: 'alt'},
a: {href: 'url', rel: 'rel', target: 'target', title: 'title', clicktracking: 'clicktracking', universal: 'universal'},
img: {src: 'src', alt: 'alt', class: 'className', style: 'style', height: 'height', width: 'width'},
span: {class: 'className', style: 'style'},
};

const getEntityData = (tagName: string, element: DOMElement) => {
Expand Down Expand Up @@ -156,6 +157,14 @@ const ElementToEntity = {
return generator.createEntity(ENTITY_TYPE.IMAGE, data);
}
},
span(
generator: ContentGenerator,
tagName: string,
element: DOMElement,
): ?string {
let data = getEntityData(tagName, element);
return generator.createEntity('SPAN', data);
},
};

class ContentGenerator {
Expand Down
4 changes: 2 additions & 2 deletions packages/draft-js-import-html/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sendgrid/draft-js-import-html",
"version": "1.0.1",
"version": "1.0.3",
"description": "DraftJS: Import HTML to ContentState",
"main": "lib/main.js",
"typings": "typings/index.d.ts",
Expand All @@ -9,7 +9,7 @@
"watch": "babel src --watch --out-dir lib --ignore \"_*\""
},
"dependencies": {
"@sendgrid/draft-js-import-element": "^1.0.0"
"@sendgrid/draft-js-import-element": "1.0.3"
},
"peerDependencies": {
"draft-js": ">=0.10.0",
Expand Down