Project

General

Profile

Change macro syntax?

Added by FLX _ almost 14 years ago

Hi,

I'm very new to Ruby/Redmine but trying to create a macro that produces <a href="link_url" class"external">link_name</a> when invoking a macro formed like this: [link_name|link_url]

I made the following up but I can't make it change the macro syntax, it only responds to {{link(link_name,link_url}}:

  Redmine::WikiFormatting::Macros.register do
    desc "Creates a link to an external page" 
    macro :link do |obj, args|
      return nil if args.length < 1
      link_name = args[0]
      link_url  = args[1]
      o = '<a href="'+link_url+'" class="external">'+link_name+'</a>'
      return o
    end
  end

Can someone point out the error in my ways?

Thanks,

Dennis


Replies (7)

RE: Change macro syntax? - Added by Felix Schäfer almost 14 years ago

FLX _ wrote:

I made the following up but I can't make it change the macro syntax, it only responds to {{link(link_name,link_url}}:

Macros defined through Redmine::WikiFormatting::Macros.register are always called with {{macro_name(argument_1, argument_2)}}. You can get external links with "Foo" :http://foo.bar (minus the extra space) though, so I don't see the point of this particular example…

RE: Change macro syntax? - Added by FLX _ almost 14 years ago

Hi Felix,

The reason why I'd like to change this is because 90% of the time I'm working with Atlassian products (JIRA, Confluence, etc.), which all use [link_name|link_url] as sytax, so I rather keep it unified.

I came across several macros (such as the url macro) that doesn't use the regular macro syntax but uses "Foo": http://foo.bar instead, which gives me a reason to believe you can have your own syntax markup. Does anyone know how to do this?

Thanks,

Dennis

RE: Change macro syntax? - Added by Felix Schäfer almost 14 years ago

FLX _ wrote:

I came across several macros (such as the url macro) that doesn't use the regular macro syntax but uses "Foo": http://foo.bar instead, which gives me a reason to believe you can have your own syntax markup. Does anyone know how to do this?

Those are not macros (i.e. additions to the wiki syntax) but part of the core Textile wiki syntax. You can certainly extend that with whatever markup suits you, but you can't do it with macros, you'd have to do more "heavy" monkey-patching.

RE: Change macro syntax? - Added by FLX _ almost 14 years ago

Ah, that explains! It seems I've bit off more than I could chew, as usual :)
Do you have any idea how I can extend RedCloth (Ruby's textile parser) via a plugin?
As previously mentioned I'm quite new and a code example would work wonders.

Many thanks and merry christmas,

Dennis

RE: Change macro syntax? - Added by Felix Schäfer almost 14 years ago

The wiki pages about how to write a plugin hold examples of how to extend core classes, the textile parser is provided by a third-party library though, so I don't know much about its inner workings, sorry.

RE: Change macro syntax? - Added by FLX _ almost 14 years ago

Felix Schäfer wrote:

The wiki pages about how to write a plugin hold examples of how to extend core classes, the textile parser is provided by a third-party library though, so I don't know much about its inner workings, sorry.

That makes two of us :) I'm currently pondering with the idea of doing this via a straight regular expression replace. The regular expression part itself is easy, I'm more interested in how to retrieve/iterate the wiki content and return it after replacing. Any idea?

Thanks Felix,

Dennis

RE: Change macro syntax? - Added by FLX _ almost 14 years ago

Sorry for bumping this post, but I'd really like to make progress on this :)

    (1-7/7)