Skip to content

Commit

Permalink
Move to Handlebars
Browse files Browse the repository at this point in the history
  • Loading branch information
geido committed Dec 14, 2022
1 parent 07a550c commit a63d5d4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ import { FeatureFlag, isFeatureEnabled } from '../utils';

interface SafeMarkdownProps {
source: string;
htmlSanitization?: boolean;
htmlSchemaOverrides?: typeof defaultSchema;
}

function SafeMarkdown({ source }: SafeMarkdownProps) {
const appContainer = document.getElementById('app');
const { common } = JSON.parse(
appContainer?.getAttribute('data-bootstrap') || '{}',
);
const htmlSanitization: boolean = common?.conf?.HTML_SANITIZATION ?? true;
const htmlSchemaOverrides: typeof defaultSchema =
common?.conf?.HTML_SANITIZATION_SCHEMA_EXTENSIONS || {};
function SafeMarkdown({
source,
htmlSanitization = true,
htmlSchemaOverrides = {},
}: SafeMarkdownProps) {
const displayHtml = isFeatureEnabled(FeatureFlag.DISPLAY_MARKDOWN_HTML);
const escapeHtml = isFeatureEnabled(FeatureFlag.ESCAPE_MARKDOWN_HTML);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export const HandlebarsViewer = ({
}: HandlebarsViewerProps) => {
const [renderedTemplate, setRenderedTemplate] = useState('');
const [error, setError] = useState('');
const appContainer = document.getElementById('app');
const { common } = JSON.parse(
appContainer?.getAttribute('data-bootstrap') || '{}',
);
const htmlSanitization = common?.conf?.HTML_SANITIZATION ?? true;
const htmlSchemaOverrides =
common?.conf?.HTML_SANITIZATION_SCHEMA_EXTENSIONS || {};

useMemo(() => {
try {
Expand All @@ -56,7 +63,13 @@ export const HandlebarsViewer = ({
}

if (renderedTemplate) {
return <SafeMarkdown source={renderedTemplate} />;
return (
<SafeMarkdown
source={renderedTemplate}
htmlSanitization={htmlSanitization}
htmlSchemaOverrides={htmlSchemaOverrides}
/>
);
}
return <p>Loading...</p>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const propTypes = {
deleteComponent: PropTypes.func.isRequired,
handleComponentDrop: PropTypes.func.isRequired,
updateComponents: PropTypes.func.isRequired,

// HTML sanitization
htmlSanitization: PropTypes.bool,
htmlSchemaOverrides: PropTypes.object,
};

const defaultProps = {};
Expand Down Expand Up @@ -265,6 +269,8 @@ class Markdown extends React.PureComponent {
? MARKDOWN_ERROR_MESSAGE
: this.state.markdownSource || MARKDOWN_PLACE_HOLDER
}
htmlSanitization={this.props.htmlSanitization}
htmlSchemaOverrides={this.props.htmlSchemaOverrides}
/>
);
}
Expand Down Expand Up @@ -373,6 +379,8 @@ function mapStateToProps(state) {
return {
undoLength: state.dashboardLayout.past.length,
redoLength: state.dashboardLayout.future.length,
htmlSanitization: state.common.conf.HTML_SANITIZATION,
htmlSchemaOverrides: state.common.conf.HTML_SANITIZATION_SCHEMA_EXTENSIONS,
};
}
export default connect(mapStateToProps)(Markdown);

0 comments on commit a63d5d4

Please sign in to comment.