Skip to content

Commit 3fc975e

Browse files
committed
moving things around
1 parent 2da7287 commit 3fc975e

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

common.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import posixpath
3838
import re
3939
import shutil
40+
import string
4041

4142

4243
_LINK_REGEX = r'!?\[(.*?)\]\((.*?)\)'
@@ -127,3 +128,23 @@ def backup(filename):
127128
else:
128129
# Everything's fine, we can safely get rid of the backup.
129130
os.remove(filename + '.backup')
131+
132+
133+
def header_link(title):
134+
"""Return a github-style link target for a title.
135+
136+
>>> header_link('Hello there!')
137+
'hello-there'
138+
"""
139+
# This doesn't handle multiple titles with the same text in the
140+
# same file, but usually that's not a problem. GitHub makes
141+
# links like the-title, the-title-1, the-title-2 etc.
142+
result = ''
143+
for character in title:
144+
if character in string.whitespace:
145+
result += '-'
146+
elif character in string.punctuation:
147+
pass
148+
else:
149+
result += character.lower()
150+
return result

make-html.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,12 @@ def __init__(self, pygments_style):
101101
self.pygments_style = pygments_style
102102
self.title = None # will be set by header()
103103

104-
def _get_header_link(self, title):
105-
"""Return a github-style link target for a title.
106-
107-
>>> TutorialRenderer()._get_header_link('Hello there!')
108-
'hello-there'
109-
"""
110-
# This doesn't handle multiple titles with the same text in the
111-
# same file, but usually that's not a problem. GitHub makes
112-
# links like the-title, the-title-1, the-title-2 etc.
113-
result = ''
114-
for character in title:
115-
if character in string.whitespace:
116-
result += '-'
117-
elif character in string.punctuation:
118-
pass
119-
else:
120-
result += character.lower()
121-
return result
122-
123104
def header(self, text, level, raw):
124105
"""Create a header that is also a link and a # link target."""
125106
# "# raw"
126107
if level == 1:
127108
self.title = text
128-
target = self._get_header_link(raw)
109+
target = common.header_link(raw)
129110
content = super().header(text, level, raw)
130111
return '<a name="{0}" href="#{0}">{1}</a>'.format(target, content)
131112

0 commit comments

Comments
 (0)