0

Hey guys is there a plugin I am missing or method I cannot find to use within Jekyll so I don't have to manually write a bunch of html tags?

Example would be {% a href="blah %}

This would render out

 <a href="blah"></a>
adrian
  • 2,326
  • 2
  • 32
  • 48

1 Answers1

1

Simple answer is no, there's no stuff built in but there are provisions for you to extend Jekyll for you needs. Unless, someone else knows better, I'm willing to be proven wrong. You have two options that I can think of though ...

Option 1: Use markdown, it's built in

Instead of what you are trying to do. Liquid (what you are using) doesn't seem to support <a> tags - see here for more info from their docs

The GitHub guides provide details on how to use Markdown;

Though the above links are for GitHub, the apply on Jekyll as well since Tom Preston-Werner (co-founder of GitHub) is the guy who wrote Jekyll. Probably because it was born out of an internal need in GitHub, and figured there's no harm open-sourcing it.

Oh, and this might be better because, if you are using GitHub pages ... they don't run any custom scripts.

Option 2: Write a custom tag

There's some documentation in the official Jekyll site on the plugin page. Something like this:

# Define the custom tag, 'a_tag'
module Jekyll
  class RenderHyperlinkTag < Liquid::Tag

    def initialize(tag_name, text, tokens)
      super
      @url = text
    end

    # At a minimum, liquid tags must implement render which outputs
    # the contents of the tag
    def render(context)
      "<a href=\"#{@url}\"></a>"
    end
  end
end

# Register the new tag, 'a_tag'
Liquid::Template.register_tag('a_tag', Jekyll::RenderHyperlinkTag)

And you'd have something like this ...

<!-- Usage -->
{% a_tag 'http://example.com' %}

<!-- Output -->
<a href="http://example.com"></a>

I must admit, I haven't tested this just giving a high level explanation of what I'd try out from what I can garner from the docs. Try it out and see if it'll work and fix any errors that may spew out (I loosely typed this).

King'ori Maina
  • 4,440
  • 3
  • 26
  • 38
  • This isn't what I'm quite looking for. It's mostly similar to a rails tag helper that I can use in templates. – adrian Mar 29 '14 at 08:18
  • 1
    @amchang87 Updated the answer with a second option. Let me know how it goes. – King'ori Maina Mar 30 '14 at 18:00
  • I agree with option #2, I was just hoping someone had something out of the box before I had to start writing my own stuff, thanks. – adrian Mar 31 '14 at 18:52