Simple javascript search-and-replace
<p>I know zero javascript, and have one simple task:</p>

<ol>
<li>Find all text in the current html of the form [[.+?]]</li>
<li>Extract the content of the brackets</li>
<li>Replace all space characters with underscores</li>
<li>Instead of the entire expression, output <code>&lt;img src="foo.com/$1.jpg"/&gt;</code>, where $1 is the matched text (after spaces have been replaced).</li>
<li>(This should be done for all text inside [[]] in the html)</li>
</ol>

<p>Can I bother you with a snippet that does this?</p>
