From: Ben W. <da...@gm...> - 2007-06-13 11:58:12
|
On 6/12/07, Yuri Takhteyev <qar...@gm...> wrote: > This looks good. It is however, tied to the question of how the > processors work, so those two issues need to be discussed together. > This implementation assumes that everything is text-in-text-out. The assumption you cite is based on my implementation of that class. What I offer is the core premise, of casually linking processor order and heaping a final order. I realize the TITO is not how Markdown does things and anticipate that you would make the relevant changes. I'm familiar enough with how you wrote your implementation, but not enough to presume to offer a turnkey solution. I snipped out later comments where you tried to reconcile the difference. That is beyond my scope. :-) However, based on your later commentary, I've decided to re-tool what I offered so the resultant tool would be more universally applicable. > [...] > Another thing: Part of your code seems to implement a general > register-deregister-sort logic which would potentially be useful for > things other than markdown. Have you thought of wrapping it up into a > separate module? Actually, I have. After I posted the example to you, I noticed it would be preferable to abstract it out. However, my abstraction was still coupled to text manipulation. I believe I would remove the "parse" function. This way inside python-markdown one would simply > use: > > import treeregistry ## just making up a name for now > > r = treeregistry.Registry() > r.register('fulltext','>_begin') > r.register('split','>fulltext') > ... > r.register('[[', 'links', r'(\[\[\s*(.*?)\]\])(s?)', make_link) > load_extension(r) > processors = r.get_sorted() > > Then from here on we just use a list of pre-sorted processors. FWIW, I would suggest keeping with 'sorted' as the function name as it is similar to the Python function of the same name. You know what I mean, but to make sure I'm making my point, I'll explain. Using .sort(), the list is sorted in place with None returned. Using .sorted() returns a copy of the list, sorted. The original list remains unsorted. So, to a Python programmer, r.sorted() should be self-documenting without the 'get_' prefix. But, your general point is valid. More importantly, you can get rid of the regex reference altogether. The code bit below should be close to how Python Markdown could use it. link_processor = (r'\[\[(.*?)\]\]', make_link) r.register('[[','links',link_procssor) Then, the register is absolutely agnostic. Your local use would extract the ordered list of tuples. Perhaps I could have a local use that extracted an ordered list of objects. Oh, crap; this just solved a sort issue I gave up on last Fall! I'll re-tool the code to be agnostic and post it later today or tomorrow. -- Ben Wilson "Words are the only thing which will last forever" Churchill |