link to somewhere, the web forms

作者:   發佈於: ,更新於:   #jifty #markdown #perl #socialtext #wiki #wikitext

Rails has this link_to methods with pretty good semantic:

link_to "Gugod's website", :url => "https://gugod.org/"

Pretty much just like speaking English. In Jifty, it has several different varints. One is "hyperlink" if you use Template::Declare:

hyperlink(
    label => "Gugod's website",
    url   => "https://gugod.org"
);

In plain HTML, that's

<a href="https://gugod.org/">Gugod's website</a>

In Socialtext wikitext, that's:

"Gugod's website"https://gugod.org

In Markdown, that's:

Gugod's website

They all make sense. The frst two are designed to be written inside application's templates, the last two are designed to be written as application content. HTML are somewhere in the middle. It can be written as part of your templates, or part of your application content.

Maintianing templates of the application are usually programmer's job. Sometimes templates becomes a managable content such that users have to maintain them too. Like blogger's template, or bricolage's tempate.

Subjectively I vote for Socialtext wikitext syntax if I am a heavy content provider. For several reasons:

Backward compatible punctuations. The double quotes natually emphasizes the link label to mean: "Something different in here".

Direct. Human readers immediately catches the first part, which is the link label. Can ignore the rest of text between < and > since those characters are not likely helpful without a proper reader. Comparing this:

You must visit "Gugod's website"<https://gugod.org> and donate him.

with this:

You must visit <a href="https://gugod.org/">Gugod's website</a> and donate him.

The second one makes me stop breathing for 1.74 seconds in the middle so I can read the whole sentence. (I voicelessly read text in my head, it's a bad habbit that I have been trying to fix for 20 years since I was awared of this problem.)

The same semantic looks ok in Markdown:

You must visit [Gugod's website](https://gugod.org) and donate him.

It looks even better in Markdown with another type of syntax:

You must visit [Gugod's website][1] and donate him.

[1]: https://gugod.org

Which makes the whole article looks like a research paper with whole bunch of citation links afterwards. It's either good or bad.

The Template::Declare way to do this is quite said:

outs_raw("You must visit ");
hyperlink(
    label => "Gugod's website",
    url   => "https://gugod.org"
);
outs_raw(" and donate him.");

I'm almost out of oxygen and can't get any high. This snippet is too heavy for what it does. A sprintf-like way for these inline-level elements can work better:

outs_raw + sprintf(
    "You must visit %s and donate him",
    hyperlink(....)
)

But this doesn't work like what you'd expect due to the design of Template::Declare, another "inconvienent truth."

I feel it much lighter to be able to use just "..."<...> to represent a simple hyperlink.

But that raises a very interesting issue for framework designers: Why should this optimized to let developer put more literal links in view code ? I would also vote against for over-optimizing these things that you don't really need.

Or I would just delegate it to other formatters for such purposes, say, having a "wikitext" helper in Template::Declare:

div {
  wikiext qq{
    You must visit "Gugod's website"<https://gugod.org> and donate him.
  }
};

Or a "markdown" helper:

div {
  markdown qq{
    You must visit [Gugod's website](https://gugod.org) and donate him.
  }
};

This reminds me of my previous work, Template-Provider-Markdown, which allows you use Markdown to replace HTML in your TT2 templates.

If I have to generate a tangent link then it's a totally different story. That's something no need to be optimized. (Maybe)

Socialtext wikitext syntax is very close to be a valid piece of Perl6:

"Gugod's website"<https://gugod.org>

"" forms a string value, and <> means getting a thing from a hash with the hash key barely given inside. So that means: getting the value associated with "https://gugod.org/" from the Hash represented by "Gugod's website". Syntax error.

But there might be a chance to make this work for Perl6, since the form

$obj.<>

is a method-like postcircumfixes, it might be able to be overloaded for Strings. In fact, if this is true, the original dot-less form might just work too. That would make perl6 the best langauge to design templating system for both appllication templates and application content -- just overload a bunch of Perl6 operators such that our content can be a form of valid subset Perl6.