         (error) =>
           alert('vm.html_post_process() failed due to failure in imageManager.find_image_by_uuid(' + uuid + ')')
       )
+      must_finish_promise_list.push(p)
+    return Promise.all(must_finish_promise_list).then () -> return jq_tmp_div
 
   # ------------------------------------------------------------------------------------------------------------------
   # Operations for notes

    # remove all script tags
    jq_html_div.find('script').remove()

    # set src of img to full data url
    jq_html_div.find('img[src]').attr 'src', (i, src) ->

    # add inline style
    # refer: https://github.com/Karl33to/jquery.inlineStyler
    # TODO still too much redundant styles

  # markdown render functions
  # ------------------------------------------------------------------------------------------------------------------
  vm.render_html = (jq_html_div) ->
    processed_md = vm.md_pre_process(vm.get_md())
    _html_dom = $('<div></div>')
    _html_dom.html($window.marked(processed_md, {sanitize: true}))
    vm.html_post_process(_html_dom).then () ->
      jq_html_div.empty()
      jq_html_div.append(_html_dom)

  vm.md_pre_process = (md) ->
    # TODO more handling
    processed_md = md
    return processed_md

  # return promise
  vm.html_post_process = (jq_tmp_div) ->
    # code highlighting
    jq_tmp_div.find('pre code').each (i, block) ->
      hljs.highlightBlock(block)
    # render Latex
    MathJax.Hub.Queue(['Typeset', MathJax.Hub, jq_tmp_div.get(0)])
    # change img src to real data url
    must_finish_promise_list = []
    jq_tmp_div.find('img[src]').each (index) ->
      $img = $(this)
      uuid = $img.attr('src')
      p = imageManager.find_image_by_uuid(uuid).then(
        (image) =>
          if image?
            console.log('change img src from ' + uuid + ' to its base64 content')
