Index: app/controllers/previews_controller.rb
===================================================================
--- app/controllers/previews_controller.rb	(revision 6631)
+++ app/controllers/previews_controller.rb	(working copy)
@@ -38,6 +38,11 @@
     render :partial => 'common/preview'
   end
 
+  def documents
+    @text = (params[:document] ? params[:document][:description] : nil)
+    render :partial => 'common/preview'
+  end
+  
   private
   
   def find_project
Index: app/views/documents/edit.rhtml
===================================================================
--- app/views/documents/edit.rhtml	(revision 6631)
+++ app/views/documents/edit.rhtml	(working copy)
@@ -1,8 +1,18 @@
 <h2><%=l(:label_document)%></h2>
 
-<% form_tag({:action => 'edit', :id => @document}, :class => "tabular") do %>
-  <%= render :partial => 'form' %>
-  <%= submit_tag l(:button_save) %>
+<% form_for :document, @document, :url => {:action => 'edit'}, :html => {:multipart => true, :id => 'document-form'} do |f| %>
+<%= render :partial => 'form', :locals => { :f => f } %>
+<%= submit_tag l(:button_save) %>
+<%= link_to_remote l(:label_preview), 
+                   { :url => preview_documents_path(:project_id => @project),
+                     :method => 'post',
+                     :update => 'preview',
+                     :with => "Form.serialize('document-form')"
+                   }, :accesskey => accesskey(:preview) %>
 <% end %>
+<div id="preview" class="wiki"></div>
 
+<% content_for :header_tags do %>
+  <%= stylesheet_link_tag 'scm' %>
+<% end %>
 
Index: app/views/documents/index.rhtml
===================================================================
--- app/views/documents/index.rhtml	(revision 6631)
+++ app/views/documents/index.rhtml	(working copy)
@@ -7,14 +7,23 @@
 
 <div id="add-document" style="display:none;">
 <h2><%=l(:label_document_new)%></h2>
-<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :class => "tabular", :multipart => true) do %>
+
+<% form_tag({:controller => 'documents', :action => 'new', :project_id => @project}, :id=>"documents-form",:class => "tabular", :multipart => true) do %>
 <%= render :partial => 'documents/form' %>
 <div class="box">
 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
 </div>
 <%= submit_tag l(:button_create) %>
+<%= link_to_remote l(:label_preview), 
+                   { :url => preview_documents_path(:project_id => @project),
+                     :method => 'post',
+                     :update => 'preview',
+                     :with => "Form.serialize('documents-form')"
+                   }, :accesskey => accesskey(:preview) %>| 
 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-document")' %>
 <% end %>
+<div id="preview" class="wiki"></div>
+
 </div>
 
 <h2><%=l(:label_document_plural)%></h2>
Index: config/routes.rb
===================================================================
--- config/routes.rb	(revision 6631)
+++ config/routes.rb	(working copy)
@@ -144,6 +144,7 @@
   map.all_news 'news', :controller => 'news', :action => 'index'
   map.formatted_all_news 'news.:format', :controller => 'news', :action => 'index'
   map.preview_news '/news/preview', :controller => 'previews', :action => 'news'
+  map.preview_documents '/documents/preview', :controller => 'previews', :action => 'documents'
   map.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
   map.connect 'news/:id/comments/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
 
