Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format title text using Pelican?

I'm using Pelican with Markdown. I create blog posts as foo.md 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 Title: field (if I write *Light*, by Kelly Link it's interpreted literally. Do I have to change the theme in order to do this?

like image 840
Eli Rose Avatar asked Oct 18 '25 04:10

Eli Rose


2 Answers

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                   
            self._md.reset()                                                   
            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.

like image 125
cwallenpoole Avatar answered Oct 19 '25 18:10

cwallenpoole


Thanks, quite helpful! I did this, but now for some reason the <p></p> that Pelican wraps the formatted text in has an enormous margin. – Eli Rose Sep 8 '15 at 2:26

You can often avoid the <p></p> wrapping by amending the title variable in your theme's html pages to title|striptags. This solves several other problems (e.g. all-caps sections in titles) that Typogrify sometimes creates.

For example:

{% for p in PAGES %}
    <li{% if p == page %} class="selected"{% endif %}><a href="{{ SITEURL }}/{{ p.url }}">{{ p.title|striptags }}</a></li>
like image 23
Tofof Avatar answered Oct 19 '25 20:10

Tofof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!