From: Waylan L. <wa...@gm...> - 2013-11-02 01:16:26
|
Ian, That is a very ineficient way of doing it. First the entire parser has to be built, then the whole thing gets torn back down. Instead I would suggest subclassing the markdown.Markdown class and overriding the 'build_parser' method [1]. That method simply calls a function imported from each part of the parser. Each function returns an OrderedDict. Your reimplemented method should just build the OrderedDicts that you want. That way the default functions never get called and you only build the parts you need. In fact, I broke that part out into a separate method for this very purpose. I realize that you won't be able to use an extension for this then (you'll be using your subclass instead), but I think the difference in performance will be worthwhile. Especially if you are using a new instance of the class each time you run the parser. If you would like to continue on your present course anyway, look at those functions called by the build_parser method. You'll need to undo everything they do, so it's a good place to start. Hope that helps. Waylan [1]: https://github.com/waylan/Python-Markdown/blob/master/markdown/__init__.py#L141 On Friday, November 1, 2013, Ian G. Jeffries wrote: > Hey folks, > > I want to disable all of markdown by default and only enable certain > features, whitelist style. Here's what I've got so far (trying to enable > links only): > > > class MyMarkdownExtension(markdown.**Extension): > def extendMarkdown(self, md, md_globals): > for i in md.inlinePatterns.keys(): > if i != 'link': > del md.inlinePatterns[i] > > The next step is to do the work to disable the other parts of > python-markdown besides inlinePatters, but before I do that I wanted to ask > if I'm on the right track, or if there's a better way to do this. > > Thanks! > > Ian > -- ---- \X/ /-\ `/ |_ /-\ |\| Waylan Limberg |