This commit is contained in:
Jotham Apaloo 2015-03-24 16:58:59 +00:00
commit a67ee52c55
4 changed files with 176 additions and 2 deletions

View file

@ -1,3 +1,3 @@
include *.rst
recursive-include pelican *.html *.css *png *.in *.rst *.md *.mkd *.xml *.py
recursive-include pelican *.html *.css *png *.in *.rst *.md *.mkd *.xml *.py *.markdown
include LICENSE THANKS docs/changelog.rst

View file

@ -0,0 +1,11 @@
$if(title)$Title: $title$$endif$
$for(author)$Author: $author$$endfor$
$if(date)$Date: $date$$endif$
$if(category)$Category: $category$$endif$
$if(summary)$Summary: $summary$$endif$
$if(slug)$Slug: $slug$$endif$
$for(tags)$Tags: $tags$$endfor$
$if(modified)$Modified: $modified$$endif$
$if(toc)$ $toc$$endif$
$body$
$for(include-after)$$include-after$$endfor$

View file

@ -4,6 +4,7 @@ from __future__ import unicode_literals, print_function
import logging
import os
import re
import pkg_resources
import docutils
import docutils.core
@ -21,6 +22,10 @@ try:
from html import escape
except ImportError:
from cgi import escape
try:
import pypandoc
except ImportError:
pypandoc = False # NOQA
from six.moves.html_parser import HTMLParser
from pelican import signals
@ -86,7 +91,7 @@ class _FieldBodyTranslator(HTMLTranslator):
def depart_field_body(self, node):
pass
def render_node_to_html(document, node):
visitor = _FieldBodyTranslator(document)
@ -197,6 +202,10 @@ class MarkdownReader(BaseReader):
enabled = bool(Markdown)
file_extensions = ['md', 'markdown', 'mkd', 'mdown']
enable_pypandoc = bool(pypandoc)
if enable_pypandoc is True:
file_extensions.append('org')
logger.info('Using pandoc to convert org to markdown')
def __init__(self, *args, **kwargs):
super(MarkdownReader, self).__init__(*args, **kwargs)
@ -239,6 +248,17 @@ class MarkdownReader(BaseReader):
self._source_path = source_path
self._md = Markdown(extensions=self.extensions)
with pelican_open(source_path) as text:
if self._source_path[-4:] == '.org' and \
self.enable_pypandoc is True:
pandoc_data_dir = '='.join(['--data-dir',
pkg_resources.resource_filename(
'pelican', 'pandoc_templates')])
logger.info('Using %s as pandoc_data_dir',
pandoc_data_dir)
text = pypandoc.convert(text, 'markdown', \
format='org',\
extra_args=['--template=md_org_template.markdown',
pandoc_data_dir])
content = self._md.convert(text)
metadata = self._parse_metadata(self._md.Meta)

View file

@ -0,0 +1,143 @@
#+Title: test org in md reader
#+Date: 2014-01-26
#+Author: Joth
#+Category: pelican
#+Tags: pelican readers, pypandoc
#+Slug: test-org-md-reader
#+Summary: Testing org reader
#+OPTIONS: H:2
#+OPTIONS: toc:2
#+TOC: headlines 2
* Org Metadata
The following metadata are exporting properly
#+begin_src
#+Title: test org in md reader
#+Date: 2014-01-26
#+Author: Joth
#+Category: pelican
#+end_src
These metadata are not exporting properly. It may be in the
pandoc template. It may be in the pandoc convert call.
#+begin_src
#+Tags: pelican readers, pypandoc
#+Slug: test-org-md-reader
#+Summary: Testing org reader
#+OPTIONS: toc:2
#+TOC: headlines 2
#+end_src
* Markup
Quotes
#+BEGIN_QUOTE
Everything should be made as simple as possible,
but not any simpler -- Albert Einstein
#+END_QUOTE
are included with
#+begin_src
#+BEGIN_QUOTE
...
#+END_QUOTE
#+end_src
Centred text and verse are not working in markdown export.
#+begin_src
#+BEGIN_CENTER
...
#+END_CENTER
#+end_src
* Fonts
*bold* =*bold*=
/italic/ =/italic/=
_underlined_ =_underlined_=
=verbatim= ~=verbatim=~
~code~ =~code~=
+strike-through+ =+strike-through+=
* Code
#+begin_src python :noeval
class BaseReader(object):
"""Base class to read files.
This class is used to process static files, and it can be inherited for
other types of file. A Reader class must have the following attributes:
- enabled: (boolean) tell if the Reader class is enabled. It
generally depends on the import of some dependency.
- file_extensions: a list of file extensions that the Reader will process.
- extensions: a list of extensions to use in the reader (typical use is
Markdown).
"""
enabled = True
file_extensions = ['static']
extensions = None
def __init__(self, settings):
self.settings = settings
def process_metadata(self, name, value):
if name in METADATA_PROCESSORS:
return METADATA_PROCESSORS[name](value, self.settings)
return value
def read(self, source_path):
"No-op parser"
content = None
metadata = {}
return content, metadata
#+end_src
* Tables
Not working nicely. They work with pandoc to rst.
| header 1 | header 2 |
|----------+----------|
| and | with |
| a | two |
| table | columns |
* Misc
Five or more dashes make a line
------
# lines with whitespace infront of '# ' will be treated as comments
#+begin_src sh
# lines with whitespace infront of '# ' will be treated as comments
#+end_src
* Alternatives and TODOs
- implement as plugin?
- org is amazin markup language, i like it native...
- do the org text to html with pandoc instead of markdown
- use Rst/html classes
- dedicated org class
- specify in SETTINGS which reader subclass to use for org files
- fix tables
- images example
- tests