mirror of https://github.com/CrimsonTome/tldr.git
Rework PDF script (#3654)
parent
d77f8bc18a
commit
e2ae506613
|
@ -14,3 +14,7 @@ npm-debug.log
|
|||
# hosted at https://tldr-pages.github.io/assets/index.json
|
||||
pages/index.json
|
||||
index.json
|
||||
|
||||
# Generated PDF pages
|
||||
scripts/pdf/*.html
|
||||
scripts/pdf/tldr.pdf
|
||||
|
|
|
@ -11,21 +11,13 @@ This directory contains the script and related resources to generate a PDF copy
|
|||
## Highlights
|
||||
|
||||
- No LaTeX dependencies for generating the PDF.
|
||||
|
||||
- 3 available color-schemes- *Basic*, *Solarized Light* and *Solarized Dark*. More can be added easily through CSS.
|
||||
|
||||
- 3 available color-schemes: *Basic*, *Solarized Light* and *Solarized Dark*. More can be added easily through CSS.
|
||||
|
||||
## Requirements
|
||||
|
||||
The PDF is generated by first converting the markdown files to HTML, and then rendering those HTML files as PDF. It depends on the following libraries:
|
||||
The PDF is generated by first converting the markdown files to HTML, and then rendering those HTML files as PDF. It depends on `markdown` and `weasyprint` libraries. To install the dependencies, run:
|
||||
|
||||
#### Python-Markdown
|
||||
|
||||
pip3 install markdown
|
||||
|
||||
#### WeasyPrint
|
||||
|
||||
pip3 install WeasyPrint
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
Make sure OS specific dependencies for WeasyPrint are installed by following the instructions [here](http://weasyprint.readthedocs.io/en/latest/install.html).
|
||||
|
||||
|
@ -43,6 +35,3 @@ The color-schemes that can be specified are
|
|||
|
||||
* `solarized-light`
|
||||
* `solarized-dark`
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@font-face {
|
||||
font-family: 'PT_Serif-Web-Regular';
|
||||
src: url('PT_Serif-Web-Regular.ttf') format('truetype');
|
||||
font-family: "PT Serif";
|
||||
src: url("pt-serif-web-regular.ttf") format("truetype");
|
||||
}
|
||||
|
||||
p {
|
||||
|
@ -11,23 +11,23 @@ code {
|
|||
color: darkslategrey;
|
||||
}
|
||||
|
||||
h1, h4, h2, ul {
|
||||
font-family: "PT_Serif-Web-Regular";
|
||||
h1, h2, h4, ul {
|
||||
font-family: "PT Serif";
|
||||
}
|
||||
|
||||
h1.titlemain {
|
||||
.title-main {
|
||||
text-align: center;
|
||||
margin-top: 6em;
|
||||
font-size: 350%;
|
||||
}
|
||||
|
||||
h4.titlesub {
|
||||
.title-sub {
|
||||
text-align: center;
|
||||
font-size: 120%;
|
||||
color: darkslategrey;
|
||||
}
|
||||
|
||||
h2.titledir {
|
||||
.title-dir {
|
||||
text-align: center;
|
||||
margin-top: 8.2em;
|
||||
font-size: 300%;
|
||||
|
|
|
@ -32,37 +32,40 @@ def main(loc, colorscheme):
|
|||
oslist.sort()
|
||||
|
||||
# Required strings to create intermediate HTML files
|
||||
header = "<html><head><link rel=stylesheet type=text/css href=" + colorscheme + ".css></head><body>\n"
|
||||
header = '<!doctype html><html><head><meta charset="utf-8"><link rel="stylesheet" href="basic.css">'
|
||||
if colorscheme != "basic":
|
||||
header += '<link rel="stylesheet" href="' + colorscheme + '.css"></head><body>\n'
|
||||
header += "</head><body>\n"
|
||||
footer = "</body></html>"
|
||||
title_content = "<h1 class=titlemain>tldr pages</h1><h4 class=titlesub>Simplified and community driven man pages</h4></body></html>"
|
||||
title_content = "<h1 class=title-main>tldr pages</h1><h4 class=title-sub>Simplified and community-driven man pages</h4></body></html>"
|
||||
|
||||
# Creating title page
|
||||
with open("title.html", 'w') as f:
|
||||
with open("title.html", "w") as f:
|
||||
f.write(header + title_content)
|
||||
|
||||
group.append(HTML('title.html').render())
|
||||
group.append(HTML("title.html").render())
|
||||
|
||||
for operating_sys in oslist:
|
||||
|
||||
i = 1
|
||||
|
||||
# Required string to create directory title pages
|
||||
dir_title = "<h2 class=titledir>" + operating_sys.capitalize() + "</h2></body></html>"
|
||||
dir_title = "<h2 class=title-dir>" + operating_sys.capitalize() + "</h2></body></html>"
|
||||
|
||||
# Creating directory title page for current directory
|
||||
with open("dir_title.html", 'w') as os_html:
|
||||
with open("dir_title.html", "w") as os_html:
|
||||
os_html.write(header + dir_title)
|
||||
|
||||
group.append(HTML('dir_title.html').render())
|
||||
group.append(HTML("dir_title.html").render())
|
||||
|
||||
# Creating a list of all md files in the current directory
|
||||
for temp in glob.glob(os.path.join(loc, operating_sys, '*.md')):
|
||||
for temp in glob.glob(os.path.join(loc, operating_sys, "*.md")):
|
||||
allmd.append(temp)
|
||||
|
||||
# Sorting all filenames in the directory, to maintain the order of the PDF
|
||||
allmd.sort()
|
||||
|
||||
#Conversion of md to HTML
|
||||
# Conversion of Markdown to HTML
|
||||
for md in allmd:
|
||||
|
||||
with open(md, "r") as inp:
|
||||
|
@ -78,7 +81,7 @@ def main(loc, colorscheme):
|
|||
out.write(html)
|
||||
out.write(footer)
|
||||
|
||||
group.append(HTML('htmlout.html').render())
|
||||
group.append(HTML("htmlout.html").render())
|
||||
print("Rendered page {} of the directory {}".format(str(i), operating_sys))
|
||||
i += 1
|
||||
|
||||
|
@ -104,7 +107,7 @@ def main(loc, colorscheme):
|
|||
print("Error removing temporary file(s)")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Unless specified otherwise by the user, this is the default colorscheme
|
||||
colorscheme = "basic"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
markdown
|
||||
weasyprint
|
|
@ -1,18 +1,8 @@
|
|||
@font-face {
|
||||
font-family: 'PT_Serif-Web-Regular';
|
||||
src: url('PT_Serif-Web-Regular.ttf') format('truetype');
|
||||
}
|
||||
|
||||
p {
|
||||
margin-left: 2.5em;
|
||||
}
|
||||
|
||||
code {
|
||||
color: #b58900;
|
||||
}
|
||||
|
||||
h1, h2, h4, ul {
|
||||
font-family: "PT_Serif-Web-Regular";
|
||||
color: #93a1a1;
|
||||
}
|
||||
|
||||
|
@ -20,21 +10,6 @@ body {
|
|||
background-color: #002b36;
|
||||
}
|
||||
|
||||
|
||||
h1.titlemain {
|
||||
text-align: center;
|
||||
margin-top: 6em;
|
||||
font-size: 350%;
|
||||
}
|
||||
|
||||
h4.titlesub {
|
||||
text-align: center;
|
||||
font-size: 120%;
|
||||
.title-sub {
|
||||
color: #b58900;
|
||||
}
|
||||
|
||||
h2.titledir {
|
||||
text-align: center;
|
||||
margin-top: 8.2em;
|
||||
font-size: 300%;
|
||||
}
|
|
@ -1,18 +1,8 @@
|
|||
@font-face {
|
||||
font-family: 'PT_Serif-Web-Regular';
|
||||
src: url('PT_Serif-Web-Regular.ttf') format('truetype');
|
||||
}
|
||||
|
||||
p {
|
||||
margin-left: 2.5em;
|
||||
}
|
||||
|
||||
code {
|
||||
color: #dc322f
|
||||
}
|
||||
|
||||
h1, h2, h4, ul {
|
||||
font-family: "PT_Serif-Web-Regular";
|
||||
color: #586e75;
|
||||
}
|
||||
|
||||
|
@ -20,20 +10,6 @@ body {
|
|||
background-color: #fdf6e3;
|
||||
}
|
||||
|
||||
h1.titlemain {
|
||||
text-align: center;
|
||||
margin-top: 6em;
|
||||
font-size: 350%;
|
||||
}
|
||||
|
||||
h4.titlesub {
|
||||
text-align: center;
|
||||
font-size: 120%;
|
||||
.title-sub {
|
||||
color: #dc322f
|
||||
}
|
||||
|
||||
h2.titledir {
|
||||
text-align: center;
|
||||
margin-top: 8.2em;
|
||||
font-size: 300%;
|
||||
}
|
Loading…
Reference in New Issue