Tutorial :Custom Markup in Django



Question:

Can anyone give me an idea or perhaps some references on how to create custom markups for django using textile or Markdown(or am I thinking wrong here)?

For example: I'd like to convert the following markups(the outer bracket mean they are grouped as one tag:
[
[Contacts]
* Contact #1
* Contact #2
* Contact #3
[Friend Requests]
* Jose
]

to have them converted to:

<div class="tabs">        <ul>           <li class="tab">Contacts</li>           <li>Contact #1</li>          (etc.. etc..)      </ul>  </div>    

or is regex more recommended for my needs?


Solution:1

The built in markup app uses a filter template tag to render textile, markdown and restructuredtext. If that is not what your looking for, another option is to use a 'markup' field. e.g.,

class TownHallUpdate(models.Model):      content = models.TextField()      content_html = models.TextField(editable=False)        def save(self, **kwargs):          self.content_html = textile.textile(sanitize_html(self.content))      super(TownHallUpdate, self).save(**kwargs)  

Example from James Tauber's (and Brian Rosner's) django patterns talk.


Solution:2

Django comes with a built-in contrib app that provides filters to display data using several different markup languages, including textile and markdown.

See the relevant docs for more info.


Solution:3

A quick google search resulted with this


Solution:4

Well it seems the best way is still use a regex and create my own filter.

here are some links that helped me out:
http://showmedo.com/videos/video?name=1100010&fromSeriesID=110
http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/

hope this helps someone who had the same problem as me!


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »