2424use DOMNode ;
2525use DOMXPath ;
2626use file_exception ;
27+ use html_writer ;
2728use Iterator ;
2829use moodle_exception ;
2930use moodle_url ;
@@ -145,6 +146,7 @@ public static function from_element(DOMElement $element): ?static {
145146 * @throws stored_file_creation_exception
146147 */
147148 public function render (question_attempt $ qa , question_ui_renderer $ renderer ): DOMNode {
149+ $ html = html_writer::start_div ('qpy-editor-container ' . ($ renderer ->options ->readonly ? 'readonly ' : '' ));
148150 if ($ renderer ->options ->readonly ) {
149151 global $ PAGE ;
150152 /** @var qtype_questionpy_renderer $qpyrenderer */
@@ -154,7 +156,7 @@ public function render(question_attempt $qa, question_ui_renderer $renderer): DO
154156 $ editorsdata = utils::get_qpy_editors_data ($ responsestep ->get_qt_data ());
155157 $ editordata = $ editorsdata [$ this ->name ] ?? null ;
156158
157- $ html = $ qpyrenderer ->render_readonly_editor_content (
159+ $ html . = $ qpyrenderer ->render_readonly_editor_content (
158160 $ editordata ,
159161 qubaid: $ qa ->get_usage_id (),
160162 slot: $ qa ->get_slot (),
@@ -164,24 +166,27 @@ public function render(question_attempt $qa, question_ui_renderer $renderer): DO
164166 rows: $ this ->rows ,
165167 cols: $ this ->cols
166168 );
167- return dom_utils::html_to_fragment ($ this ->element ->ownerDocument , $ html );
168- } {
169- return $ this ->render_writable ($ renderer , $ qa );
169+ } else {
170+ $ html .= $ this ->render_writable ($ renderer , $ qa );
170171 }
172+
173+ $ html .= html_writer::end_div ();
174+
175+ return dom_utils::html_to_fragment ($ this ->element ->ownerDocument , $ html );
171176 }
172177
173178 /**
174179 * Renders an editor using the usual Moodle APIs.
175180 *
176181 * @param question_ui_renderer $renderer
177182 * @param question_attempt $qa
178- * @return DOMDocumentFragment|false|void
183+ * @return string HTML
179184 * @throws coding_exception
180185 * @throws file_exception
181186 * @throws moodle_exception
182187 * @throws stored_file_creation_exception
183188 */
184- public function render_writable (question_ui_renderer $ renderer , question_attempt $ qa ) {
189+ public function render_writable (question_ui_renderer $ renderer , question_attempt $ qa ): string {
185190 $ limits = $ this ->get_limits_in ($ renderer ->options ->context );
186191
187192 $ alleditorsdata = utils::get_qpy_editors_data ($ qa );
@@ -241,7 +246,7 @@ public function render_writable(question_ui_renderer $renderer, question_attempt
241246
242247 $ meditor ->setValue ($ values );
243248
244- return dom_utils:: html_to_fragment ( $ this -> element -> ownerDocument , $ meditor ->toHtml () );
249+ return $ meditor ->toHtml ();
245250 }
246251
247252 /**
0 commit comments