kzykhys / Ciconia

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

Chaining extensions #17

Closed jenssegers closed 10 years ago

jenssegers commented 10 years ago

I wrote a small extension that helps me integrate bootstrap's grid system. But when the extension gets executed, it does not gets parsed as a regular paragraph block anymore. Is there a way to to "chain" extensions so that the parsing does not stop on 1 extension?

For example, if I have something like this:

{.col-md-6} This is a paragraph

It will be wrapped with <div class=".col-md-6"> by my extension, but it will not be transformed to a paragraph.

kzykhys commented 10 years ago

@jenssegers Is it right?

Expected result is

<div class="col-md-6"><p>This is a paragraph</p></div>

but actual

<div class="col-md-6">This is a paragraph</div>
jenssegers commented 10 years ago

Yes.

jenssegers commented 10 years ago

I found a "solution". I'm now executing my extension on 'finalize'. It then splits the text into parts again, parses the parts en joins them again (like the paragraphExtension).

kzykhys commented 10 years ago

Block level HTML will be ignored.

  1. First, your extension turns {.col-md-6} This is a paragraph into <div class=".col-md-6"> This is a paragraph </div>
  2. Then, HtmlBlockExtension turns HTML block into hashes to skip parsing.

    {hash:xxxxxxxxxxxxxxxxxxxxxx}
  3. next "chained" extensions ignores hashes.
  4. HtmlBlockExtension revert hashes to HTML

How about this?

//separate text into `{.col-md-6}` and `This is a paragraph`

// Do regexp

$grid = '{.col-md-6}';
$content = new Text('\n\nThis is a paragraph\n\n');

// call block level parser manually
$this->getEmitter()->emit('block', [$content]);

// combine them
return '<div>' . $content . '</div>';
kzykhys commented 10 years ago

Oh, it's too late :cry: