scripts: improve generated PDF bookmark layout (#8809)

pull/1/head
Matthew Peveler 2022-10-07 19:10:44 -04:00 committed by GitHub
parent 5385806733
commit ffcd73854c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -34,3 +34,13 @@ h1, h2, h4, ul {
margin-top: 8.2em; margin-top: 8.2em;
font-size: 300%; font-size: 300%;
} }
/*
The same is to have this look like a H1 tag, but we want the H2 tag so the
bookmarks list makes sense.
*/
h2.title-page {
font-size: 2em;
margin-top: 0.67em;
margin-bottom: 0.67em;
}

View File

@ -10,7 +10,6 @@ through CSS, and finally rendering them as PDF. There is no LaTeX dependency for
import os import os
import sys import sys
import glob import glob
import re
import markdown import markdown
import argparse import argparse
from datetime import datetime from datetime import datetime
@ -34,10 +33,10 @@ def main(loc, colorscheme):
html = ( html = (
'<!doctype html><html><head><meta charset="utf-8"></head>' '<!doctype html><html><head><meta charset="utf-8"></head>'
+ "<body><h1 class=title-main>tldr pages</h1>" + "<body><h1 class=title-main>tldr pages</h1>"
+ "<h4 class=title-sub>Simplified and community-driven man pages</h4>" + "<div class=title-sub>Simplified and community-driven man pages</div>"
+ "<h6 class=title-sub><em><small>Generated on " + "<div class=title-sub><em><small>Generated on "
+ datetime.now().strftime("%c") + datetime.now().strftime("%c")
+ "</small></em></h6>" + "</small></em></div>"
+ '<p style="page-break-before: always" ></p>' + '<p style="page-break-before: always" ></p>'
) )
@ -46,9 +45,9 @@ def main(loc, colorscheme):
# Required string to create directory title pages # Required string to create directory title pages
html += ( html += (
"<h2 class=title-dir>" "<h1 class=title-dir>"
+ operating_sys.capitalize() + operating_sys.capitalize()
+ "</h2>" + "</h1>"
+ '<p style="page-break-before: always" ></p>' + '<p style="page-break-before: always" ></p>'
) )
@ -58,9 +57,12 @@ def main(loc, colorscheme):
): ):
with open(md, "r") as inp: with open(md, "r") as inp:
text = inp.readlines() text = inp.readlines()
# modify our page to have an H2 header, so that it is grouped under
# the H1 header for the directory
text[0] = "<h2 class='title-page'>" + text[0][2:] + "</h2>"
for line in text: for line in text:
if re.match(r"^>", line): if line.startswith(">"):
line = line[:0] + "####" + line[1:] line = "####" + line[1:]
html += markdown.markdown(line) html += markdown.markdown(line)
html += '<p style="page-break-before: always" ></p>' html += '<p style="page-break-before: always" ></p>'
print(f"Rendered page {page_number} of the directory {operating_sys}") print(f"Rendered page {page_number} of the directory {operating_sys}")