Browse Source

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.
main
Youen 2 years ago
parent
commit
0d60536dd5
  1. 2
      source/index.md
  2. 20
      sphinx-tools/make_pdf.py

2
source/index.md

@ -14,7 +14,7 @@ Guide de montage – Version 1.0.0 - Mai 2023
:width: 200px
```
# Avant propos
<h2>Avant propos <a class="headerlink" href="#avant-propos" title="Permalink to this heading"></a></h2>
Le projet vhélio est collaboratif (amélioration continue grâce aux contributions de tous). L’objet vhéliotech et le présent document constituent la première version définitive du vhéliotech, mais l'objet est voué à évoluer continuellement. Vous êtes invités à faire part de vos retours/expériences/propositions d’améliorations sur le [forum](https://communaute.vhelio.org) ainsi que sur le [dépôt officiel de la documentation](https://git.vhelio.org/vhelio/vheliotech-guide-de-montage)

20
sphinx-tools/make_pdf.py

@ -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('&#61633;', '')
# 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('&#160;', ' ')+'\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…
Cancel
Save