# HG changeset patch # User nanaya # Date 1441480850 -32400 # Node ID a18e19139f57b4ab0818d10453490bcff9c05be6 # Parent 6bb805283daf1879571f4f09f232b3705d2b2eb4 Markdown preview \o/ diff -r 6bb805283daf -r a18e19139f57 app/assets/javascripts/application.coffee --- a/app/assets/javascripts/application.coffee Sun Sep 06 04:01:22 2015 +0900 +++ b/app/assets/javascripts/application.coffee Sun Sep 06 04:20:50 2015 +0900 @@ -11,7 +11,7 @@ pasteText = -> - $(".js-paste-pl").text() + $(".js-paste-paste").val() || $(".js-paste-pl").text() setHash = (newLocation = window.location.pathname) -> @@ -21,6 +21,12 @@ history.replaceState null, "", newLocation +markdownfy = (plaintext) -> + reader = new commonmark.Parser + writer = new commonmark.HtmlRenderer(safe: true) + writer.render reader.parse(plaintext) + + $(document).on "click", ".js-show-tab-pl", -> setHash() @@ -43,14 +49,17 @@ $mdBox = $(".js-paste-md") return if $mdBox.data("processed") - reader = new commonmark.Parser - writer = new commonmark.HtmlRenderer(safe: true) - parsed = reader.parse pasteText() - - $mdBox.html writer.render(parsed) + $mdBox.html markdownfy(pasteText()) $mdBox.find("a").attr("rel", "nofollow") $mdBox.data "processed", true + +$(document).on "click", ".js-paste-preview-md", -> + return if pasteText() == "" + $(".js-paste-preview-md-box").html markdownfy(pasteText()) + $(".js-paste-preview-md-modal").modal "show" + + $(document).on "ready", -> return if $(".js-showing-paste").length < 1 diff -r 6bb805283daf -r a18e19139f57 app/views/pastes/new.html.erb --- a/app/views/pastes/new.html.erb Sun Sep 06 04:01:22 2015 +0900 +++ b/app/views/pastes/new.html.erb Sun Sep 06 04:20:50 2015 +0900 @@ -1,4 +1,5 @@ <% provide :title, t(".title") %> + <%= form_for @paste do |f| %> <%= render "shared/filter_spam" %> @@ -6,6 +7,13 @@ <%= f.text_area :paste, :autofocus => true, :class => "form-control paste-paste js-paste-paste", :rows => 20 %> + +
+ <%= link_to t(".preview_md"), "#", + :class => "btn btn-default js-paste-preview-md pull-right" + %> +
+
<%= f.label :key, t(".deletion_key"), :class => "col-sm-2 control-label" %> @@ -36,3 +44,17 @@
<% end %> + + diff -r 6bb805283daf -r a18e19139f57 config/locales/en.yml --- a/config/locales/en.yml Sun Sep 06 04:01:22 2015 +0900 +++ b/config/locales/en.yml Sun Sep 06 04:20:50 2015 +0900 @@ -10,7 +10,9 @@ pastes: new: clear: Clear + close: Close deletion_key: Deletion Key + preview_md: Preview Markdown privacy: label: Privacy private: Private