Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Markdown==2.6.8
Markdown==3.0.1
Pygments==1.6
Jinja2==2.7.3
PyYAML==3.11
Expand Down
10 changes: 9 additions & 1 deletion simiki/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ def get_meta_and_content(self, do_render=True):

return meta, content

def get_toc(self):
with io.open(self._src_file, "rt", encoding="utf-8") as fd:
cont_str=fd.read()
if cont_str:
md = markdown.Markdown(extensions=['markdown.extensions.toc'])
md.convert(cont_str)
return md.toc_tokens if cont_str else []

def get_layout(self, meta):
"""Get layout config in meta, default is `page'"""
if "layout" in meta:
Expand Down Expand Up @@ -170,7 +178,7 @@ def get_template_vars(self, meta, content):
page = {"content": content}
page.update(meta)
page.update({'relation': self.get_relation()})

page.update({"toc":self.get_toc()})
template_vars.update({'page': page})

return template_vars
Expand Down
3 changes: 2 additions & 1 deletion tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def test_get_template_vars(self):
u'date': '2013-10-17 00:03',
u'layout': 'page',
u'relation': [],
u'title': 'Foo Page 2'
u'title': 'Foo Page 2',
u'toc': []
},
u'site': get_default_config()
}
Expand Down