Skip to content

Commit

Permalink
Merge pull request #53 from arnfinn/title_from_.title
Browse files Browse the repository at this point in the history
Extract title from .title[my title]
  • Loading branch information
bast committed Dec 17, 2017
2 parents ea239fa + ba35f7f commit e0ca51f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cicero/title.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
def extract_title(markdown):
for line in markdown.split('\n'):
if ".title[" in line:
start = line.index(".title[") + len(".title[")
end = line.rindex("]", start)
return line[start:end]
if '#' in line:
index_first_non_whitespace = len(line) - len(line.lstrip())
index_first_hash = line.index('#')
Expand Down Expand Up @@ -28,5 +32,23 @@ def test_extract_title():
Licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
Code examples: [OSI](http://opensource.org)-approved [MIT license](http://opensource.org/licenses/mit-license.html).
---'''
markdown_alt = '''name: inverse
layout: true
class: center, middle, inverse
---
.title[Talking to [C/C++/Fortran] via CFFI]
.author[Radovan Bast]
High Performance Computing Group,
UiT The Arctic University of Norway
Licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
Code examples: [OSI](http://opensource.org)-approved [MIT license](http://opensource.org/licenses/mit-license.html).
---'''
assert extract_title(markdown) == 'Talking to C/C++/Fortran via CFFI'
assert extract_title(markdown_alt) == 'Talking to [C/C++/Fortran] via CFFI'

0 comments on commit e0ca51f

Please sign in to comment.