python-frontmatter 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python-frontmatter-0.2.0 → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages}/frontmatter/__init__.py +53 -18
- Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/frontmatter/__init__.pyc +0 -0
- Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/frontmatter/handlers.py +67 -0
- Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/frontmatter/handlers.pyc +0 -0
- {python-frontmatter-0.2.0 → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages}/frontmatter/util.py +4 -2
- Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/frontmatter/util.pyc +0 -0
- {python-frontmatter-0.2.0/python_frontmatter.egg-info → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/python_frontmatter-0.3.0-py2.7.egg-info}/PKG-INFO +14 -3
- {python-frontmatter-0.2.0/python_frontmatter.egg-info → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/python_frontmatter-0.3.0-py2.7.egg-info}/SOURCES.txt +3 -0
- {python-frontmatter-0.2.0/python_frontmatter.egg-info → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/python_frontmatter-0.3.0-py2.7.egg-info}/requires.txt +1 -1
- python-frontmatter-0.2.0/LICENSE +0 -21
- python-frontmatter-0.2.0/MANIFEST.in +0 -6
- python-frontmatter-0.2.0/PKG-INFO +0 -100
- python-frontmatter-0.2.0/README.md +0 -79
- python-frontmatter-0.2.0/setup.cfg +0 -5
- python-frontmatter-0.2.0/setup.py +0 -50
- python-frontmatter-0.2.0/tests/chinese.txt +0 -5
- python-frontmatter-0.2.0/tests/empty-frontmatter.txt +0 -4
- python-frontmatter-0.2.0/tests/extra-dash.txt +0 -6
- python-frontmatter-0.2.0/tests/hello-markdown.markdown +0 -18
- python-frontmatter-0.2.0/tests/hello-world.markdown +0 -6
- python-frontmatter-0.2.0/tests/network-diagrams.markdown +0 -12
- python-frontmatter-0.2.0/tests/no-frontmatter.txt +0 -1
- python-frontmatter-0.2.0/tests/unpretty.md +0 -21
- {python-frontmatter-0.2.0/python_frontmatter.egg-info → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/python_frontmatter-0.3.0-py2.7.egg-info}/dependency_links.txt +0 -0
- {python-frontmatter-0.2.0/python_frontmatter.egg-info → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/python_frontmatter-0.3.0-py2.7.egg-info}/not-zip-safe +0 -0
- {python-frontmatter-0.2.0/python_frontmatter.egg-info → Users/chris_amico/code/frontmatter/lib/python2.7/site-packages/python_frontmatter-0.3.0-py2.7.egg-info}/top_level.txt +0 -0
|
@@ -6,53 +6,70 @@ from __future__ import unicode_literals
|
|
|
6
6
|
|
|
7
7
|
import codecs
|
|
8
8
|
import re
|
|
9
|
-
import yaml
|
|
10
9
|
|
|
10
|
+
import six
|
|
11
|
+
|
|
12
|
+
import yaml
|
|
11
13
|
try:
|
|
12
14
|
from yaml import CSafeDumper as SafeDumper
|
|
13
15
|
except ImportError:
|
|
14
16
|
from yaml import SafeDumper
|
|
15
17
|
|
|
16
18
|
from .util import u
|
|
19
|
+
from .handlers import YAMLHandler, JSONHandler, TOMLHandler
|
|
17
20
|
|
|
18
|
-
__all__ = ['parse', 'load', 'loads', 'dump', 'dumps']
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
# split on this
|
|
22
|
-
FM_BOUNDARY = re.compile(r'^-{3,}$', re.MULTILINE)
|
|
22
|
+
__all__ = ['parse', 'load', 'loads', 'dump', 'dumps']
|
|
23
23
|
|
|
24
24
|
POST_TEMPLATE = """\
|
|
25
|
-
|
|
25
|
+
{start_delimiter}
|
|
26
26
|
{metadata}
|
|
27
|
-
|
|
27
|
+
{end_delimiter}
|
|
28
28
|
|
|
29
29
|
{content}
|
|
30
30
|
"""
|
|
31
31
|
|
|
32
|
+
# global handlers
|
|
33
|
+
handlers = {
|
|
34
|
+
'---': YAMLHandler(),
|
|
35
|
+
'{': JSONHandler(),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# if toml is installed
|
|
39
|
+
if TOMLHandler is not None:
|
|
40
|
+
handlers['+++'] = TOMLHandler()
|
|
41
|
+
|
|
32
42
|
|
|
33
43
|
def parse(text, **defaults):
|
|
34
44
|
"""
|
|
35
|
-
Parse text with
|
|
45
|
+
Parse text with frontmatter, return metadata and content.
|
|
36
46
|
Pass in optional metadata defaults as keyword args.
|
|
37
47
|
|
|
38
48
|
If frontmatter is not found, returns an empty metadata dictionary
|
|
39
|
-
and original text content.
|
|
49
|
+
(or defaults) and original text content.
|
|
40
50
|
"""
|
|
41
51
|
# ensure unicode first
|
|
42
|
-
text = u(text)
|
|
52
|
+
text = u(text).strip()
|
|
43
53
|
|
|
44
54
|
# metadata starts with defaults
|
|
45
55
|
metadata = defaults.copy()
|
|
46
56
|
|
|
47
|
-
|
|
57
|
+
for delim in handlers:
|
|
58
|
+
if text.startswith(delim):
|
|
59
|
+
handler = handlers[delim]
|
|
60
|
+
break
|
|
61
|
+
else:
|
|
62
|
+
return metadata, text
|
|
63
|
+
|
|
64
|
+
# split on the delimiters
|
|
48
65
|
try:
|
|
49
|
-
|
|
66
|
+
fm, content = handler.split(text)
|
|
50
67
|
except ValueError:
|
|
51
68
|
# if we can't split, bail
|
|
52
69
|
return metadata, text
|
|
53
70
|
|
|
54
|
-
# parse
|
|
55
|
-
fm =
|
|
71
|
+
# parse, now that we have frontmatter
|
|
72
|
+
fm = handler.load(fm)
|
|
56
73
|
if isinstance(fm, dict):
|
|
57
74
|
metadata.update(fm)
|
|
58
75
|
|
|
@@ -100,23 +117,30 @@ def dumps(post, **kwargs):
|
|
|
100
117
|
"""
|
|
101
118
|
kwargs.setdefault('Dumper', SafeDumper)
|
|
102
119
|
kwargs.setdefault('default_flow_style', False)
|
|
120
|
+
|
|
121
|
+
start_delimiter = kwargs.pop('start_delimiter', '---')
|
|
122
|
+
end_delimiter = kwargs.pop('end_delimiter', '---')
|
|
103
123
|
|
|
104
124
|
metadata = yaml.dump(post.metadata, **kwargs).strip()
|
|
105
125
|
metadata = u(metadata) # ensure unicode
|
|
106
|
-
|
|
126
|
+
|
|
127
|
+
return POST_TEMPLATE.format(
|
|
128
|
+
metadata=metadata, content=post.content,
|
|
129
|
+
start_delimiter=start_delimiter,
|
|
130
|
+
end_delimiter=end_delimiter).strip()
|
|
107
131
|
|
|
108
132
|
|
|
109
133
|
class Post(object):
|
|
110
134
|
"""
|
|
111
|
-
A post contains content and metadata from
|
|
135
|
+
A post contains content and metadata from Front Matter.
|
|
112
136
|
For convenience, metadata values are available as proxied item lookups.
|
|
113
137
|
|
|
114
138
|
Don't use this class directly. Use module-level functions load, dump, etc.
|
|
115
139
|
"""
|
|
116
140
|
def __init__(self, content, **metadata):
|
|
117
|
-
self.content = content
|
|
141
|
+
self.content = u(content)
|
|
118
142
|
self.metadata = metadata
|
|
119
|
-
|
|
143
|
+
|
|
120
144
|
def __getitem__(self, name):
|
|
121
145
|
"Get metadata key"
|
|
122
146
|
return self.metadata[name]
|
|
@@ -129,6 +153,17 @@ class Post(object):
|
|
|
129
153
|
"Delete a metadata key"
|
|
130
154
|
del self.metadata[name]
|
|
131
155
|
|
|
156
|
+
def __bytes__(self):
|
|
157
|
+
return self.content.encode('utf-8')
|
|
158
|
+
|
|
159
|
+
def __str__(self):
|
|
160
|
+
if six.PY2:
|
|
161
|
+
return self.__bytes__()
|
|
162
|
+
return self.content
|
|
163
|
+
|
|
164
|
+
def __unicode__(self):
|
|
165
|
+
return self.content
|
|
166
|
+
|
|
132
167
|
def get(self, key, default=None):
|
|
133
168
|
"Get a key, fallback to default"
|
|
134
169
|
return self.metadata.get(key, default)
|
|
Binary file
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Handlers for various kinds of metadata, including YAML, JSON and TOML
|
|
3
|
+
"""
|
|
4
|
+
from __future__ import unicode_literals
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
import yaml
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import toml
|
|
12
|
+
except ImportError:
|
|
13
|
+
toml = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BaseHandler(object):
|
|
17
|
+
FM_BOUNDARY = None
|
|
18
|
+
|
|
19
|
+
def __init__(self, fm_boundary=None):
|
|
20
|
+
self.FM_BOUNDARY = fm_boundary or self.FM_BOUNDARY
|
|
21
|
+
|
|
22
|
+
if self.FM_BOUNDARY is None:
|
|
23
|
+
raise NotImplementedError('No frontmatter boundary defined. '
|
|
24
|
+
'Please set {}.FM_BOUNDARY to a regular expression'.format(self.__class__.__name__))
|
|
25
|
+
|
|
26
|
+
def load(self, fm):
|
|
27
|
+
"""
|
|
28
|
+
Parse frontmatter and return a dict
|
|
29
|
+
"""
|
|
30
|
+
raise NotImplementedError
|
|
31
|
+
|
|
32
|
+
def split(self, text):
|
|
33
|
+
"""
|
|
34
|
+
Split text into frontmatter and content
|
|
35
|
+
"""
|
|
36
|
+
_, fm, content = self.FM_BOUNDARY.split(text, 2)
|
|
37
|
+
return fm, content
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class YAMLHandler(BaseHandler):
|
|
41
|
+
FM_BOUNDARY = re.compile(r'^-{3,}$', re.MULTILINE)
|
|
42
|
+
|
|
43
|
+
def load(self, fm):
|
|
44
|
+
return yaml.safe_load(fm)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class JSONHandler(BaseHandler):
|
|
49
|
+
FM_BOUNDARY = re.compile(r'^(?:{|})$', re.MULTILINE)
|
|
50
|
+
|
|
51
|
+
def load(self, fm):
|
|
52
|
+
return json.loads(fm)
|
|
53
|
+
|
|
54
|
+
def split(self, text):
|
|
55
|
+
_, fm, content = self.FM_BOUNDARY.split(text, 2)
|
|
56
|
+
return "{" + fm + "}", content
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if toml:
|
|
60
|
+
class TOMLHandler(BaseHandler):
|
|
61
|
+
FM_BOUNDARY = re.compile(r'^\+{3,}$', re.MULTILINE)
|
|
62
|
+
|
|
63
|
+
def load(self, fm):
|
|
64
|
+
return toml.loads(fm)
|
|
65
|
+
|
|
66
|
+
else:
|
|
67
|
+
TOMLHandler = None
|
|
Binary file
|
|
@@ -8,6 +8,8 @@ def u(text, encoding='utf-8'):
|
|
|
8
8
|
"Return unicode text, no matter what"
|
|
9
9
|
|
|
10
10
|
if isinstance(text, six.binary_type):
|
|
11
|
-
|
|
11
|
+
text = text.decode(encoding)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
# it's already unicode
|
|
14
|
+
text = text.replace('\r\n', '\n')
|
|
15
|
+
return text
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 1.
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
2
|
Name: python-frontmatter
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Parse and manage posts with YAML frontmatter
|
|
5
5
|
Home-page: https://github.com/eyeseast/python-frontmatter
|
|
6
6
|
Author: Chris Amico
|
|
@@ -15,6 +15,12 @@ Description: Python Frontmatter
|
|
|
15
15
|
|
|
16
16
|
[](https://travis-ci.org/eyeseast/python-frontmatter)
|
|
17
17
|
|
|
18
|
+
Install:
|
|
19
|
+
--------
|
|
20
|
+
|
|
21
|
+
pip install python-frontmatter
|
|
22
|
+
|
|
23
|
+
|
|
18
24
|
Usage:
|
|
19
25
|
------
|
|
20
26
|
|
|
@@ -39,6 +45,11 @@ Description: Python Frontmatter
|
|
|
39
45
|
>>> print(post.content)
|
|
40
46
|
Well, hello there, world.
|
|
41
47
|
|
|
48
|
+
# this works, too
|
|
49
|
+
>>> print(post)
|
|
50
|
+
Well, hello there, world.
|
|
51
|
+
|
|
52
|
+
|
|
42
53
|
Use metadata (metadata gets proxied as post keys):
|
|
43
54
|
|
|
44
55
|
>>> print(post['title'])
|
|
@@ -88,7 +99,7 @@ Description: Python Frontmatter
|
|
|
88
99
|
|
|
89
100
|
Keywords: frontmatter
|
|
90
101
|
Platform: UNKNOWN
|
|
91
|
-
Classifier: Development Status ::
|
|
102
|
+
Classifier: Development Status :: 4 - Beta
|
|
92
103
|
Classifier: Intended Audience :: Developers
|
|
93
104
|
Classifier: License :: OSI Approved :: MIT License
|
|
94
105
|
Classifier: Natural Language :: English
|
|
@@ -3,6 +3,7 @@ MANIFEST.in
|
|
|
3
3
|
README.md
|
|
4
4
|
setup.py
|
|
5
5
|
frontmatter/__init__.py
|
|
6
|
+
frontmatter/handlers.py
|
|
6
7
|
frontmatter/util.py
|
|
7
8
|
python_frontmatter.egg-info/PKG-INFO
|
|
8
9
|
python_frontmatter.egg-info/SOURCES.txt
|
|
@@ -13,7 +14,9 @@ python_frontmatter.egg-info/top_level.txt
|
|
|
13
14
|
tests/chinese.txt
|
|
14
15
|
tests/empty-frontmatter.txt
|
|
15
16
|
tests/extra-dash.txt
|
|
17
|
+
tests/hello-json.markdown
|
|
16
18
|
tests/hello-markdown.markdown
|
|
19
|
+
tests/hello-toml.markdown
|
|
17
20
|
tests/hello-world.markdown
|
|
18
21
|
tests/network-diagrams.markdown
|
|
19
22
|
tests/no-frontmatter.txt
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
PyYAML
|
|
2
|
-
six
|
|
2
|
+
six
|
python-frontmatter-0.2.0/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014 Chris Amico, Glass Eye Media LLC
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 1.0
|
|
2
|
-
Name: python-frontmatter
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Parse and manage posts with YAML frontmatter
|
|
5
|
-
Home-page: https://github.com/eyeseast/python-frontmatter
|
|
6
|
-
Author: Chris Amico
|
|
7
|
-
Author-email: eyeseast@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: Python Frontmatter
|
|
10
|
-
==================
|
|
11
|
-
|
|
12
|
-
[Jekyll](http://jekyllrb.com/)-style YAML front matter offers a useful way to add arbitrary, structured metadata to text documents, regardless of type.
|
|
13
|
-
|
|
14
|
-
This is a small package to load and parse files (or just text) with YAML front matter.
|
|
15
|
-
|
|
16
|
-
[](https://travis-ci.org/eyeseast/python-frontmatter)
|
|
17
|
-
|
|
18
|
-
Usage:
|
|
19
|
-
------
|
|
20
|
-
|
|
21
|
-
>>> import frontmatter
|
|
22
|
-
|
|
23
|
-
Load a post from a filename:
|
|
24
|
-
|
|
25
|
-
>>> post = frontmatter.load('tests/hello-world.markdown')
|
|
26
|
-
|
|
27
|
-
Or a file (or file-like object):
|
|
28
|
-
|
|
29
|
-
>>> with open('tests/hello-world.markdown') as f:
|
|
30
|
-
... post = frontmatter.load(f)
|
|
31
|
-
|
|
32
|
-
Or load from text:
|
|
33
|
-
|
|
34
|
-
>>> with open('tests/hello-world.markdown') as f:
|
|
35
|
-
... post = frontmatter.loads(f.read())
|
|
36
|
-
|
|
37
|
-
Access content:
|
|
38
|
-
|
|
39
|
-
>>> print(post.content)
|
|
40
|
-
Well, hello there, world.
|
|
41
|
-
|
|
42
|
-
Use metadata (metadata gets proxied as post keys):
|
|
43
|
-
|
|
44
|
-
>>> print(post['title'])
|
|
45
|
-
Hello, world!
|
|
46
|
-
|
|
47
|
-
Metadata is a dictionary, with some handy proxies:
|
|
48
|
-
|
|
49
|
-
>>> sorted(post.keys())
|
|
50
|
-
['layout', 'title']
|
|
51
|
-
|
|
52
|
-
>>> from pprint import pprint
|
|
53
|
-
>>> post['excerpt'] = 'tl;dr'
|
|
54
|
-
>>> pprint(post.metadata)
|
|
55
|
-
{'excerpt': 'tl;dr', 'layout': 'post', 'title': 'Hello, world!'}
|
|
56
|
-
|
|
57
|
-
If you don't need the whole post object, just parse:
|
|
58
|
-
|
|
59
|
-
>>> with open('tests/hello-world.markdown') as f:
|
|
60
|
-
... metadata, content = frontmatter.parse(f.read())
|
|
61
|
-
>>> print(metadata['title'])
|
|
62
|
-
Hello, world!
|
|
63
|
-
|
|
64
|
-
Write back to plain text, too:
|
|
65
|
-
|
|
66
|
-
>>> print(frontmatter.dumps(post)) # doctest: +NORMALIZE_WHITESPACE
|
|
67
|
-
---
|
|
68
|
-
excerpt: tl;dr
|
|
69
|
-
layout: post
|
|
70
|
-
title: Hello, world!
|
|
71
|
-
---
|
|
72
|
-
Well, hello there, world.
|
|
73
|
-
|
|
74
|
-
Or write to a file (or file-like object):
|
|
75
|
-
|
|
76
|
-
>>> from io import StringIO
|
|
77
|
-
>>> f = StringIO()
|
|
78
|
-
>>> frontmatter.dump(post, f)
|
|
79
|
-
>>> print(f.getvalue()) # doctest: +NORMALIZE_WHITESPACE
|
|
80
|
-
---
|
|
81
|
-
excerpt: tl;dr
|
|
82
|
-
layout: post
|
|
83
|
-
title: Hello, world!
|
|
84
|
-
---
|
|
85
|
-
Well, hello there, world.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Keywords: frontmatter
|
|
90
|
-
Platform: UNKNOWN
|
|
91
|
-
Classifier: Development Status :: 2 - Pre-Alpha
|
|
92
|
-
Classifier: Intended Audience :: Developers
|
|
93
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
94
|
-
Classifier: Natural Language :: English
|
|
95
|
-
Classifier: Programming Language :: Python :: 2
|
|
96
|
-
Classifier: Programming Language :: Python :: 2.6
|
|
97
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
98
|
-
Classifier: Programming Language :: Python :: 3
|
|
99
|
-
Classifier: Programming Language :: Python :: 3.3
|
|
100
|
-
Classifier: Programming Language :: Python :: 3.4
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
Python Frontmatter
|
|
2
|
-
==================
|
|
3
|
-
|
|
4
|
-
[Jekyll](http://jekyllrb.com/)-style YAML front matter offers a useful way to add arbitrary, structured metadata to text documents, regardless of type.
|
|
5
|
-
|
|
6
|
-
This is a small package to load and parse files (or just text) with YAML front matter.
|
|
7
|
-
|
|
8
|
-
[](https://travis-ci.org/eyeseast/python-frontmatter)
|
|
9
|
-
|
|
10
|
-
Usage:
|
|
11
|
-
------
|
|
12
|
-
|
|
13
|
-
>>> import frontmatter
|
|
14
|
-
|
|
15
|
-
Load a post from a filename:
|
|
16
|
-
|
|
17
|
-
>>> post = frontmatter.load('tests/hello-world.markdown')
|
|
18
|
-
|
|
19
|
-
Or a file (or file-like object):
|
|
20
|
-
|
|
21
|
-
>>> with open('tests/hello-world.markdown') as f:
|
|
22
|
-
... post = frontmatter.load(f)
|
|
23
|
-
|
|
24
|
-
Or load from text:
|
|
25
|
-
|
|
26
|
-
>>> with open('tests/hello-world.markdown') as f:
|
|
27
|
-
... post = frontmatter.loads(f.read())
|
|
28
|
-
|
|
29
|
-
Access content:
|
|
30
|
-
|
|
31
|
-
>>> print(post.content)
|
|
32
|
-
Well, hello there, world.
|
|
33
|
-
|
|
34
|
-
Use metadata (metadata gets proxied as post keys):
|
|
35
|
-
|
|
36
|
-
>>> print(post['title'])
|
|
37
|
-
Hello, world!
|
|
38
|
-
|
|
39
|
-
Metadata is a dictionary, with some handy proxies:
|
|
40
|
-
|
|
41
|
-
>>> sorted(post.keys())
|
|
42
|
-
['layout', 'title']
|
|
43
|
-
|
|
44
|
-
>>> from pprint import pprint
|
|
45
|
-
>>> post['excerpt'] = 'tl;dr'
|
|
46
|
-
>>> pprint(post.metadata)
|
|
47
|
-
{'excerpt': 'tl;dr', 'layout': 'post', 'title': 'Hello, world!'}
|
|
48
|
-
|
|
49
|
-
If you don't need the whole post object, just parse:
|
|
50
|
-
|
|
51
|
-
>>> with open('tests/hello-world.markdown') as f:
|
|
52
|
-
... metadata, content = frontmatter.parse(f.read())
|
|
53
|
-
>>> print(metadata['title'])
|
|
54
|
-
Hello, world!
|
|
55
|
-
|
|
56
|
-
Write back to plain text, too:
|
|
57
|
-
|
|
58
|
-
>>> print(frontmatter.dumps(post)) # doctest: +NORMALIZE_WHITESPACE
|
|
59
|
-
---
|
|
60
|
-
excerpt: tl;dr
|
|
61
|
-
layout: post
|
|
62
|
-
title: Hello, world!
|
|
63
|
-
---
|
|
64
|
-
Well, hello there, world.
|
|
65
|
-
|
|
66
|
-
Or write to a file (or file-like object):
|
|
67
|
-
|
|
68
|
-
>>> from io import StringIO
|
|
69
|
-
>>> f = StringIO()
|
|
70
|
-
>>> frontmatter.dump(post, f)
|
|
71
|
-
>>> print(f.getvalue()) # doctest: +NORMALIZE_WHITESPACE
|
|
72
|
-
---
|
|
73
|
-
excerpt: tl;dr
|
|
74
|
-
layout: post
|
|
75
|
-
title: Hello, world!
|
|
76
|
-
---
|
|
77
|
-
Well, hello there, world.
|
|
78
|
-
|
|
79
|
-
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
|
-
try:
|
|
5
|
-
from setuptools import setup
|
|
6
|
-
except ImportError:
|
|
7
|
-
from distutils.core import setup
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
with open('README.md') as f:
|
|
11
|
-
readme = f.read()
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
requirements = [
|
|
15
|
-
'PyYAML',
|
|
16
|
-
'six'
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
VERSION = '0.2.0'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
setup(
|
|
24
|
-
name = 'python-frontmatter',
|
|
25
|
-
version = VERSION,
|
|
26
|
-
description = 'Parse and manage posts with YAML frontmatter',
|
|
27
|
-
long_description = readme,
|
|
28
|
-
author = 'Chris Amico',
|
|
29
|
-
author_email = 'eyeseast@gmail.com',
|
|
30
|
-
url = 'https://github.com/eyeseast/python-frontmatter',
|
|
31
|
-
packages = ['frontmatter'],
|
|
32
|
-
include_package_data = True,
|
|
33
|
-
install_requires = requirements,
|
|
34
|
-
license = 'MIT',
|
|
35
|
-
zip_safe = False,
|
|
36
|
-
keywords = 'frontmatter',
|
|
37
|
-
classifiers=[
|
|
38
|
-
'Development Status :: 2 - Pre-Alpha',
|
|
39
|
-
'Intended Audience :: Developers',
|
|
40
|
-
'License :: OSI Approved :: MIT License',
|
|
41
|
-
'Natural Language :: English',
|
|
42
|
-
'Programming Language :: Python :: 2',
|
|
43
|
-
'Programming Language :: Python :: 2.6',
|
|
44
|
-
'Programming Language :: Python :: 2.7',
|
|
45
|
-
'Programming Language :: Python :: 3',
|
|
46
|
-
'Programming Language :: Python :: 3.3',
|
|
47
|
-
'Programming Language :: Python :: 3.4',
|
|
48
|
-
],
|
|
49
|
-
test_suite='test',
|
|
50
|
-
)
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "TODO: Understand Network Diagrams"
|
|
3
|
-
layout: post
|
|
4
|
-
published: true
|
|
5
|
-
tags: [todo]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
Kim Rees, sitting in for Nathan Yau at [Flowing Data](http://flowingdata.com), has been posting examples of [network diagrams](http://flowingdata.com/category/visualization/network-visualization/) lately. I have to confess I'm stumped by most of them them. Or maybe I'm just overwhelmed. Maybe I'm [not alone](http://flowingdata.com/2012/05/28/network-diagrams-simplified/):
|
|
9
|
-
|
|
10
|
-
> Network diagrams are notoriously messy. Even a small number of nodes can be overwhelmed by their chaotic placement and relationships. [Cody Dunne](http://www.cs.umd.edu/~cdunne/) of [HCIL](http://www.cs.umd.edu/hcil/) showed off [his new work in simplifying these complex structures](http://www.cs.umd.edu/localphp/hcil/tech-reports-search.php?number=2012-11). In essence, he aggregates leaf nodes into a fan glyph that describes the underlying data in its size, arc, and color. Span nodes are similarly captured into crescent glyphs. The result is an easy to read, high level look at the network. You can easily compare different sections of the network, understand areas that may have been occluded by the lines in a traditional diagram, and see relationships far more quickly.
|
|
11
|
-
|
|
12
|
-
This seems like the kind of thing that could be useful for news, where we're often trying to understand and illustrate complex relationships. I'll have to find a good dataset to play with.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
I have no frontmatter.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
destination:
|
|
3
|
-
encoding:
|
|
4
|
-
xz:
|
|
5
|
-
enabled: true
|
|
6
|
-
min_size: 5120
|
|
7
|
-
options:
|
|
8
|
-
path_filter:
|
|
9
|
-
result:
|
|
10
|
-
append_to_file:
|
|
11
|
-
append_to_lafs_dir:
|
|
12
|
-
print_to_stdout: true
|
|
13
|
-
url: http://localhost:3456/uri
|
|
14
|
-
filter:
|
|
15
|
-
- 'Длинный стринг на русском'
|
|
16
|
-
- 'Еще одна длинная строка'
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
This is a test of both unicode and prettier dumping. The above metadata comes from the [pretty-yaml](https://github.com/mk-fg/pretty-yaml) readme file.
|
|
20
|
-
|
|
21
|
-
Metadata should be dumped in order.
|
|
File without changes
|
|
File without changes
|