File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
src/schedule-and-details/introducing-section Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { WysiwygEditor } from '../../generic/WysiwygEditor';
1111import SectionSubHeader from '../../generic/section-sub-header' ;
1212import IntroductionVideo from './introduction-video' ;
1313import ExtendedCourseDetails from './extended-course-details' ;
14+ import { determineEditorType } from './contentTypeUtils' ;
1415import messages from './messages' ;
1516
1617const 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 >
You can’t perform that action at this time.
0 commit comments