         # url has no protocol
         url = '//'+url
 
-      "<a href='#{url}' data-original-url='#{originalUrl}' target='_blank' >#{visibleUrl}#{if checkForPostSlash then "/…" else ""}<span class='expanded-link'></span></a>"
+      # Just yield a placeholder string for replacement later on
+      # this is needed if the text should get shortened, add expanded
+      # string to array at corresponding index
+      if replaceAndYieldLinks
+        links.push "<a href='#{url}' data-original-url='#{originalUrl}' target='_blank' >#{visibleUrl}#{if checkForPostSlash then "/…" else ""}<span class='expanded-link'></span></a>"
+        "[tempLink#{linkCount++}]"
+      else
+        # yield the replacement inline (good for non-shortened text)
+        "<a href='#{url}' data-original-url='#{originalUrl}' target='_blank' >#{visibleUrl}#{if checkForPostSlash then "/…" else ""}<span class='expanded-link'></span></a>"
+
+    if replaceAndYieldLinks
+      {
+        links
+        text
+      }
+    else
+      text
 
   putShowMore: (text, l = 500)->
     shortenedText = __utils.shortenText text,

      longText = Encoder.htmlDecode longText

      tempText = longText.slice 0, maxLength
      lastClosingTag = tempText.lastIndexOf "</a"
      lastOpeningTag = tempText.lastIndexOf "<a"


      if lastOpeningTag <= lastClosingTag
        finalMaxLength = maxLength
      else
        finalMaxLength = lastOpeningTag

      return longText if longText.replace(/(<([^>]+)>)/ig,"").length < minLength or longText.replace(/(<([^>]+)>)/ig,"").length < maxLength

      longText = longText.substr 0, finalMaxLength



  applyTextExpansions: (text, shorten)->
    return null unless text

    text = text.replace /&#10;/g, ' '
    text = @expandUsernames text

    # Expand URLs with intention to replace them after putShowMore
    {links,text} = @expandUrls text, yes

    text = __utils.putShowMore text if shorten

    # Reinsert URLs into text
    if links? then for link,i in links
      text = text.replace "[tempLink#{i}]", link

    return text
    # @expandWwwDotDomains @expandUrls @expandUsernames text

  expandWwwDotDomains: (text) ->
