mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge branch 'dynamic_nosetupfools' of https://github.com/JNRowe/pelican
This commit is contained in:
commit
0f45b5ab1b
3 changed files with 38 additions and 15 deletions
|
|
@ -23,13 +23,14 @@ At this time, pelican is dependent of the following python packages:
|
||||||
|
|
||||||
* feedgenerator, to generate the ATOM feeds.
|
* feedgenerator, to generate the ATOM feeds.
|
||||||
* jinja2, for templating support.
|
* jinja2, for templating support.
|
||||||
* pygments, to have syntactic colorization
|
|
||||||
* docutils and Markdown
|
|
||||||
|
|
||||||
If you're not using python 2.7, you will also need `argparse`.
|
If you're not using python 2.7, you will also need `argparse`.
|
||||||
|
|
||||||
All those dependencies will be processed automatically if you install pelican
|
Optionally:
|
||||||
using setuptools/distribute or pip.
|
|
||||||
|
* docutils, for reST support
|
||||||
|
* pygments, to have syntactic colorization with resT input
|
||||||
|
* Markdown, for Markdown as an input format
|
||||||
|
|
||||||
Writing articles using pelican
|
Writing articles using pelican
|
||||||
==============================
|
==============================
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@ method, that is returning an HTML content and some metadata.
|
||||||
|
|
||||||
Take a look to the Markdown reader::
|
Take a look to the Markdown reader::
|
||||||
|
|
||||||
class MarkdownReader(object):
|
class MarkdownReader(Reader):
|
||||||
|
enabled = bool(Markdown)
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""Parse content and metadata of markdown files"""
|
||||||
|
|
@ -59,6 +60,12 @@ Take a look to the Markdown reader::
|
||||||
|
|
||||||
Simple isn't it ?
|
Simple isn't it ?
|
||||||
|
|
||||||
|
If your new reader requires additional Python dependencies then you should wrap
|
||||||
|
their `imports` statements in `try...except`. Then inside the reader's class
|
||||||
|
set the `enabled` class attribute to mark import success or failure. This makes
|
||||||
|
it possible for users to continue using their favourite markup method without
|
||||||
|
needing to install modules for all the additional formats they don't use.
|
||||||
|
|
||||||
How to implement a new generator ?
|
How to implement a new generator ?
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from docutils import core
|
try:
|
||||||
from markdown import Markdown
|
from docutils import core
|
||||||
|
|
||||||
|
# import the directives to have pygments support
|
||||||
|
import rstdirectives
|
||||||
|
except ImportError:
|
||||||
|
core = False
|
||||||
|
try:
|
||||||
|
from markdown import Markdown
|
||||||
|
except ImportError:
|
||||||
|
Markdown = False
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
# import the directives to have pygments support
|
|
||||||
import rstdirectives
|
|
||||||
|
|
||||||
from pelican.utils import get_date, open
|
from pelican.utils import get_date, open
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +23,12 @@ _METADATAS_PROCESSORS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class RstReader(object):
|
class Reader(object):
|
||||||
|
enabled = True
|
||||||
|
|
||||||
|
class RstReader(Reader):
|
||||||
|
enabled = bool(core)
|
||||||
|
extension = "rst"
|
||||||
|
|
||||||
def _parse_metadata(self, content):
|
def _parse_metadata(self, content):
|
||||||
"""Return the dict containing metadatas"""
|
"""Return the dict containing metadatas"""
|
||||||
|
|
@ -43,7 +54,9 @@ class RstReader(object):
|
||||||
metadatas['title'] = title
|
metadatas['title'] = title
|
||||||
return content, metadatas
|
return content, metadatas
|
||||||
|
|
||||||
class MarkdownReader(object):
|
class MarkdownReader(Reader):
|
||||||
|
enabled = bool(Markdown)
|
||||||
|
extension = "md"
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
"""Parse content and metadata of markdown files"""
|
"""Parse content and metadata of markdown files"""
|
||||||
|
|
@ -60,7 +73,8 @@ class MarkdownReader(object):
|
||||||
return content, metadatas
|
return content, metadatas
|
||||||
|
|
||||||
|
|
||||||
class HtmlReader(object):
|
class HtmlReader(Reader):
|
||||||
|
extension = "html"
|
||||||
_re = re.compile('\<\!\-\-\#\s?[A-z0-9_-]*\s?\:s?[A-z0-9\s_-]*\s?\-\-\>')
|
_re = re.compile('\<\!\-\-\#\s?[A-z0-9_-]*\s?\:s?[A-z0-9\s_-]*\s?\-\-\>')
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
|
|
@ -76,8 +90,7 @@ class HtmlReader(object):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_EXTENSIONS = {'rst': RstReader, 'md': MarkdownReader, 'html': HtmlReader} # supported formats
|
_EXTENSIONS = dict((cls.extension, cls) for cls in Reader.__subclasses__())
|
||||||
|
|
||||||
|
|
||||||
def read_file(filename, fmt=None):
|
def read_file(filename, fmt=None):
|
||||||
"""Return a reader object using the given format."""
|
"""Return a reader object using the given format."""
|
||||||
|
|
@ -86,4 +99,6 @@ def read_file(filename, fmt=None):
|
||||||
if fmt not in _EXTENSIONS.keys():
|
if fmt not in _EXTENSIONS.keys():
|
||||||
raise TypeError('Pelican does not know how to parse %s' % filename)
|
raise TypeError('Pelican does not know how to parse %s' % filename)
|
||||||
reader = _EXTENSIONS[fmt]()
|
reader = _EXTENSIONS[fmt]()
|
||||||
|
if not reader.enabled:
|
||||||
|
raise ValueError("Missing dependencies for %s" % fmt)
|
||||||
return reader.read(filename)
|
return reader.read(filename)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue