             allowedAttributes: [["href", ["a"]], ["style"]],
             removeAttrs: ["id", "class", "onclick", "ondblclick", "accesskey", "data", "dynsrc", "tabindex",],
         }
-        cleaned_html = $.htmlClean($html_div_hidden.html(), html_clean_option);
+        cleaned_html = $.htmlClean(jq_element.html(), html_clean_option);
         # FIXME hack for strange class attr not removed
         cleaned_html = cleaned_html.replace(/class="[^"]*"/g, "")
 
         # embbed raw markdown content into the html
         cleaned_html = cleaned_html +
             "<center style='display:none'>" +
-            $('<div />').text(vm.markdown).html() +
+            $('<div />').text(markdown).html() +
             "</center>"
 
         # add XML header & wrap with <en-note></en-note>

    # ------------------------------------------------------------------------------------------------------------------
    vm.save_note = ->
        # fill the hidden html div
        $html_div_hidden = $("#md_html_div_hidden")

        # highlight code & style Latex
        $html_div_hidden.find('pre code').each (i, block) ->
            hljs.highlightBlock(block)
        MathJax.Hub.Queue(["Typeset", MathJax.Hub, $html_div_hidden.get(0)])

        # remove all script tags
        $html_div_hidden.find("script").remove()

        # add inline style
        # refer: https://github.com/Karl33to/jquery.inlineStyler

    # refer: http://stackoverflow.com/questions/18952623/synchronized-scrolling-using-jquery
    # ------------------------------------------------------------------------------------------------------------------
    $scope.aceLoaded = (editor) =>
        scrollSyncor.syncScroll(editor, $html_div)

    $scope.aceChanged = (e) ->
        $html_div = $("#md_html_div")
