how to compose URLs?

41 views
Skip to first unread message

Rich Morin

unread,
May 15, 2017, 2:05:30 AM5/15/17
to kramdown-users
Let's say that I want to create a link to a Wikipedia article.
I can do this using either a regular or a reference link:


...
[Markdown][_wp_md1]

However, if I'm linking to a lot of Wikipedia articles, I'd like to reduce the clutter even further.
Problem is, I can't find a way to compose URLs from (say) abbreviations.
For example, this doesn't work:

[_wp_md2]: _wp/Markdown
...
[Markdown][_wp_md2]

Am I missing something?

-r

Thomas Leitner

unread,
May 16, 2017, 5:11:13 PM5/16/17
to kramdow...@googlegroups.com
Hi Rich,

On 2017-05-14 23:05 -0700 Rich Morin wrote:
> However, if I'm linking to a *lot* of Wikipedia articles, I'd like to
> reduce the clutter even further.
> Problem is, I can't find a way to compose URLs from (say)
> abbreviations. For example, this doesn't work:
>
> *[_wp]: https://en.wikipedia.org/wiki
> [_wp_md2]: _wp/Markdown
> ...
> [Markdown][_wp_md2]
>
> Am I missing something?

No, you are not missing something. It is not the job of kramdown to do
the job of a pre-processor or template engine. You may want to look at
ERB or something similar to do what you want.

Cheers,
Thomas

Rich Morin

unread,
May 16, 2017, 5:28:25 PM5/16/17
to kramdown-users
Although ERB is certainly able to make these sorts of substitutions,
it can also do far more.  Indeed, it can run any code that some miscreant
might decide to put in a document.  So, it's a bit too powerful for this task.

Given that kramdown already supports abbreviations, would there be any
harm in allowing them to be used in the URL section of a link?

Thomas Leitner

unread,
May 17, 2017, 11:55:21 AM5/17/17
to kramdow...@googlegroups.com
On 2017-05-16 14:28 -0700 Rich Morin wrote:
> Although ERB is certainly able to make these sorts of substitutions,
> it can also do far more. Indeed, it can run any code that some
> miscreant might decide to put in a document. So, it's a bit *too
> *powerful for this task.

Yes, as usual and with all technologies you have to make certain that
nothing bad happens. If you allow input for ERB to be provided by an
user, many things can go wrong. Therefore many websites use Liquid or
another templating engine. However, I don't think that Liquid, HAML,
Slim or any such templating engine would allow you to do what you want.

> Given that kramdown already supports abbreviations, would there be any
> harm in allowing them to be used in the URL section of a link?

Yes, the harming being that it just doesn't make sense, in itself and
for kramdown. Again, this is not something that kramdown was built for,
you want a pre-processor for that. And if you don't like ERB, then just
build your own pre-processor that does *just* what you want. This could
easily be done with Regexps in a few lines of code and nobody else's
converted documents would suddenly and subtly change.

Cheers,
Thomas

David Doolin

unread,
May 18, 2017, 3:44:12 AM5/18/17
to kramdown-users

Hi Rich,

I used M4 a few years ago for preprocessing kramdown.
It worked well for me.

-dave d
Reply all
Reply to author
Forward
0 new messages