   # Show the Advanced (codemirror) Editor. Pulled out as a helper method for unit testing.
   showAdvancedEditor: (visualEditor) ->
     if visualEditor.isDirty()
-      content = visualEditor.getContent({no_events: 1})
-      regex = new RegExp(@base_asset_url, 'g')
-      content = content.replace(regex, '/static/')
+      content = @rewriteStaticLinks(visualEditor.getContent({no_events: 1}), @base_asset_url, '/static/')
       @advanced_editor.setValue(content)
       @advanced_editor.setCursor(0)
     @advanced_editor.refresh()
     @advanced_editor.focus()
     @showingVisualEditor = false
 
+  rewriteStaticLinks: (content, from, to) ->
+    regex = new RegExp(from, 'g')
+    return content.replace(regex, to)    
+
   # Show the Visual (tinyMCE) Editor. Pulled out as a helper method for unit testing.
   showVisualEditor: (visualEditor) ->
     # In order for isDirty() to return true ONLY if edits have been made after setting the text,
     # both the startContent must be sync'ed up and the dirty flag set to false.
-    visualEditor.startContent = visualEditor.getContent({format: "raw", no_events: 1});
+    content = @rewriteStaticLinks(@advanced_editor.getValue(), '/static/', @base_asset_url)
+    visualEditor.setContent(content)
+    visualEditor.startContent = content
     @focusVisualEditor(visualEditor)
     @showingVisualEditor = true
 
+  initInstanceCallback: (visualEditor) =>
+    visualEditor.setContent(@rewriteStaticLinks(@advanced_editor.getValue(), '/static/', @base_asset_url))
+    @focusVisualEditor(visualEditor)
+
   focusVisualEditor: (visualEditor) =>
-    content = @advanced_editor.getValue()
-    regex = new RegExp('/static/', 'g')
-    content = content.replace(regex, @base_asset_url)
-    visualEditor.setContent(content)
-
     visualEditor.focus()
     # Need to mark editor as not dirty both when it is initially created and when we switch back to it.
     visualEditor.isNotDirty = true

    text = @advanced_editor.getValue()
    visualEditor = @getVisualEditor()
    if @showingVisualEditor and visualEditor.isDirty()
      text = visualEditor.getContent({no_events: 1})
      regex = new RegExp(@base_asset_url, 'g')
      text = text.replace(regex, '/static/')
    data: text

      setup : @setupTinyMCE,
      # Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered.
      # The tinyMCE callback passes in the editor as a paramter.
      init_instance_callback: @initInstanceCallback
    })

    @showingVisualEditor = true
