February 26, 2009 will

More on extended-markup

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.

Use Markdown for formatting
*Italic* **Bold** `inline code` Links to [Google](http://www.google.com) > This is a quote > ```python import this ```
your comment will be previewed here