From e4f7a2817cecba302285d8f141b2dd4dd34c5713 Mon Sep 17 00:00:00 2001 From: pR0Ps Date: Thu, 25 Dec 2014 00:07:12 -0500 Subject: [PATCH 1/6] Remove cruft from .gitignore --- .gitignore | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) diff --git a/.gitignore b/.gitignore index 51cbe85..43ae0e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,54 +1,2 @@ -# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -# Sphinx documentation -docs/_build/ - From 67e080a66352c54a7516594cc62a7f0389198a43 Mon Sep 17 00:00:00 2001 From: pR0Ps Date: Thu, 25 Dec 2014 00:08:52 -0500 Subject: [PATCH 2/6] Major refactor, bordering on rewrite - Rename the plugin (md_yaml -> md_metayaml) - Rework directory structure for easier integration into Pelican - Change markdown extension libary to a submodule - Remove ugly path hacks - Make the reader do less work (leverage the MarkdownReader class) --- .gitmodules | 3 + __init__.py | 1 + markdown_metayaml | 1 + md_metayaml.py | 29 +++++++++ md_yaml/__init__.py | 1 - md_yaml/md_yaml.py | 63 ------------------ md_yaml/mdx_meta_yaml/LICENSE.md | 30 --------- md_yaml/mdx_meta_yaml/__init__.py | 10 --- md_yaml/mdx_meta_yaml/extension.py | 100 ----------------------------- 9 files changed, 34 insertions(+), 204 deletions(-) create mode 100644 .gitmodules create mode 100644 __init__.py create mode 160000 markdown_metayaml create mode 100644 md_metayaml.py delete mode 100644 md_yaml/__init__.py delete mode 100644 md_yaml/md_yaml.py delete mode 100644 md_yaml/mdx_meta_yaml/LICENSE.md delete mode 100644 md_yaml/mdx_meta_yaml/__init__.py delete mode 100644 md_yaml/mdx_meta_yaml/extension.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..327aab8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "markdown_metayaml"] + path = markdown_metayaml + url = git@github.com:pR0Ps/markdown_metayaml.git diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..1d3a5d4 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .md_metayaml import * diff --git a/markdown_metayaml b/markdown_metayaml new file mode 160000 index 0000000..201a20e --- /dev/null +++ b/markdown_metayaml @@ -0,0 +1 @@ +Subproject commit 201a20e1c3cf6f89cb7d38fbb2a7da3f81923091 diff --git a/md_metayaml.py b/md_metayaml.py new file mode 100644 index 0000000..9586045 --- /dev/null +++ b/md_metayaml.py @@ -0,0 +1,29 @@ +from pelican import signals +from pelican.readers import MarkdownReader + +from .markdown_metayaml.meta_yaml import MetaYamlExtension + +class MarkdownYAMLReader(MarkdownReader): + """Reader for Markdown files with YAML metadata""" + + def __init__(self, *args, **kwargs): + super(MarkdownYAMLReader, self).__init__(*args, **kwargs) + self.extensions.append(MetaYamlExtension()) + + def _parse_metadata(self, meta): + """Return the dict containing document metadata""" + + # MarkdownReader _parse_metadata() expects a list of length 1 + # containing a string of comma-seperated values for authors and tags + for x in ("tags", "authors"): + if x in meta: + meta[x] = [",".join(meta[x])] + + return super(MarkdownYAMLReader, self)._parse_metadata(meta) + +def add_reader(readers): + for k in MarkdownYAMLReader.file_extensions: + readers.reader_classes[k] = MarkdownYAMLReader + +def register(): + signals.readers_init.connect(add_reader) diff --git a/md_yaml/__init__.py b/md_yaml/__init__.py deleted file mode 100644 index 2f6bceb..0000000 --- a/md_yaml/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .md_yaml import * diff --git a/md_yaml/md_yaml.py b/md_yaml/md_yaml.py deleted file mode 100644 index 6c54ea8..0000000 --- a/md_yaml/md_yaml.py +++ /dev/null @@ -1,63 +0,0 @@ -import sys -import os - -from pelican import signals -from pelican.readers import BaseReader -from pelican.utils import pelican_open - -try: - from markdown import Markdown -except ImportError: - Markdown = False - -class MarkdownYAMLReader(BaseReader): - """Reader for Markdown files with YAML metadata""" - - enabled = bool(Markdown) - file_extensions = ['md', 'markdown', 'mkd', 'mdown'] - - def __init__(self, *args, **kwargs): - super(MarkdownYAMLReader, self).__init__(*args, **kwargs) - self.settings = args[0] - self.extensions = list(self.settings['MD_EXTENSIONS']) - if 'meta_yaml' not in self.extensions: - self.extensions.append('meta_yaml') - - def _parse_metadata(self, meta): - """Return the dict containing document metadata""" - - output = {} - for name, value in meta.items(): - name = name.lower() - output[name] = value - return output - - def read(self, source_path): - """Parse content and metadata of Markdown files with YAML metadata""" - - self.__set_plugin_path() - - self._md = Markdown(extensions=self.extensions) - with pelican_open(source_path) as text: - content = self._md.convert(text) - metadata = self._parse_metadata(self._md.Meta) - - self.__unset_plugin_path() - - return content, metadata - - def __set_plugin_path(self): - self.__sys_path_old = sys.path[:] - for pluginpath in self.settings['PLUGIN_PATHS']: - sys.path.insert(0, pluginpath) - sys.path.insert(0, os.path.join(pluginpath, 'md_yaml')) - - def __unset_plugin_path(self): - sys.path = self.__sys_path_old - -def add_reader(readers): - for k in MarkdownYAMLReader.file_extensions: - readers.reader_classes[k] = MarkdownYAMLReader - -def register(): - signals.readers_init.connect(add_reader) diff --git a/md_yaml/mdx_meta_yaml/LICENSE.md b/md_yaml/mdx_meta_yaml/LICENSE.md deleted file mode 100644 index 4cd8b14..0000000 --- a/md_yaml/mdx_meta_yaml/LICENSE.md +++ /dev/null @@ -1,30 +0,0 @@ -Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later) -Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b) -Copyright 2004 Manfred Stienstra (the original version) - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of the nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - diff --git a/md_yaml/mdx_meta_yaml/__init__.py b/md_yaml/mdx_meta_yaml/__init__.py deleted file mode 100644 index 16d8309..0000000 --- a/md_yaml/mdx_meta_yaml/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- - -from mdx_meta_yaml.extension import MetaYamlExtension - -def makeExtension(configs=None): - if isinstance(configs, list): - configs = dict(configs) - elif configs is None: - configs = {} - return MetaYamlExtension(configs=configs) diff --git a/md_yaml/mdx_meta_yaml/extension.py b/md_yaml/mdx_meta_yaml/extension.py deleted file mode 100644 index 40d7114..0000000 --- a/md_yaml/mdx_meta_yaml/extension.py +++ /dev/null @@ -1,100 +0,0 @@ -""" -# YAML Meta Data Extension for [Python-Markdown](https://github.com/waylan/Python-Markdown) - -This extension adds YAML meta data handling to markdown. - -As in the original, meta data is parsed but not used in processing. - -(YAML meta data is used e.g. by [pandoc](http://johnmacfarlane.net/pandoc/)) - -Dependencies: [PyYAML](http://pyyaml.org/) - - -Basic Usage: - - >>> import markdown - >>> text = '''--- - ... Title: Test Doc. - ... Author: Waylan Limberg - ... Blank_Data: - ... ... - ... - ... The body. This is paragraph one. - ... ''' - >>> md = markdown.Markdown(['meta_yaml']) - >>> print(md.convert(text)) -

The body. This is paragraph one.

- >>> print(md.Meta) # doctest: +SKIP - {'blank_data': [''], 'author': ['Waylan Limberg'], 'title': ['Test Doc.']} - -Make sure text without Meta Data still works (markdown < 1.6b returns a

). - - >>> text = ' Some Code - not extra lines of meta data.' - >>> md = markdown.Markdown(['meta_yaml']) - >>> print(md.convert(text)) -

Some Code - not extra lines of meta data.
-	
- >>> md.Meta - {} - - -Copyright 2014 Bernhard Fisseni - -Based on the meta data extension included with Python-Markdown, -Copyright 2007-2008 [Waylan Limberg](http://achinghead.com). - -License: BSD (see LICENSE.md for details) - -""" - -from __future__ import absolute_import -from __future__ import unicode_literals -from markdown import Extension -from markdown.preprocessors import Preprocessor -import yaml -# from yaml.scanner import ScannerError - - -class MetaYamlExtension (Extension): - """Extension for parsing YAML-Metadata with Python-Markdown.""" - - def extendMarkdown(self, md, md_globals): - """Add MetaYamlPreprocessor to Markdown instance.""" - - md.preprocessors.add('meta_yaml', MetaYamlPreprocessor(md), "_begin") - - -class MetaYamlPreprocessor(Preprocessor): - """ - Get Meta-Data. - - A YAML block is delimited by - - a line '---' at the start - - and a '...' or '---' line - at the end. - """ - - def run(self, lines): - """ Parse Meta-Data and store in Markdown.Meta. """ - - in_yaml = False - yaml_block = [] - line = lines.pop(0) - - if line == '---': - in_yaml = True - else: - lines.insert(0, line) - - while in_yaml and lines: - line = lines.pop(0) - if line == '---' or line == '...': - break - yaml_block.append(line) - - if yaml_block: - yaml_block = "\n".join(yaml_block) - meta = yaml.load(yaml_block) - self.markdown.Meta = meta - - return lines From 008f240a8cd3c08f25f11352539c6b7031dd3c5f Mon Sep 17 00:00:00 2001 From: pR0Ps Date: Thu, 25 Dec 2014 00:41:29 -0500 Subject: [PATCH 3/6] Update README --- README.md | 63 ++++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 36ce202..5bb9f7a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -pelican-md-yaml -=============== +pelican-md-metayaml +=================== This [Pelican](https://github.com/getpelican/pelican) plugin adds a reader for Markdown files with [YAML](https://en.wikipedia.org/wiki/YAML) metadata. As the well-known static site generator [Jekyll](https://github.com/jekyll/jekyll) uses Markdown files with YAML metadata, this eases migration from Jekyll to Pelican. @@ -16,54 +16,37 @@ Dependencies Installation ------------ -Copy the `md_yaml` directory to the `plugins` directory of your Pelican project (or whatever directory you specified for plugins in Pelican's `PLUGIN_PATHS` setting) and add `'md_yaml'` to the list of plugins (Pelican setting `PLUGINS`) of your project. +Clone this repo (and it's submodules) to the `plugins` directory of your Pelican project (or whatever directory you specified for plugins in Pelican's `PLUGIN_PATHS` setting) and add `'md_metayaml'` to the list of plugins (Pelican setting `PLUGINS`) of your project. + +To make sure the submodule is included use `git clone --recursive [repo] [path]` +Alternatively, you can clone normally, then run `git submodule update --init` to checkout the submodule Usage ----- All your Markdown files (ending in `.md`, `.markdown`, `.mkd` and `.mdown`) will now be interpreted as using YAML for their metadata. + The following example shows a very simple article (only one line of text at the bottom) but with quite complex metadata (everything between the `---`): ``` --- -template: article_recipe -title: Tiramisù -components: - - name: Tiramisù - for: 10 - ingredients: - - - 4 - - eggs - - - 150g - - sugar - - - 10 small cups - - espresso - - - 500g - - mascarpone - - - 1 package - - ladyfingers +title: Some title +author: Some person +tags: + - tag 1 + - tag 2 +date: 2014-12-25 00:00 +data: + - name: some name + options: + - opt 1 + - opt 2 + - opt 3 steps: - - Cook the espresso, pour it into a soup plate. - - Separate the eggs very carefully. - - Add very little salt to the egg white. - - Blend egg yolk and sugar and mix it extensively for some minutes using a mixer, until you obtain a homogenous mass. - - Add mascarpone and mix again very extensively. - - Beat the egg white and fold it into the other mass. - - Construct the tiramisù: First a layer of cream, then a layer of ladyfingers dipped into espresso, cream, ladyfingers, ..., cream. Sprinkle with cacao. - - Put the tiramisù into the fridge for about a night, serve cold! + - Step 1 + - Step 2 + - Step 3 --- -Thank you Silvia for the recipe! +This is the only text in the article. ``` - -Warranty --------- - -No warranty whatsoever is provided for either the code or the recipe provided above! ;) Use only at your own risk! - -References ----------- - -* This Pelican plugin uses the Markdown extension `mdx_meta_yaml` found here: -* The Pelican plugin `markdown-pullquote` was used as an example for a Pelican plugin providing a Markdown extension and can be found here: -* A similar approach to YAML metadata in Markdown files can be found here: From ced3d62e1a6a28232f1df3ee6dd7641cc5ec5975 Mon Sep 17 00:00:00 2001 From: pR0Ps Date: Thu, 25 Dec 2014 01:50:19 -0500 Subject: [PATCH 4/6] Change submodule to https --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 327aab8..d926f13 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "markdown_metayaml"] path = markdown_metayaml - url = git@github.com:pR0Ps/markdown_metayaml.git + url = https://github.com/pR0Ps/markdown-metayaml.git From 88f540841b8b7c5e37b6043630d7d14c520af9c6 Mon Sep 17 00:00:00 2001 From: pR0Ps Date: Sun, 28 Dec 2014 20:30:28 -0500 Subject: [PATCH 5/6] Update markdown_metayaml submodule --- markdown_metayaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown_metayaml b/markdown_metayaml index 201a20e..2743341 160000 --- a/markdown_metayaml +++ b/markdown_metayaml @@ -1 +1 @@ -Subproject commit 201a20e1c3cf6f89cb7d38fbb2a7da3f81923091 +Subproject commit 27433419bdc7311f2d34c7316207603a02f03f52 From e266d28f8ca7450d9f604dfc23df94cf7eaca1e4 Mon Sep 17 00:00:00 2001 From: pR0Ps Date: Mon, 2 Feb 2015 21:21:07 -0500 Subject: [PATCH 6/6] Change submodule back to the upstream The upsteam has accepted the pull request that adds unicode support, along with other minor tweaks. Switching back to the original project. --- .gitmodules | 2 +- markdown_metayaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index d926f13..9210c17 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "markdown_metayaml"] path = markdown_metayaml - url = https://github.com/pR0Ps/markdown-metayaml.git + url = https://github.com/teoric/python-markdown-yaml-meta-data.git diff --git a/markdown_metayaml b/markdown_metayaml index 2743341..dd7f3b6 160000 --- a/markdown_metayaml +++ b/markdown_metayaml @@ -1 +1 @@ -Subproject commit 27433419bdc7311f2d34c7316207603a02f03f52 +Subproject commit dd7f3b648d8f8fab80dfb40b2d1604c74db72d16