Eli Rose Eli Rose - 1 year ago 106
Python Question

How do I format title text using Pelican?

I'm using Pelican with Markdown. I create blog posts as

files, which look like this:

Title: Light, by Kelly Link
Date: 2015-09-07 21:18

Blah blah ...

I would like a word in the title to be italicized, but I can't use markdown in the
field (if I write
*Light*, by Kelly Link
it's interpreted literally. Do I have to change the theme in order to do this?

Answer Source

So, the relevant section of code in Pelican is, I believe, the following from readers.py (starting c. line 183):

def _parse_metadata(self, meta):                                               
    """Return the dict containing document metadata"""                         
    formatted_fields = self.settings['FORMATTED_FIELDS']                       

    output = {}                                                                
    for name, value in meta.items():                                           
        name = name.lower()                                                    
        if name in formatted_fields:                                           
            # handle summary metadata as markdown                              
            # summary metadata is special case and join all list values        
            summary_values = "\n".join(value)                                  
            # reset the markdown instance to clear any state                   
            summary = self._md.convert(summary_values)                         
            output[name] = self.process_metadata(name, summary)   

In short, Pelican is looking to see if it is supposed to parse Markdown fields before writing them (title is part of the meta dict). Based on that, it looks like all you need to do is make sure that you have title in your FORMATTED_FIELDS setting.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download