Add the Creole Reader plugin

This commit is contained in:
Julien Enselme
2014-04-21 23:57:04 +02:00
parent c96846c201
commit 046eaadd61
3 changed files with 88 additions and 0 deletions

31
creole_reader/Readme.md Normal file
View File

@@ -0,0 +1,31 @@
# Creole Reader
This plugins allows you to write your posts using the wikicreole syntax. Give to
these files the creole extension. The medata are between <<header>> <</header>>
tags.
## Syntax
Use ** for strong, // for emphasis, one = for 1st level titles.
For the complete syntax, look at: http://www.wikicreole.org/
## Basic example
```
<<header>>
title: Créole
tags: creole, python, pelican_open
date: 2013-12-12
<</header>>
= Title 1
== Title 2
Some nice texte with **strong** and //emphasis//.
* A nice list
** With subelements
* Python
# An ordered list
# A second item
```

View File

@@ -0,0 +1 @@
from .creole_reader import *

View File

@@ -0,0 +1,56 @@
#-*- conding: utf-8 -*-
'''
Creole Reader
-------------
This plugins allows you to write your posts using the wikicreole syntax. Give to
these files the creole extension.
For the syntax, look at: http://www.wikicreole.org/
'''
from pelican import readers
from pelican import signals
from pelican import settings
from pelican.utils import pelican_open
try:
from creole import creole2html
creole = True
except ImportError:
creole = False
class CreoleReader(readers.BaseReader):
enabled = creole
file_extensions = ['creole']
def __init__(self, settings):
super(CreoleReader, self).__init__(settings)
def _parse_header_macro(self, text):
for line in text.split('\n'):
name, value = line.split(':')
name, value = name.strip(), value.strip()
if name == 'title':
self._metadata[name] = value
else:
self._metadata[name] = self.process_metadata(name, value)
return u''
# You need to have a read method, which takes a filename and returns
# some content and the associated metadata.
def read(self, source_path):
"""Parse content and metadata of creole files"""
self._metadata = {}
with pelican_open(source_path) as text:
content = creole2html(text, macros={'header': self._parse_header_macro})
return content, self._metadata
def add_reader(readers):
readers.reader_classes['creole'] = CreoleReader
def register():
signals.readers_init.connect(add_reader)