-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Produce AST prior to render #576
Conversation
This also splits 'text' into 'text', 'elements', and 'element' to hopefully better communicate structure
So far this aims to allow the entire AST to be generated prior to its rendering by separating handler delegation from the structure – in the integrated AST-handler model, the AST is generated in layers and then rendered before generating the next later (i.e. generate, render, recurse via handler, ...). Previously handlers would be required to return HTML, and would be inserted directly within an element. In order to successfully decouple this process and obtain a meaningful AST end result, handlers therefore need to be able to return AST data. The handler is now an array that contains information only relevant to handler delegation, in which the following keys should all be specified: IMO this also majorly disambiguates the handling process, in particular the use of the This has caused confusion in the past: e.g. #507 (comment)
Also see #523 It's definitely worth considering the implications of all these changes before deciding which version this might belong to should it ever be merged. This is a bit of an experiment, so there is potentially room for improvement with regard to breaking changes. |
Also note that (since the handler key is now mapping to a different type), we could in theory implement a compatibility layer using protected function handle(array $Element)
{
if (isset($Element['handler']))
{
if (!isset($Element['nonNestables']))
{
$Element['nonNestables'] = array();
}
if (is_string($Element['handler']))
{
$function = $Element['handler'];
$argument = $Element['text'];
$destination = 'rawHtml';
}
else
{
$function = $Element['handler']['function'];
$argument = $Element['handler']['argument'];
$destination = $Element['handler']['destination'];
}
$Element[$destination] = $this->{$function}($argument, $Element['nonNestables']);
}
unset($Element['handler']);
return $Element;
} Just to give an example of doing this with minimal BC breaks if desired. |
@aidantwoods Since you switch to an AST structure, is there any chance to register node visitors in order to extend functions or add new functionalities? I think something in the direction of #333 . |
@Sommerregen would you mind opening a separate issue to track this? I'll try take a look at this when I can, though probably separately to this PR :) |
cc: @PhrozenByte :) |
4402280
to
86c59e7
Compare
I'll definitly look into this, unfortunately my time is very limited right now. I hope I'll find some tme in the next couple of days 😃 |
No worries, just for when you get the chance :) |
b4925f0
to
6b259ed
Compare
f469e2e
to
af1dd59
Compare
af1dd59
to
40e7970
Compare
Even though it is now possible to generate the AST prior to rendering – |
I think I'd consider this pretty much done now, bar any improvements @PhrozenByte may suggest :) |
95548dd
to
e4d6c8f
Compare
I hope you finish this soon, I check this page every day ! |
Is there a hook I can register against when subclassing Parsedown to grab a hold of that AST? It would be great for things like generating tables of contents (ref: sbrl/Pepperminty-Wiki#155) |
An experimental go at refactoring the main to produce a complete AST prior to converting it into a HTML string. This could allow us/extensions to traverse the AST and perform structural transformations to parsing results.
Highly experimental, definitely not finished.
Closes #338
Closes #413