aa_macro syntax 
 aa_macro source 
 HTML source 
 HTML render 

4.65 - [postparse] Built-In

Mnemonic aid: postparse for POST (after) PARSE pretty-print Python source

See also:  [pythparse] 

This built-in allows you to generate a pretty-printed representation of Python source code. In the example, you'll see I wrapped a  <div>  with a black background around the  [postparse] , as the default pretty-printing colors were selected with a black background in mind:

[postparse content]

<div style="background: #000000; padding: 1em;">
def mygen(n):
for i in range(0,n):
print "hello!"

<div style="background: #000000; padding: 1em;"><span style="color: #00ff00"><span style="color: #ff00ff">def</span> mygen<span style="color:#ff8844;">(</span>n<span style="color:#ff8844;">)</span><span style="color:#00ffff;">:</span></span>
<span style="color: #00ff00"> <span style="color: #ff00ff">for</span> i <span style="color: #ff00ff">in</span> range<span style="color:#ff8844;">(</span>0<span style="color:#00ffff;">,</span>n<span style="color:#ff8844;">)</span><span style="color:#00ffff;">:</span></span>
<span style="color: #00ff00"> <span style="color: #ff00ff">print</span> </span><span style="color: #ffffff">"</span><span style="color: #ff0000">hello!</span><span style="color: #ffffff">"</span><span style="color: #00ff00"></span></div>
def mygen(n): for i in range(0,n): print "hello!"

You can use aa_macro code within the scope of Python source code fed to  [postparse]  at any parsing level, not just the top context; this can be very handy, but it comes with a bit of work, too: You have to change all the Python source occurances of [ and ] to  [lb]  and  [rb] , and all of the occurances of { and } to  [ls]  and  [rs] , or aa_macro will try to parse the Python as aa_macro, and the result of that won't be pretty. With that in mind, it is sometimes more practical to use  [pythparse] , store the result in a variable, and then use the variable in deeper aa_macro contexts.

You can control what the pretty printing does in terms of styling by setting the following variables (default values are shown):

CSS style wrap for Python keywords: import, while, etc.
'<span style="color: #ff00ff">'

CSS style wrap for single and double quotes
'<span style="color: #ffffff">'

CSS style wrap for Python code
'<span style="color: #00FF00">'

CSS style wrap for text inside quotes
'<span style="color: #ff0000">'

CSS style wrap for comment content
'<span style="color: #ffff00">'

CSS style wrap for {}, [], and ()
'<span style="color: #ff8844">'

CSS style wrap for symbols such as ==, +, < and so on
'<span style="color: #00ffff">'
Keyboard Navigation
, Previous Page . Next Page t TOC i Index

Valid HTML 4.01 Loose

This manual was generated with wtfm
wtfm uses aa_macro and SqLite
aa_macro uses python 2.7