Skip to content

Commit 2489cc7

Browse files
fix: contentAnalyzer added to determine TinyMCE Editor type
1 parent 6afe609 commit 2489cc7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Utility functions for detecting content type and
3+
* determining appropriate editor type for TinyMCE editor
4+
*/
5+
6+
/**
7+
* Detects if content contains HTML tags
8+
* @param {string} content - The content to analyze
9+
* @returns {boolean} - True if content contains HTML tags
10+
*/
11+
export const containsHtml = (content) => {
12+
if (!content || typeof content !== 'string') {
13+
return false;
14+
}
15+
16+
// Check for common HTML patterns
17+
const htmlPatterns = [
18+
/<\/?[a-z][\s\S]*>/i, // HTML tags
19+
/&[a-z]+;/i, // HTML entities
20+
/&#\d+;/, // Numeric entities
21+
];
22+
23+
return htmlPatterns.some(pattern => pattern.test(content));
24+
};
25+
26+
/**
27+
* Determines the appropriate editor type based on content analysis
28+
* @param {string} content - The content to analyze
29+
* @returns {string} - The recommended editor type ('text' or 'html')
30+
*/
31+
export const determineEditorType = (content) => {
32+
if (!content || typeof content !== 'string') {
33+
return 'text';
34+
}
35+
36+
// If content contains HTML, use html editor for better HTML editing
37+
if (containsHtml(content)) {
38+
return 'html';
39+
}
40+
41+
// For plain text content, use text editor
42+
return 'text';
43+
};

src/schedule-and-details/introducing-section/index.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { WysiwygEditor } from '../../generic/WysiwygEditor';
1111
import SectionSubHeader from '../../generic/section-sub-header';
1212
import IntroductionVideo from './introduction-video';
1313
import ExtendedCourseDetails from './extended-course-details';
14+
import { determineEditorType } from './contentTypeUtils';
1415
import messages from './messages';
1516

1617
const IntroducingSection = ({
@@ -112,6 +113,7 @@ const IntroducingSection = ({
112113
<Form.Label>{intl.formatMessage(messages.courseOverviewLabel)}</Form.Label>
113114
<WysiwygEditor
114115
initialValue={overview}
116+
editorType={determineEditorType(overview)}
115117
onChange={(value) => onChange(value, 'overview')}
116118
/>
117119
<Form.Control.Feedback>{overviewHelpText}</Form.Control.Feedback>
@@ -121,6 +123,7 @@ const IntroducingSection = ({
121123
<Form.Label>{intl.formatMessage(messages.courseAboutSidebarLabel)}</Form.Label>
122124
<WysiwygEditor
123125
initialValue={aboutSidebarHtml}
126+
editorType={determineEditorType(aboutSidebarHtml)}
124127
onChange={(value) => onChange(value, 'aboutSidebarHtml')}
125128
/>
126129
<Form.Control.Feedback>{aboutSidebarHelpText}</Form.Control.Feedback>

0 commit comments

Comments
 (0)