diff --git a/client/src/templates/Challenges/redux/create-question-epic.js b/client/src/templates/Challenges/redux/create-question-epic.js index e01f001147a..93ff05697b2 100644 --- a/client/src/templates/Challenges/redux/create-question-epic.js +++ b/client/src/templates/Challenges/redux/create-question-epic.js @@ -43,13 +43,36 @@ function createQuestionEpic(action$, state$, { window }) { ofType(actionTypes.createQuestion), tap(() => { const state = state$.value; - const challengeFiles = challengeFilesSelector(state); + let challengeFiles = challengeFilesSelector(state); const { title: challengeTitle, superBlock, block, helpCategory } = challengeMetaSelector(state); + if ( + challengeFiles?.some(file => file.editableRegionBoundaries.length > 0) + ) { + const editableRegionStrings = fileExtension => { + const startComment = fileExtension === 'html' ? '' : '*/'; + return `\n${startComment} User Editable Region ${endComment}\n`; + }; + + const filesWithEditableRegions = challengeFiles.map(file => { + const { contents, editableRegionBoundaries, ext } = file; + if (editableRegionBoundaries.length > 0) { + const comment = editableRegionStrings(ext); + const [start, end] = editableRegionBoundaries; + const lines = contents.split('\n'); + lines.splice(start, 0, comment); + lines.splice(end, 0, comment); + return { ...file, contents: lines.join('\n') }; + } + return file; + }); + challengeFiles = filesWithEditableRegions; + } const { navigator: { userAgent }, location: { pathname, origin }