From: Waylan L. <wa...@gm...> - 2013-09-08 03:39:37
|
My first approach might be to use a treeprocessor, step through all `li` tags, and check for the appropriate string at the beginning of the li's text. If it exists, modify the `li` element as appropriate. The CodeHilite extension uses a similar approach to act on all `pre` elements, as does the HeaderID extension on h1-6 elements, and the Attribute List extension on the entire tree. The great thing about this approach it that it doesn't modify/reimplement Markdown's existing parsing and eliminates the need to mirror any updates/bug fixes to the basic syntax parsing. In fact, CodeHilite used to be a reimplementation (replacing the codeblock processor) which didn't work as good. Once I moved it to a treeprocessor, maintance got much easier. Another great thing about treeprocessors is that because all inlinePatterns are called from one of the builtin treeprocessors, you can have yours run either before or after inlinePatterns - giving you much more power to do exactly what you need without the extra baggage (like doing extra work to account for inline stuff you don't need). As I see it, preprocessors are great for a quick and dirty hack. But for a reliable, consistent long term solution, treeprocessors are where the real power in the API is. Just make sure you are comfortable working with ElementTree. ---- \X/ /-\ `/ |_ /-\ |\| Waylan Limberg On Sat, Sep 7, 2013 at 11:20 AM, Frederik Dohr <fd...@gm...> wrote: > Hi all, > > As mentioned elsewhere, I've created a checklists extension: > https://github.com/FND/markdown-checklist > > Right now that's just a simple preprocessor converting unordered lists > of a special type: > > * [ ] foo > * [ ] bar > > <ul> > <li><input type="checkbox" disabled> foo</li> > <li><input type="checkbox" disabled checked> bar</li> > </ul> > > However, I now want to add a class to such lists[1] - which renders my > preprocessor unsuitable. > > Since I'd rather avoid reinventing the wheel, I'd be grateful if someone > could point me to existing examples for customizing elements like that > (not in terms of markup, but extension code). > > > Thanks, > > Fred > > > [1] due to https://github.com/FND/markdown-checklist/issues/1 > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk > _______________________________________________ > Python-markdown-discuss mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss |