Skip to content
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

Ability for extensions to define an AST processor #207

Closed
colinodell opened this issue Nov 19, 2015 · 5 comments
Closed

Ability for extensions to define an AST processor #207

colinodell opened this issue Nov 19, 2015 · 5 comments
Labels
enhancement New functionality or behavior
Milestone

Comments

@colinodell
Copy link
Member

The process of converting Markdown to HTML is basically two steps:

  1. Parse the Markdown into an AST
  2. Render the AST as HTML

Users can manually add a third step in the middle to modify the AST before it is rendered. However, it's currently impossible to insert an AST processor via the extension functionality.

I'd therefore like to add support for this within the extensions.

Now, we do have something called inline processors which are executed at the very end of that first step. It's geared towards processing inline AST elements, but perhaps we can make this more generalized?

@colinodell colinodell added enhancement New functionality or behavior feedback wanted We need your input! labels Nov 19, 2015
@hason
Copy link
Contributor

hason commented Nov 23, 2015

I proposed a similar functionality in #106.

@colinodell
Copy link
Member Author

Yeah I'd like to do something similar to #106, where multiple "visitors" can be defined, and they modify the AST in between the parsing and rendering steps. The main difference is that each "visitor" will be passed the document root Node - they can work directly off that, or use the NodeWalker to iterate through the different nodes. (This wouldn't use the "visitor" pattern, so we'd need to call them something else.)

@colinodell
Copy link
Member Author

For clarification, I'd like the implementation to look something like this:

foreach ($this->environment->getASTProcessors() as $processor) {
    $processor->process($documentRoot);
}

Very similar to how inline processors work, except each "AST processor" (or "AST filter", if you prefer that name) operates on the root-level Document node. Each processor/filter can decide how it wants to manipulate the AST - maybe it'll use a NodeWalker, but it doesn't necessarily need to.

@colinodell colinodell added the up-for-grabs Please feel free to take this one! label Nov 29, 2015
@colinodell
Copy link
Member Author

And to further clarify: I'd like to see if we can remove inline processors and have them use this new approach instead.

@colinodell colinodell added this to the 0.13.0 milestone Nov 29, 2015
@colinodell colinodell removed feedback wanted We need your input! up-for-grabs Please feel free to take this one! labels Jan 12, 2016
@colinodell
Copy link
Member Author

(Removed up-for-grabs tag since @marijnvdwerf is almost done implementing this via #210)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New functionality or behavior
Projects
None yet
Development

No branches or pull requests

2 participants