Created
June 27, 2018 10:21
-
-
Save levvsha/1c89f0af66743681fa36759746396edb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { convertToHTML } from 'draft-convert'; | |
export const styleToHTML = (style) => { // <-- [1] | |
switch (style) { | |
case 'ITALIC': | |
return <em className="italic" />; | |
case 'BOLD': | |
return <strong className="bold" />; | |
case 'HIGHLIGHT': | |
return <strong className="highlight" />; | |
default: | |
return null; | |
} | |
}; | |
export const blockToHTML = (block) => { // <-- [2] | |
const blockType = block.type; | |
switch (blockType) { | |
case 'SLIDER': { | |
const slides = block.data.slides; // <-- [4] | |
return { | |
start: `<div class="slider js-slider" data-slides="${ JSON.stringify(slides).replace(/"/g, "'")}"><div>`, | |
end: `</div></div>` | |
} | |
} | |
default: return null; | |
} | |
}; | |
export const entityToHTML = (entity, text) => { // <-- [3] | |
if (entity.type === 'LINK') { | |
return ( | |
<a | |
className="link" | |
href={entity.data.url} | |
target="_blank" | |
> | |
{text} | |
</a> | |
); | |
} | |
return text; | |
}; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment