Skip to content

Instantly share code, notes, and snippets.

@levvsha
Created June 27, 2018 10:21
Show Gist options
  • Save levvsha/1c89f0af66743681fa36759746396edb to your computer and use it in GitHub Desktop.
Save levvsha/1c89f0af66743681fa36759746396edb to your computer and use it in GitHub Desktop.
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