From: edA-qa mort-ora-y <ed...@di...> - 2014-01-05 15:51:52
|
Thank you. Since there fenced_code processor was actually small enough I took the easy approach: I copied the whole thing and just emitted my own required tags. Though I agree that a block processor would be the nicer approach. On 05/01/14 16:16, Waylan Limberg wrote: > I agree, your code should be working ... except that you are also > using the 'fence_code' extension. Unfortunately, the current > implementation of the fenced_code extension does not insert code > blocks into the tree, but uses the raw htmlStash to store the code > blocks. > > Try your source text with tradition markdown indented code blocks and > your code should work. If you also want to support fenced code blocks, > then I would suggest looking at the RawHtmlPostprocessor [1]. However, > you will need to manually check to make sure the raw blocks are code > blocks as it handles all raw html blocks - not just code. > > [1]: https://github.com/waylan/Python-Markdown/blob/master/markdown/postprocessors.py#L48 > > I do have plans to refactor the fenced_code extension to be a > Blockprocessor (rather than a Preprocessor), but haven't had the time. > Doing so would solve your problem and also allow fenced code blocks to > be nested in lists, blockquotes, etc. As always, patches are welcome. > ;-) > > ---- > \X/ /-\ `/ |_ /-\ |\| > Waylan Limberg > > > On Sun, Jan 5, 2014 at 1:18 AM, edA-qa mort-ora-y <ed...@di...> wrote: >> I'm trying to write an extension which translates code blocks into the >> Wordpress [sourcecode] form. I used codehilite as an example, but my >> code never finds any "pre" blocks. If I remove the 'pre' matching and >> print all blocks in the loop I never see a 'pre' in the list. Yet the >> final HTML generated does indeed have the pre/code blocks there. >> >> class WPSource(markdown.treeprocessors.Treeprocessor): >> def run(self,root): >> blocks = root.getiterator('pre') >> for block in blocks: >> print(block) >> if len(children) == 1 and children[0].tag == 'code': >> print( children[0].text ) >> >> class WPExtension(markdown.Extension): >> def __init__(self,configs): >> pass >> >> def extendMarkdown(self, md, md_globals): >> sourcer = WPSource(md) >> md.treeprocessors.add("wpsource", sourcer, "_end" ) >> md.registerExtension(self) >> >> md = markdown.Markdown( >> extensions = [ 'meta', 'fenced_code', WPExtension({}) ] >> ) >> >> >> -- >> edA-qa mort-ora-y >> Leaf Creator >> >> Leaf - the language we always wanted >> http://leaflang.org/ >> >> ------------------------------------------------------------------------------ >> Rapidly troubleshoot problems before they affect your business. Most IT >> organizations don't have a clear picture of how application performance >> affects their revenue. With AppDynamics, you get 100% visibility into your >> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! >> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk >> _______________________________________________ >> Python-markdown-discuss mailing list >> Pyt...@li... >> https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss > > -- edA-qa mort-ora-y Leaf Creator Leaf - the language we always wanted http://leaflang.org/ |