In my last post I introduced extended-markup, which is the light-weight markup system used to generate posts in Django-Techblog. I'll cover a few other things it can do in this post.

When the Post model is saved to the database, the extended markup is parsed in to a structure that is basically a dictionary containing a list of chunks, and associated variables. The order that the chunks appear in each section is the same as the order they appear in the markup, unless a chunk variable called priority is defined. This causes the chunks to be sorted in descending order of priority, chunks without a priority value are assigned a default of 100.

Here is an example of two chunks with a priority value assigned:

{..}
{..priority=50}
This appears at the end.

{..}
{..priority=100}
This appears at the top.

So why would you want to assign a priority to a chunk, when you already define the order they appear in the text? It becomes useful when combined with another feature of Django-Techblog – extended-markup can be derived from parent markup.

In this blog there is some markup associated with the blog itself, which specifies the content in the right hand column (and potentially other places). The markup in the post is combined with this to create the final page. By giving a chunk a priority that is greater than the default of 100, the chunk will display at the top of the section, rather than the bottom.

Alternatively the markup for a post could replace the content in a section entirely, by assigning a value to a chunk variable called replace. There is a shortcut for chunk variables that don't need a value assigned to them, {..replace!} has the same effect as {..replace=1}.

Here's an example of using replace in a chunk:

{..}
{..replace!}
This will blank out the right hand column and go at the top.
Me, as a South Park Character

This is me as a South Park character – it is uncannily accurate!

A useful chunk type, which you should see to the left, is siteimage. This inserts an image that was uploaded via Django admin. A number of parameters are used to specify the image to insert, its dimensions and at what side it is to be floated. Any text in the chunk is used for the image caption.

When the markup is saved, Django-Techblog creates a high-quality antialiased thumbnail with Python Image Library . This makes it easy to tweak the image dimensions if–like me–you are never satisfied with defaults.

Here is the markup used to display the South Park image:

{..siteimage}
{..name=spwill}
{..size=160}
{..float=left}
This is me as a South Park character -- it is uncannily accurate!

There are a few more features of extended-markup that I haven't covered here. I probably wont blog about them, but if anyone is interested, feel free to ask me.

This blog post was posted to It's All Geek to Me on Thursday February 26th, 2009 at 8:04PM
 

Leave a Comment

You can use bbcode in the comment: e.g. [b]This is bold[/b], [url]http://www.willmcgugan.com[/url], [code python]import this[/code]
Preview Posting...
Previewing comment, please wait a moment...
Will McGugan

My name is Will McGugan. I am an unabashed geek, an author, a hacker and a Python expert – amongst other things!

You are reading my tech blog. See the homepage for my other blogs.

Search for Posts
Possibly related posts
Tags
Popular Tags
 
Archives
2013
 
Recent Comments
Great! All other image slideshow with kenburn effect use my processor(i5-2400) in firefox(and only in ff) on 100%. But with ...
Would be great to get this on GitHub. I could see using it in multiple places and you should get ...
Would be great to get this on GitHub. I could see using it in multiple places and you should get ...
Classic Roy
- Oriol on ChessPy
Hi how much money is the book and does it say how u publish it
 
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan