     $editable.find('p:not([data-section-id])').each ->
       $(this).addClass('commentable-section').attr('data-section-id', i)
       i++
+
+    # Highlight code blocks
+    highlightSyntax tpl
 
     if $editable.get(0)
       editor = makeEditor tpl

    this.tagsinput('input').typeahead('val', '')
  , $('input[data-role="tagsinput"]'))

  # Syntax highlighting
  if Blog.settings.syntaxHighlighting
    hljs.configure({userBR: true})

    br2nl = (i, html) ->
      html
        # medium-editor leaves <br>'s in <pre> tags, which screws up
        # highlight.js. Replace them with actual newlines.
        .replace(/<br>/g, "\n")
        # Strip out highlight.js tags so we don't create them multiple times
        .replace(/<[^>]+>/g, '')

    # Remove 'hljs' class we don't create it multiple times
    @$('pre').removeClass('hljs').html(br2nl).each (i, block) ->
      hljs.highlightBlock(block)

  # Medium editor
  makeEditor @

Template.blogAdminEdit.helpers
  post: ->
    getPost()

setEditMode = (tpl, mode) ->
  tpl.$('.editable').toggle()
  tpl.$('.html-editor').toggle()
  tpl.$('.edit-mode a').removeClass 'selected'
  tpl.$(".#{mode}-toggle").addClass 'selected'

Template.blogAdminEdit.events
  'click .mediumInsert-action': (e, tpl) ->


    post = getPost()
    post.body = $html.val()?.trim()
    highlightSyntax tpl
    setEditMode tpl, 'visual'

  'click .html-toggle': (e, tpl) ->
