Skip to content

Commit ac5758d

Browse files
committed
Merge pull request #206 from carlwoodward/307-protip-preview
Fix #307 - provide protip live preview.
2 parents 8113cb4 + 98ab89e commit ac5758d

File tree

4 files changed

+223
-178
lines changed

4 files changed

+223
-178
lines changed

app/assets/javascripts/protips.js.coffee

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Place all the behaviors and hooks related to the matching controller here.
22
# All this logic will automatically be available in application.js.
33
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4-
#= require showdown
4+
#= require marked
5+
#= require highlight/highlight
6+
#= require highlight/language
57
#= require blur
68
#= require jquery.filedrop
79
#= require jquery.textselection
@@ -31,6 +33,8 @@ $ ->
3133
if event.keyCode == 13
3234
search(null)
3335

36+
enablePreviewEditing()
37+
3438

3539
window.initializeProtip = ->
3640
if inEditMode = $(".x-tip-content.preview").length > 0
@@ -344,3 +348,16 @@ toggleCommentEditMode = (comment)->
344348
comment.children('p').first().toggleClass('hidden')
345349
comment.find('.edit-comment').toggleClass('hidden')
346350
comment.siblings('ul.edit-del').toggleClass('hidden')
351+
352+
marked.setOptions highlight: (code) ->
353+
hljs.highlightAuto(code).value
354+
355+
enablePreviewEditing = ->
356+
if $('.preview-body').length > 0
357+
updatePreview = ->
358+
markdown = marked $('#protip_body').val(), gfm: true
359+
$('.preview-body').html markdown
360+
361+
$('#protip_body').on 'keyup', updatePreview
362+
363+
updatePreview()

0 commit comments

Comments
 (0)