From c81e7a999f54fdfcc17b84fba69ff187aa9307ce Mon Sep 17 00:00:00 2001 From: Joachim Neu Date: Sat, 26 Sep 2015 01:49:24 +0200 Subject: [PATCH] Compatibility with Markdown's meta extension --- meta_yaml.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/meta_yaml.py b/meta_yaml.py index aea9c0d..3f011fe 100644 --- a/meta_yaml.py +++ b/meta_yaml.py @@ -47,29 +47,34 @@ 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 + try: from yaml import CBaseLoader as Loader except ImportError: - from yaml import BaseLoader + from yaml import BaseLoader as Loader # Override the default string handling function to always return unicode objects def construct_yaml_str(self, node): return self.construct_scalar(node) + Loader.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str) -class MetaYamlExtension (Extension): +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), ">meta") + + md.preprocessors.add("meta_yaml", MetaYamlPreprocessor(md), "