4

I am using Octopress and I know that in order to add an image in my post, instead of writing:

<img src="src" alt="alt" class="class" />

I can write:

{% img class src alt %}

And, instead if writing:

<a href="href">text</a>

I can write:

[text](href)

But how can I write:

<a href="href" target="target">text</a>

?

If this is not possible and the only solution is to write the html tag, where and how can I add ruby code translate this for example: [text](href target) to this: <a href="href" target="target">text</a>?

In addition, where can I find a list of all those html octopress shortcuts?

seliopou
  • 2,896
  • 20
  • 19
Naor
  • 23,465
  • 48
  • 152
  • 268

3 Answers3

1

This is actually controlled by the Markdown engine used to process the text rather than any Octopress code. Depending on the engine you are using, you can write

[text](href){: target="target" }

This is called an "inline attribute list", and is an extension to the Markdown syntax. It is supported by Maruku, as well as Kramdown.

(Note that Maruku is Jekyll's default Markdown engine, so this syntax is supported if you haven't touched this aspect of the configuration.)

huon
  • 94,605
  • 21
  • 231
  • 225
  • For some reason this doesn't work and just append {: target="_blank" } after the anchor text. Do you have any idea why? – Naor Jan 12 '13 at 13:54
0

Use the Markdown Syntax:

[text](#target)

For <a href="href" target="target">text</a>

[text](href){: target="target" }
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
  • For some reason this doesn't work and just append {: target="_blank" } after the anchor text. Do you have any idea why? – Naor Jan 12 '13 at 13:54
0

The {% img class src alt %} is a octopress tag, see the plugin docs for more tags.

The [text](href) follow the markdown sintax, and does not let you add classes, attributes, or ids to elements.

So to workaround the target problem use the snipet below in your custom header layout, and added the #_blank anchor at the end of the url, to open in a new window.

<script type="text/javascript">
function addBlankTargetForLinks () {
    $('a[href^="http"],a[href*="#_blank"]').each(function(){
        $(this).attr('target', '_blank');
    });
}

$(document).bind('DOMNodeInserted', function(event) {
    addBlankTargetForLinks();
});
</script>
Wagner Pinheiro
  • 339
  • 5
  • 14