return headContentLines.slice(startLineIndex + 1, endLineIndex).join('\n');
}
+/**
+ * Setup a serializer filter for <br> tags to ensure they're not rendered
+ * within code blocks and that we use newlines there instead.
+ * @param {Editor} editor
+ */
+function setupBrFilter(editor) {
+ editor.serializer.addNodeFilter('br', function(nodes) {
+ for (const node of nodes) {
+ if (node.parent && node.parent.name === 'code') {
+ const newline = new tinymce.html.Node.create('#text');
+ newline.value = '\n';
+ node.replace(newline);
+ }
+ }
+ });
+}
+
/**
* @param {WysiwygConfigOptions} options
* @return {function(Editor)}
window.editor = editor;
});
+ editor.on('PreInit', () => {
+ setupBrFilter(editor);
+ });
+
function editorChange() {
const content = editor.getContent();
if (options.darkMode) {