From 5f05ec83f198db2e14d59a56605ed132825ba42d Mon Sep 17 00:00:00 2001 From: cahrens Date: Thu, 17 Jan 2013 13:11:47 -0500 Subject: [PATCH] Change the div being used to create code mirror to a textarea-- just make sure to escape the content! Update tests accordingly. --- cms/templates/widgets/html-edit.html | 4 ++-- .../js/fixtures/html-edit-formattingbug.html | 23 +++++++++++++------ .../xmodule/js/fixtures/html-edit.html | 2 +- .../xmodule/js/spec/html/edit_spec.coffee | 16 ++++++------- .../xmodule/xmodule/js/src/html/edit.coffee | 9 ++++---- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/cms/templates/widgets/html-edit.html b/cms/templates/widgets/html-edit.html index 6d7f3386c6..7a9d563a57 100644 --- a/cms/templates/widgets/html-edit.html +++ b/cms/templates/widgets/html-edit.html @@ -6,7 +6,7 @@
- -
${data}
+ +
diff --git a/common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html b/common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html index 4ba4a971c8..5db864373d 100644 --- a/common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html +++ b/common/lib/xmodule/xmodule/js/fixtures/html-edit-formattingbug.html @@ -1,9 +1,18 @@
- -
<problem> -<p></p> -<multiplechoiceresponse> -
<problem>
-    <p></p>
-
bar
+ + +
\ No newline at end of file diff --git a/common/lib/xmodule/xmodule/js/fixtures/html-edit.html b/common/lib/xmodule/xmodule/js/fixtures/html-edit.html index 62f46a00ea..22dfc97dcb 100644 --- a/common/lib/xmodule/xmodule/js/fixtures/html-edit.html +++ b/common/lib/xmodule/xmodule/js/fixtures/html-edit.html @@ -5,6 +5,6 @@
-
Advanced Editor Text
+
\ No newline at end of file diff --git a/common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee b/common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee index d18fbf7172..554235ef9c 100644 --- a/common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/html/edit_spec.coffee @@ -13,12 +13,12 @@ describe 'HTMLEditingDescriptor', -> spyOn(@descriptor, 'getVisualEditor').andCallFake () -> visualEditorStub data = @descriptor.save().data - expect(data).toEqual("""<problem> - <p></p> - <multiplechoiceresponse> -
<problem>
-                                  <p></p>
-
bar
""") + expect(data).toEqual("""<problem> + <p></p> + <multiplechoiceresponse> +
<problem>
+                               <p></p>
+
bar
""") describe 'Saves HTML', -> beforeEach -> loadFixtures 'html-edit.html' @@ -52,7 +52,7 @@ describe 'HTMLEditingDescriptor', -> beforeEach -> loadFixtures 'html-edit.html' @descriptor = new HTMLEditingDescriptor($('.html-edit')) - it 'Populates from Advanced Editor if Advanced Editor is dirty', -> + it 'Populates from Visual Editor if Advanced Visual is dirty', -> expect(@descriptor.showingVisualEditor).toEqual(true) visualEditorStub = isDirty: () -> true @@ -60,7 +60,7 @@ describe 'HTMLEditingDescriptor', -> @descriptor.showAdvancedEditor(visualEditorStub) expect(@descriptor.showingVisualEditor).toEqual(false) expect(@descriptor.advanced_editor.getValue()).toEqual('from visual editor') - it 'Does not populate from Advanced Editor if Advanced Editor is not dirty', -> + it 'Does not populate from Visual Editor if Visual Editor is not dirty', -> expect(@descriptor.showingVisualEditor).toEqual(true) visualEditorStub = isDirty: () -> false diff --git a/common/lib/xmodule/xmodule/js/src/html/edit.coffee b/common/lib/xmodule/xmodule/js/src/html/edit.coffee index 63fed014dc..2902f4d1c9 100644 --- a/common/lib/xmodule/xmodule/js/src/html/edit.coffee +++ b/common/lib/xmodule/xmodule/js/src/html/edit.coffee @@ -3,13 +3,12 @@ class @HTMLEditingDescriptor constructor: (element) -> @element = element; - text = $(".edit-box", @element)[0]; - replace_func = (elt) -> text.parentNode.replaceChild(elt, text) - @advanced_editor = CodeMirror(replace_func, { - value: text.innerHTML + + @advanced_editor = CodeMirror.fromTextArea($(".edit-box", @element)[0], { mode: "text/html" lineNumbers: true - lineWrapping: true}) + lineWrapping: true + }) $(@advanced_editor.getWrapperElement()).addClass(HTMLEditingDescriptor.isInactiveClass)