Customfilter Grammar Conver
from google.appengine.ext.webapp import template#導入Django template module
from django.utils.safestring import mark_safe
from py.parser import reList
from py.parser import mylist
 
'''
input : content
output : conversion from content
 
'''
#載入註冊自定義filter用的register
register = template.create_template_register()
#載入自定義的filter
template.register_template_library('py.customfilter.grammar_conver')
__re_source = reList.res
#設定filter名稱為context_conver
@register.filter(name='context_conver')
def context_conver(source):
    #設定臨時變數
    temp_context = source
    #核心:執行每個轉換
    for parse_re in __re_source:
        temp_context = parse_re.conver(temp_context)
    return mark_safe(temp_context)