Collapse long text (with more/less links)
Instead of pn use a longer variable name. A variable like this with such a big scope really deserves a longer name. It would make the code easier to read.

var pn = text.split(' ');

Instead of commenting use the comment name as a function name:

// escape the html code in the text
text = (text || '').replace(/&lt;/g, '&amp;lt;').replace(/&gt;/g,'&amp;gt;').replace(/\r/g, ' ').replace(/\n/g, ' &lt;br&gt; ')


I'd write this:

function escapeHtml(text) {
    if (!text) {
        return "";
    }
    return text.replace(/&lt;/g, '&amp;lt;').replace(/&gt;/g,'&amp;gt;').replace(/\r/g, ' ').replace(/\n/g, ' &lt;br&gt; ')        
}

I'd create a createToggleLink function. 

function createToggleLink(prefix, linkText) {
    return '&lt;a href="#" onclick="javascript:$(' +
            "'." + prefix + "-more-text').toggle(); return false;" +
            '"&gt;(" + linkText + ")&lt;/a&gt;');
}


It removes some code duplication and furthermore makes it more explicit that you close the span tag:

if (compacted) {
    var toggleLink = createToggleLink(prefix, '(show less)');
    result.push(toggleLink);
    result.push('&lt;/span&gt;');
}


So, the comment is unnecessary, the code says the same.