kzykhys / Ciconia

A New Markdown parser for PHP5.4
http://ciconia.kzykhys.com/
MIT License
355 stars 31 forks source link

Hook to process links #12

Closed evert closed 10 years ago

evert commented 10 years ago

Hi!

I'm working on a static site generator with Ciconia.

I would like to automatically be able to process all the links in the markdown source, and prepend the link with a base url (if they are relative).

Ideally, I would also be able to automatically add .md to the resulting like.

To do this effectively, it would be awesome if it were somehow possible to add a callback that allows me to process and rewrite links... For example something like this:

$ciconia->setLinkHandler(function($in) {

   return $in . '.md';

});

But I would also settle with a simple baseUrl and let Ciconia do the heavy lifting :)

kzykhys commented 10 years ago

Just pushed v0.1.5. Please see this gist. This example shows how to use RendererInterface to control urls.


I'm planning to extend event system like this:

$ciconia->on('event_name', function () {});

For example

// find "@username" and turn it into url
$ciconia->addExtension(new UsernameMentionExtension());

// called from extension
$ciconia->on('username', function ($username) use ($ciconia) {
    // fetch user's url from twitter api (or github)
   $user = [];
   return $user['url'];
});
$ciconia->render('****');

i'm looking forward to your site generator, because I'm just looking for a jekyll alternative written in PHP!

evert commented 10 years ago

Cool :) consider using https://github.com/fruux/sabre-event (my project) or https://github.com/igorw/evenement ;)

kzykhys commented 10 years ago

Great projects :) Looks like more powerful than ciconia's event classes.

I'm going to create a new ticket for events. so closing it.