Tuesday, 15 June 2010

python - Where should markdown parsing code live in a Django app? -



python - Where should markdown parsing code live in a Django app? -

i using wmd editor in django admin. have written simple parser (regex mostly) can grab specific tags in markdown , insert html accordingly. problem need access django object itself.

currently i'm overriding model.save() , calling model.process_markdown()

def process_markdown(self): p = re.compile("\[\[\s*(?p<tag>image):(?p<id>[\d,]+)\s*\]\]") processed = p.sub(partial(render_markdown, self), self.body_markdown) homecoming markdown.markdown(processed)

the result saved model.rendered field on model. if notice have render_markdown function beingness called. thats stored in file called util.py in app , real work.

everything working seems there should improve way. know can tie markdown custom tags , cleaner have beable access django object , reference related inline objects. far can tell there not way me this.

is there improve way organize this?

beware markdown allows html tunneled through. if this, want markdown(html, safe_mode='escape') if you're allowing untrusted sources insert .body_markdown, need sanitize input via bleach: http://pypi.python.org/pypi/bleach

python django markdown wmd-editor

No comments:

Post a Comment