Skip to content

Commit e0ca51f

Browse files
authored
Merge pull request #53 from arnfinn/title_from_.title
Extract title from .title[my title]
2 parents ea239fa + ba35f7f commit e0ca51f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cicero/title.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
def extract_title(markdown):
22
for line in markdown.split('\n'):
3+
if ".title[" in line:
4+
start = line.index(".title[") + len(".title[")
5+
end = line.rindex("]", start)
6+
return line[start:end]
37
if '#' in line:
48
index_first_non_whitespace = len(line) - len(line.lstrip())
59
index_first_hash = line.index('#')
@@ -28,5 +32,23 @@ def test_extract_title():
2832
Licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
2933
Code examples: [OSI](http://opensource.org)-approved [MIT license](http://opensource.org/licenses/mit-license.html).
3034
35+
---'''
36+
markdown_alt = '''name: inverse
37+
layout: true
38+
class: center, middle, inverse
39+
40+
---
41+
42+
.title[Talking to [C/C++/Fortran] via CFFI]
43+
44+
.author[Radovan Bast]
45+
46+
High Performance Computing Group,
47+
UiT The Arctic University of Norway
48+
49+
Licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
50+
Code examples: [OSI](http://opensource.org)-approved [MIT license](http://opensource.org/licenses/mit-license.html).
51+
3152
---'''
3253
assert extract_title(markdown) == 'Talking to C/C++/Fortran via CFFI'
54+
assert extract_title(markdown_alt) == 'Talking to [C/C++/Fortran] via CFFI'

0 commit comments

Comments
 (0)