Добавлен !markdown для YAML
parent
6f771d8740
commit
e8519fd954
|
@ -0,0 +1,4 @@
|
||||||
|
all: bdist
|
||||||
|
|
||||||
|
bdist:
|
||||||
|
python3 setup.py sdist bdist_wheel
|
|
@ -10,12 +10,16 @@ from pathlib import PurePath
|
||||||
from ..resources import (Folder, Document, Markdown, YAML, Jinja2)
|
from ..resources import (Folder, Document, Markdown, YAML, Jinja2)
|
||||||
import yaml
|
import yaml
|
||||||
import frontmatter
|
import frontmatter
|
||||||
|
import markdown
|
||||||
|
|
||||||
|
from ..filters import IgnoreExtension
|
||||||
|
|
||||||
|
|
||||||
class Loader(yaml.Loader):
|
class Loader(yaml.Loader):
|
||||||
def __init__(self, stream):
|
def __init__(self, stream):
|
||||||
super(Loader, self).__init__(stream)
|
super(Loader, self).__init__(stream)
|
||||||
Loader.add_constructor('!include', Loader.include)
|
Loader.add_constructor('!include', Loader.include)
|
||||||
|
Loader.add_constructor('!markdown', Loader.markdown)
|
||||||
|
|
||||||
def include(self, node):
|
def include(self, node):
|
||||||
if isinstance(node, yaml.ScalarNode):
|
if isinstance(node, yaml.ScalarNode):
|
||||||
|
@ -35,6 +39,17 @@ class Loader(yaml.Loader):
|
||||||
raise yaml.constructor.ConstructorError(
|
raise yaml.constructor.ConstructorError(
|
||||||
"Error:: unrecognised node type in !include statement")
|
"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):
|
def extractFile(self, filename):
|
||||||
path = PurePath(self.data_dir) / filename
|
path = PurePath(self.data_dir) / filename
|
||||||
f = AssetResolver().resolve(str(path)).stream()
|
f = AssetResolver().resolve(str(path)).stream()
|
||||||
|
|
Reference in New Issue