mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #306 from mbowcock/master
Add output markup option to importer doc and multiple file extensions to file reader
This commit is contained in:
commit
0fe1453c50
6 changed files with 52 additions and 5 deletions
|
|
@ -39,7 +39,7 @@ Usage
|
|||
"""""
|
||||
|
||||
| pelican-import [-h] [--wpfile] [--dotclear] [--feed] [-o OUTPUT]
|
||||
| [--dir-cat]
|
||||
| [-m MARKUP][--dir-cat]
|
||||
| input
|
||||
|
||||
Optional arguments
|
||||
|
|
@ -51,6 +51,7 @@ Optional arguments
|
|||
--feed Feed to parse
|
||||
-o OUTPUT, --output OUTPUT
|
||||
Output path
|
||||
-m MARKUP Output markup
|
||||
--dir-cat Put files in directories with categories name
|
||||
|
||||
Examples
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ def render_node_to_html(document, node):
|
|||
|
||||
class RstReader(Reader):
|
||||
enabled = bool(docutils)
|
||||
extension = "rst"
|
||||
file_extensions = ['rst']
|
||||
|
||||
def _parse_metadata(self, document):
|
||||
"""Return the dict containing document metadata"""
|
||||
|
|
@ -111,7 +111,7 @@ class RstReader(Reader):
|
|||
|
||||
class MarkdownReader(Reader):
|
||||
enabled = bool(Markdown)
|
||||
extension = "md"
|
||||
file_extensions = ['md', 'markdown', 'mkd']
|
||||
extensions = ['codehilite', 'extra']
|
||||
|
||||
def read(self, filename):
|
||||
|
|
@ -128,7 +128,7 @@ class MarkdownReader(Reader):
|
|||
|
||||
|
||||
class HtmlReader(Reader):
|
||||
extension = "html"
|
||||
file_extensions = ['html', 'htm']
|
||||
_re = re.compile('\<\!\-\-\#\s?[A-z0-9_-]*\s?\:s?[A-z0-9\s_-]*\s?\-\-\>')
|
||||
|
||||
def read(self, filename):
|
||||
|
|
@ -144,7 +144,11 @@ class HtmlReader(Reader):
|
|||
return content, metadata
|
||||
|
||||
|
||||
_EXTENSIONS = dict((cls.extension, cls) for cls in Reader.__subclasses__())
|
||||
_EXTENSIONS = {}
|
||||
|
||||
for cls in Reader.__subclasses__():
|
||||
for ext in cls.file_extensions:
|
||||
_EXTENSIONS[ext] = cls
|
||||
|
||||
|
||||
def read_file(filename, fmt=None, settings=None):
|
||||
|
|
|
|||
BIN
pelican/themes/notmyidea/static/images/icons/facebook.png
Normal file
BIN
pelican/themes/notmyidea/static/images/icons/facebook.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 300 B |
10
tests/content/article_with_md_extension.md
Normal file
10
tests/content/article_with_md_extension.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
title: Test md File
|
||||
category: test
|
||||
|
||||
Test Markdown File Header
|
||||
=========================
|
||||
|
||||
Used for pelican test
|
||||
---------------------
|
||||
|
||||
The quick brown fox jumped over the lazy dog's back.
|
||||
10
tests/content/article_with_mkd_extension.mkd
Normal file
10
tests/content/article_with_mkd_extension.mkd
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
title: Test mkd File
|
||||
category: test
|
||||
|
||||
Test Markdown File Header
|
||||
=========================
|
||||
|
||||
Used for pelican test
|
||||
---------------------
|
||||
|
||||
This is another markdown test file. Uses the mkd extension.
|
||||
|
|
@ -61,3 +61,25 @@ class RstReaderTest(unittest.TestCase):
|
|||
self.assertEqual(content, expected)
|
||||
except ImportError:
|
||||
return unittest.skip('need the typogrify distribution')
|
||||
|
||||
class MdReaderTest(unittest.TestCase):
|
||||
|
||||
def test_article_with_md_extention(self):
|
||||
# test to ensure the md extension is being processed by the correct reader
|
||||
reader = readers.MarkdownReader({})
|
||||
content, metadata = reader.read(_filename('article_with_md_extension.md'))
|
||||
expected = "<h1>Test Markdown File Header</h1>\n"\
|
||||
"<h2>Used for pelican test</h2>\n"\
|
||||
"<p>The quick brown fox jumped over the lazy dog's back.</p>"
|
||||
|
||||
self.assertEqual(content, expected)
|
||||
|
||||
def test_article_with_mkd_extension(self):
|
||||
# test to ensure the mkd extension is being processed by the correct reader
|
||||
reader = readers.MarkdownReader({})
|
||||
content, metadata = reader.read(_filename('article_with_mkd_extension.mkd'))
|
||||
expected = "<h1>Test Markdown File Header</h1>\n"\
|
||||
"<h2>Used for pelican test</h2>\n"\
|
||||
"<p>This is another markdown test file. Uses the mkd extension.</p>"
|
||||
|
||||
self.assertEqual(content, expected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue