Добавлен !markdown для YAML

master
Антон Касимов 2018-10-31 20:23:24 +03:00
parent 6f771d8740
commit e8519fd954
2 changed files with 19 additions and 0 deletions

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
all: bdist
bdist:
python3 setup.py sdist bdist_wheel

View File

@ -10,12 +10,16 @@ from pathlib import PurePath
from ..resources import (Folder, Document, Markdown, YAML, Jinja2)
import yaml
import frontmatter
import markdown
from ..filters import IgnoreExtension
class Loader(yaml.Loader):
def __init__(self, stream):
super(Loader, self).__init__(stream)
Loader.add_constructor('!include', Loader.include)
Loader.add_constructor('!markdown', Loader.markdown)
def include(self, node):
if isinstance(node, yaml.ScalarNode):
@ -35,6 +39,17 @@ class Loader(yaml.Loader):
raise yaml.constructor.ConstructorError(
"Error:: unrecognised node type in !include statement")
def markdown(self, node):
if not isinstance(node, yaml.ScalarNode):
raise yaml.constructor.ConstructorError(
"Error:: unrecognised node type in !markdown statement")
m = self.construct_scalar(node)
return markdown.markdown(
m,
extensions=[IgnoreExtension(), 'markdown.extensions.extra'],
output_format='html5',
tab_length=2)
def extractFile(self, filename):
path = PurePath(self.data_dir) / filename
f = AssetResolver().resolve(str(path)).stream()