added actual code
This commit is contained in:
parent
ae7d07898e
commit
dc50988b4e
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .pandoc_reader import *
|
42
pandoc_reader.py
Normal file
42
pandoc_reader.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from pelican import signals
|
||||||
|
from pelican.readers import BaseReader
|
||||||
|
import pypandoc
|
||||||
|
|
||||||
|
class NewReader(BaseReader):
|
||||||
|
enabled = True
|
||||||
|
file_extensions = ['md', 'markdown', 'mkd', 'mdown']
|
||||||
|
|
||||||
|
def read(self, filename):
|
||||||
|
with open(filename) as file:
|
||||||
|
metadata_items = []
|
||||||
|
in_content = False
|
||||||
|
MD = ''
|
||||||
|
for line in file.readlines():
|
||||||
|
splitted = line.split(':', 1)
|
||||||
|
if len(splitted) == 2 and not in_content:
|
||||||
|
metadata_items.append(splitted)
|
||||||
|
else:
|
||||||
|
in_content = True
|
||||||
|
MD += line
|
||||||
|
|
||||||
|
metadata = {}
|
||||||
|
for item in metadata_items:
|
||||||
|
name, value = item
|
||||||
|
name = name.lower()
|
||||||
|
value = value.strip()
|
||||||
|
meta = self.process_metadata(name, value)
|
||||||
|
metadata[name] = meta
|
||||||
|
|
||||||
|
if 'PANDOC_ARGS' in self.settings:
|
||||||
|
output = pypandoc.convert(MD, 'html5', format='md', extra_args=self.settings['PANDOC_ARGS'])
|
||||||
|
else:
|
||||||
|
output = pypandoc.convert(MD, 'html5', format='md')
|
||||||
|
|
||||||
|
return output, metadata
|
||||||
|
|
||||||
|
def add_reader(readers):
|
||||||
|
readers.reader_classes['md'] = NewReader
|
||||||
|
|
||||||
|
def register():
|
||||||
|
signals.readers_init.connect(add_reader)
|
Loading…
Reference in New Issue
Block a user