Adding Target="_blank" to HTML Links

I have just started using Scrivener for blogging. It works great, by the way.

I write everything in markdown. I then compile to HTML and give it to my assistant to post into WordPress. I noticed that links are being compiled to open in the same page. However, I prefer having them open in a new page.

For example, rather than this:

<a href="http://michaelhyatt.com" title="Michael Hyatt’s Blog">Michael Hyatt’s Blog</a>

I’d prefer this:

<a href="http://michaelhyatt.com" title="Michael Hyatt’s Blog" target="_blank">Michael Hyatt’s Blog</a>

This may already exist within the compiler. If so, I can’t seem to find it.

Is there a way to do this? It’s a small thing, but it keeps my assistant from having to add these manually.

Thanks.

Actually everything that happens to MultiMarkdown files at this level of detail is handled outside of Scrivener. All it does is assemble the final MMD file that gets used to make the HTML. So for a request of this nature you would need to refer to the MMD group discussion (I think they are still on Google Groups). As far as I know there isn’t a way to do this automatically, though. You’d have to use the XSLT workflow to transform the HTML output.

A quickish workaround would be:

(1) open the HTML file in a text editor

(2) search for
">

(3) replace with
" target="_blank">

I checked the MultiMarkdown documentation, as I recalled you could add attributes to images and links if you used the referenced syntax as opposed to inline. Here is what you can do:

This is the body text, with a [hyperlink][].

[hyperlink]: http://www.literatureandlatte.com target="_blank"

Basically anything after the URL will get added into the a element verbatim, so you can put class, style and other useful things in here too. A quoted string after the URL will be added as a title attribute, too.

In practice, the link definition can be placed anywhere in the project so long as it is compiled. So you can collect all of your link references into one location if you prefer, or at the end of every section, or even just straight after the paragraph (as shown in the sample above).

This works beautifully. Thanks. I didn’t even know that was possible. One thing I had to do, however, was turn off Markdown Compatibility Mode in the compiler:

Otherwise, some of the straight quotes get converted to HTML entities, like this:

<a href="http://www.eventualmillionaire.com/blog/" title="Jamie Tardy’s The Eventual Millionaire Blog" target="_blank">Jamie Tardy</a>

Rather than this:

<a href="http://www.eventualmillionaire.com/blog/" title="Jamie Tardy’s The Eventual Millionaire Blog" target="_blank">Jamie Tardy</a>

Thanks again.