From 0d60536dd55603f4cbc88aa374fad23afc7f2cb0 Mon Sep 17 00:00:00 2001 From: Youen Date: Thu, 11 May 2023 00:39:52 +0200 Subject: [PATCH] Correction de la structure des titres MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tous les titres étaients imbriqués dans "Avant propos" ; maintenant "avant propos" est au même niveau que "Documentation" etc. --- source/index.md | 2 +- sphinx-tools/make_pdf.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/index.md b/source/index.md index 15c81eb..736c3a3 100644 --- a/source/index.md +++ b/source/index.md @@ -14,7 +14,7 @@ Guide de montage – Version 1.0.0 - Mai 2023 :width: 200px ``` -# Avant propos +

Avant propos

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) diff --git a/sphinx-tools/make_pdf.py b/sphinx-tools/make_pdf.py index 1db7359..63a2b7a 100644 --- a/sphinx-tools/make_pdf.py +++ b/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('', '') + +# 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)