Macros?
Anton J Aylward
aja at si.on.ca
Sat May 6 20:49:36 EDT 2006
Either I don't understand your response or you didn't understand my
question. Certainly I can't see how your answer relates to the question I
thought I was asking.
Let me try again.
If I'm user Ruby's RDoc (or Perls TT, but different syntax)
I can write a _template_ such as:
You are <%= session.username %>
Logged in at <%= session.logintime %>
Your browser is <%= cgi.['HTTP_USER_AGENT'] %>
You are accessing from <%= cgi.['REMOTE_ADDR'] . cgi.['REMOTE_PORT'] %>
The time is now <%= (time.now +
session.user.timezone).strftime("%H:%M:%S") %>
BUT !!
That is a template.
I want to be able to put the macros in the data of a blog or wiki so that
when the template reads..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html><head>
.....
</head><body >
......
<div id='content'>
<%= render(page.body) %>
</div>
......
</body></html>
any of the macros that the user has inserted into the blog/wiki page will
get expanded. See my example of the stuff between '%%' in the original
message.
Which means that macro expansion has to be done in the 'render'.
Now it may happen that one of the macros invokes a function in the
blog/wiki (perhaps a plugin) that, rather than generate HTML, generates
markup (down/cloth/whatever) code.
I can see a way to do this with the render function being a two-step
1. Expand macros
2. process the result using Markdown
That is fine if the macros are simple and only do things like text
insertion. If they are more comprehensive then they may need to do
additional logic.
Consider a %%TOC%% or %%TOC{params..}%% macro. that builds a nested list of
markup references to the actual heading.
Take a look at
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/134005
and tell me what YOU think is wrong with it.
I can think of a few things.
1. It doesn't deal with <code> and other 'verbatim' sections
correctly
2. It doesn't deal with the situations where HTML headings are in the
body.
3. It doesn't deal with situations where other macros might generate
headings
Consider a full text search in a wiki page:
%%FULLTEXTSEARCH{
searchtext="[jJ]ust\w+[oO]ne\w+[tT]ing"
regex="yes"
fmt="* [result.spacedout](result.url)"
}%%
Oh, and make that able to do nested searches as well
OK, now consider a case where the parameter to a macro has to be rendered
first.
Realistically, I can only see macros working with something a bit more ...
controlled? What spring to mind is the render-chain mechanism used in the
perl-based wiki "CGI::Kwiki". The plugins that do 'macro' work and the
rest of the basic markup rendering are in the form of an ordered (read
prioritized) list. Of course the TOC will be near the end of the chain.
(This strikes me as a nice idea since conditionally included macros that
need javascript support can flag that the javascrip needs to be loaded,
rather than have a fixed header that includes all the javascrip that could
possibly be required!)
So how to use Markdown (or textile or redcloth or whatever) in this
context? Possibly repeated calls to Markdown with different restrictions.
But that seems a hell of an overhead.
I don't know if this better expresses thoughts and examples better.
A. Pagaltzis wrote:
> * Anton J Aylward <aja at si.on.ca> [2006-05-02 19:35]:
>
>>Is there any way to do macros in Markdown? Or do you have any
>>other suggestions?
>
> You can hack this on top of Markdown as it is, as long as you
> don’t need to nest macros inside links. Then you can write this:
>
>> You are %%USERNAME%%
>> Logged in at %%LOGINTIME%%
>>
>> Your browser is %%HTTP{"User-Agent"}%%
>> You are accessing from %%REMOTE_ADDR%%:%%REMOTE_PORT%%
>>
>> The time is now %%TIME(timezone=%%USER{%%TZ%%}%%, fmt="HH:MM:SS")%%
>
>
> like this:
>
> You are [USERNAME](macro:)
> Logged in at [LOGINTIME](macro:)
>
> Your browser is [HTTP{"User-Agent"}](macro:)
> You are accessing from [REMOTE_ADDR](macro:):[REMOTE_PORT](macro:)
>
> The time is now [TIME(timezone=USER{TZ},fmt="HH:MM:SS")](macro:)
>
> Markdown makes this out of it:
>
> <p>You are <a href="macro:">USERNAME</a>
> Logged in at <a href="macro:">LOGINTIME</a></p>
>
> <p>Your browser is <a href="macro:">HTTP{“User-Agent”}</a>
> You are accessing from <a href="macro:">REMOTE<em>ADDR</a>:<a href="macro:">REMOTE</em>PORT</a></p>
>
> <p>The time is now <a href="macro:">TIME(timezone=USER{TZ},fmt=”HH:MM:SS”)</a></p>
>
> Then you can you go in there and replace `<a>` tags with a `href`
> of `macro:` by the result of evaluating their textual content.
>
> Hmm, you’d have to be careful about your underscores and
> asterisks; not to mention there’s a bug there in Markdown…
>
> Regards,
More information about the Markdown-Discuss
mailing list