Skip to content

Commit

Permalink
fix: richtext render
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Oct 24, 2023
1 parent 9cb2ca5 commit c2cb62e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/components/ItaliaTheme/View/Commons/RichTextRender.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { flattenDeep, values } from 'lodash';
import { values } from 'lodash';
import { flattenHTMLToAppURL } from '@plone/volto/helpers';
import { hasBlocksData } from '@plone/volto/helpers';
import { RenderBlocks } from 'design-comuni-plone-theme/components/ItaliaTheme/View';
Expand All @@ -11,14 +11,16 @@ const richTextHasContent = (data) => {
//ReactDOMServer.renderToStaticMarkup(RenderBlocks({ data: data })),
const renderedBlocks = RenderBlocks({ data: data });

const textBlocks = values(data.blocks).filter((b) => b['@type'] === 'text');
const textBlocks = values(data.blocks).filter(
(b) => b['@type'] === 'slate',
);
const noTextBlocks = values(data.blocks).filter(
(b) => b['@type'] !== 'text',
(b) => b['@type'] !== 'slate',
);

const textContent = flattenDeep(
textBlocks?.map((block) => block.text?.blocks?.map((b) => b.text) ?? []),
)?.filter((b) => b != null && b.trim().length > 0)?.[0];
const textContent = textBlocks?.filter(
(b) => b.plaintext != null && b.plaintext?.trim().length > 0,
)?.[0];

return (
renderedBlocks !== null &&
Expand Down
6 changes: 5 additions & 1 deletion src/config/Slate/Alignment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const messages = defineMessages({
});

export const AlignElement = ({ attributes, children, element }) => {
return <p {...attributes}>{children}</p>;
return (
<p {...attributes} align="test">
{children}
</p>
);
};

const AlignButton = (props) => {
Expand Down
24 changes: 24 additions & 0 deletions src/config/Slate/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//config.settings.slate.contextToolbarButtons
import RichTextWidget from '@plone/volto-slate/widgets/RichTextWidget';
import HtmlSlateWidget from '@plone/volto-slate/widgets/HtmlSlateWidget';
import installAlignment from 'design-comuni-plone-theme/config/Slate/Alignment';
import installHeadings from 'design-comuni-plone-theme/config/Slate/Headings';
import installUnderline from 'design-comuni-plone-theme/config/Slate/Underline';
Expand Down Expand Up @@ -29,5 +31,27 @@ export default function applyItaliaSlateConfig(config) {
config.settings.slate.expandedToolbarButtons = config.settings.slate.toolbarButtons.filter(
(b) => b !== 'callout',
);

//add wrapper public-ui to widgets
config.widgets.widget.slate = (props) => (
<div className="public-ui">
<RichTextWidget {...props} />
</div>
);
config.widgets.widget.slate_richtext = (props) => (
<div className="public-ui">
<RichTextWidget {...props} />
</div>
);
config.widgets.widget.slate_html = (props) => (
<div className="public-ui">
<HtmlSlateWidget {...props} />
</div>
);
config.widgets.widget.richtext = (props) => (
<div className="public-ui">
<HtmlSlateWidget {...props} />
</div>
);
return config;
}

0 comments on commit c2cb62e

Please sign in to comment.