Skip to content

Commit

Permalink
improve buttons block conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Dec 20, 2024
1 parent c7503ea commit b490221
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/converters/fromDraftjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,20 @@ const blocks = {
(child, i) => `<blockquote><p>${joinRecursively(child)}</p></blockquote>`,
),
buttons: (children, { keys }) => {
let html = children[0].filter((x) => x !== undefined);
const tag = parser.parseFromString(html, 'text/html');
const data = children.map((child, i) => {
let html = child.flat().filter((x) => x !== undefined);
const tag = parser.parseFromString(html.join(''), 'text/html');

tag.body.childNodes.forEach((node) => {
if (node.getAttribute) {
let css_class = node.getAttribute('class') || '';
css_class += 'btn btn-primary inline-link';
node.setAttribute('class', css_class);
}
tag.body.childNodes.forEach((node) => {
if (node.getAttribute) {
let css_class = node.getAttribute('class') || '';
css_class += 'btn btn-primary inline-link';
node.setAttribute('class', css_class);
}
});
return tag.body.innerHTML;
});
return `<p>${tag.body.innerHTML}</p>`;
return `<p>${data.join('<br />')}</p>`;
},
// 'code-block': (children, { keys }) => (
// <pre key={keys[0]} style={styles.codeBlock}>
Expand Down

0 comments on commit b490221

Please sign in to comment.