Skip to content

Instantly share code, notes, and snippets.

@nonZero
Created March 1, 2016 10:49
Show Gist options
  • Save nonZero/f2d8cab9491a9087c78e to your computer and use it in GitHub Desktop.
Save nonZero/f2d8cab9491a9087c78e to your computer and use it in GitHub Desktop.
read markdown with metadata from one file with multiple items
SEP_RE = re.compile(r'\n+-{5,}\n+')
def read_file(name):
with (pathlib.Path(__file__).parent / 'content' / '{}.md'.format(
name)).open() as f:
return f.read()
def get_item(txt):
md = markdown.Markdown(extensions=['markdown.extensions.meta'])
html = md.convert(txt)
meta = md.Meta
return {
'html': html,
'meta': meta,
}
def get_items(filename):
return [get_item(x) for x in SEP_RE.split(read_file(filename))]
class XXXXXView(WebsiteView):
def items(self):
return get_items("xxxxxx")
<ul class="list-group syllabi">
{% for item in view.items %}
<li class="list-group-item">
<h3 class="list-group-item-heading">
{{ item.meta.title.0 }}
</h3>
<div class="list-group-item-text">
{{ item.html|safe }}
<p>
<a href="{{ item.meta.link.0 }}">
More details
</a>
</p>
</div>
</li>
<p></p>
{% endfor %}
</ul>

title: Practical Python link: https://kuku.com/123

dfjadlfjda;lfk jad;lfk jad;lkfjad;fldf lorem ipsum delor.

dfjadlfjda;lfk jad;lfk jad;lkfjad;fldf lorem ipsum delor.


title: Programming with Python link: https://kuku.com/123

dfjadlfjda;lfk jad;lfk jad;lkfjad;fldf lorem ipsum delor.


title: Introduction To Programming with Python link: https://kuku.com/123

sdsada;ldfskj ad;lfkjda ;lfkjad ;flkdajf sadlkjdasffd ad

  • ldslfk jadflk
  • saldkjsaldkj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment