Correction de la structure des titres
Tous les titres étaients imbriqués dans "Avant propos" ; maintenant "avant propos" est au même niveau que "Documentation" etc.
This commit is contained in:
parent
2187316dbf
commit
0d60536dd5
2 changed files with 15 additions and 7 deletions
|
|
@ -6,6 +6,7 @@ import os
|
|||
source_dir = sys.argv[1]
|
||||
build_dir = sys.argv[2]
|
||||
insert_toc_after_page = 1
|
||||
max_bookmark_level = 3
|
||||
|
||||
index_pdf_filename = build_dir + '/weasyprint/index.pdf'
|
||||
css_filename = source_dir + '/css/print-theme.css'
|
||||
|
|
@ -17,7 +18,7 @@ assert(subprocess.run(['weasyprint', build_dir + '/weasyprint/index.html', index
|
|||
|
||||
# Generate table of content (TOC)
|
||||
assert(subprocess.run(['sh', '-c', script_dir + '/../pdftoc-to-latex "' + index_pdf_filename + '" > "' + build_dir + '/weasyprint/toc.tex"']).returncode == 0)
|
||||
assert(subprocess.run(['pdflatex', '-interaction', 'nonstopmode', '-output-directory=' + build_dir + '/weasyprint', build_dir + '/weasyprint/toc.tex']).returncode == 1)
|
||||
subprocess.run(['pdflatex', '-interaction', 'nonstopmode', '-output-directory=' + build_dir + '/weasyprint', build_dir + '/weasyprint/toc.tex'])
|
||||
|
||||
# Count TOC pages
|
||||
toc_pdfinfo = subprocess.run(['pdfinfo', build_dir + '/weasyprint/toc.pdf'], stdout=subprocess.PIPE)
|
||||
|
|
@ -66,12 +67,19 @@ assert(subprocess.run(['pdftk', extract_bookmarks_from, 'dump_data', 'output', b
|
|||
with open(bookmarks_filename) as bookmarks_file:
|
||||
metadata = bookmarks_file.read()
|
||||
|
||||
# Offset page numbers of bookmarks
|
||||
def replaceBookmarkPageNumber(match):
|
||||
initial_page = int(match.group(1))
|
||||
# Remove link icon character at the end of each bookmark name (these are added by sphinx but make no sense in a PDF bookmark)
|
||||
metadata = metadata.replace('', '')
|
||||
|
||||
# Remove bookmarks for small titles, adjust page number for remaining ones
|
||||
def filterBookmark(match):
|
||||
#print('bookmark: "' + match.group(0) + '"')
|
||||
level = int(match.group(2))
|
||||
if level > max_bookmark_level:
|
||||
return ''
|
||||
initial_page = int(match.group(3))
|
||||
final_page = initial_page + toc_num_pages if initial_page > insert_toc_after_page else initial_page
|
||||
return 'BookmarkPageNumber: ' + str(final_page)
|
||||
metadata = re.sub('BookmarkPageNumber:\s+([0-9]+)', replaceBookmarkPageNumber, metadata)
|
||||
return 'BookmarkBegin\nBookmarkTitle: '+match.group(1).replace(' ', ' ')+'\nBookmarkLevel: '+match.group(2)+'\nBookmarkPageNumber: '+str(final_page)+'\n'
|
||||
metadata = re.sub('BookmarkBegin\nBookmarkTitle: (.*)\nBookmarkLevel: ([0-9]+)\nBookmarkPageNumber: ([0-9]+)\n', filterBookmark, metadata)
|
||||
|
||||
with open(bookmarks_filename, 'w') as bookmarks_file:
|
||||
bookmarks_file.write(metadata)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue