mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
clean_title(): Clean a little more carefully. Still does funny things with
underscores. Might this be a fundamental PDF limitation? Hm, could still be a TeX thing.
This commit is contained in:
parent
45e564dd78
commit
ac77b79df6
1 changed files with 15 additions and 6 deletions
|
|
@ -73,19 +73,28 @@ def parse_toc(fp, bigpart=None):
|
||||||
return top
|
return top
|
||||||
|
|
||||||
|
|
||||||
hackscore_rx = re.compile(r"\\(hackscore|raisebox)\s*{[^}]*}")
|
hackscore_rx = re.compile(r"\\hackscore\s*{[^}]*}")
|
||||||
title_rx = re.compile(r"\\[a-zA-Z]+\s*")
|
raisebox_rx = re.compile(r"\\raisebox\s*{[^}]*}")
|
||||||
|
title_rx = re.compile(r"\\([a-zA-Z])+\s+")
|
||||||
title_trans = string.maketrans("", "")
|
title_trans = string.maketrans("", "")
|
||||||
|
|
||||||
def clean_title(title):
|
def clean_title(title):
|
||||||
title = hackscore_rx.sub("_", title)
|
title = raisebox_rx.sub("", title)
|
||||||
|
title = hackscore_rx.sub(r"\\_", title)
|
||||||
|
pos = 0
|
||||||
while 1:
|
while 1:
|
||||||
m = title_rx.search(title)
|
m = title_rx.search(title, pos)
|
||||||
if m:
|
if m:
|
||||||
title = title[:m.start()] + title[m.end():]
|
start = m.start()
|
||||||
|
print "found", `title[start:m.end()]`
|
||||||
|
if title[start:start+15] != "\\textunderscore":
|
||||||
|
title = title[:start] + title[m.end():]
|
||||||
|
pos = start + 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
return string.translate(title, title_trans, "{}")
|
title = string.translate(title, title_trans, "{}")
|
||||||
|
print `title`
|
||||||
|
return title
|
||||||
|
|
||||||
|
|
||||||
def write_toc(toc, fp):
|
def write_toc(toc, fp):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue