mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-04-29 23:24:55 +02:00
Merge branch 'master' of https://github.com/SuperSonicHub1/tldr into
SuperSonicHub1-master
This commit is contained in:
commit
ec9f4a4d1d
4 changed files with 43 additions and 42 deletions
|
@ -7,3 +7,6 @@ end_of_line = lf
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.py]
|
||||||
|
indent_size = 4
|
||||||
|
|
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
# VS Code
|
||||||
|
.vscode/
|
||||||
|
|
||||||
# macOS filesystem custom folder attributes
|
# macOS filesystem custom folder attributes
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
@ -18,3 +21,7 @@ index.json
|
||||||
# Generated PDF pages
|
# Generated PDF pages
|
||||||
scripts/pdf/*.html
|
scripts/pdf/*.html
|
||||||
scripts/pdf/tldr-pages.pdf
|
scripts/pdf/tldr-pages.pdf
|
||||||
|
|
||||||
|
# Python venv for testing the PDF script
|
||||||
|
# Create it with: python3 -m venv scripts/pdf/venv/
|
||||||
|
scripts/pdf/venv/
|
||||||
|
|
|
@ -4,9 +4,9 @@ This directory contains the script and related resources to generate a PDF docum
|
||||||
|
|
||||||
## Preview
|
## Preview
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## Highlights
|
## Highlights
|
||||||
|
|
||||||
|
@ -15,23 +15,24 @@ This directory contains the script and related resources to generate a PDF docum
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
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:
|
The PDF is generated by first converting the Markdown files to HTML, and then rendering those HTML files as a PDF. It depends on the `markdown` and `weasyprint` libraries. To install the dependencies, run:
|
||||||
|
|
||||||
pip3 install -r requirements.txt
|
python3 -m pip 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).
|
Make sure OS specific dependencies for WeasyPrint are installed by following the instructions [here](http://weasyprint.readthedocs.io/en/latest/install.html).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Generating the PDF is as simple as running
|
Generating the PDF is as simple as running:
|
||||||
|
|
||||||
python3 render.py <path-to-pages-directory> -c <color-scheme>
|
python3 render.py <path-to-pages-directory> --color <color-scheme>
|
||||||
|
|
||||||
Complete information about the arguments can be viewed by running
|
Complete information about the arguments can be viewed by running:
|
||||||
|
|
||||||
python3 render.py --help
|
python3 render.py --help
|
||||||
|
|
||||||
The color-schemes that can be specified are
|
The color-schemes that can be specified are:
|
||||||
|
|
||||||
|
* `basic`
|
||||||
* `solarized-light`
|
* `solarized-light`
|
||||||
* `solarized-dark`
|
* `solarized-dark`
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# A Python script to generate a single PDF document with all the `tldr` pages. It works by generating
|
"""
|
||||||
# intermediate HTML files from existing md files using Python-markdown, applying desired formatting
|
A Python script to generate a single PDF document with all the `tldr` pages. It works by generating
|
||||||
# through CSS, and finally rendering them as PDF. There is no LaTeX dependency for generating the PDF.
|
intermediate HTML files from existing md files using Python-markdown, applying desired formatting
|
||||||
|
through CSS, and finally rendering them as PDF. There is no LaTeX dependency for generating the PDF.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -53,8 +55,6 @@ def main(loc, colorscheme):
|
||||||
|
|
||||||
for operating_sys in oslist:
|
for operating_sys in oslist:
|
||||||
|
|
||||||
i = 1
|
|
||||||
|
|
||||||
# Required string to create directory title pages
|
# Required string to create directory title pages
|
||||||
dir_title = "<h2 class=title-dir>" + \
|
dir_title = "<h2 class=title-dir>" + \
|
||||||
operating_sys.capitalize() + "</h2></body></html>"
|
operating_sys.capitalize() + "</h2></body></html>"
|
||||||
|
@ -73,25 +73,24 @@ def main(loc, colorscheme):
|
||||||
allmd.sort()
|
allmd.sort()
|
||||||
|
|
||||||
# Conversion of Markdown to HTML
|
# Conversion of Markdown to HTML
|
||||||
for md in allmd:
|
for page_number, md in enumerate(allmd, start=1):
|
||||||
|
|
||||||
with open(md, "r") as inp:
|
with open(md, "r") as inp:
|
||||||
text = inp.readlines()
|
text = inp.readlines()
|
||||||
|
|
||||||
with open("htmlout.html", "w") as out:
|
with open("htmlout.html", "w") as out:
|
||||||
out.write(header)
|
out.write(header)
|
||||||
|
|
||||||
for line in text:
|
for line in text:
|
||||||
if re.match(r'^>', line):
|
if re.match(r'^>', line):
|
||||||
line = line[:0] + '####' + line[1:]
|
line = line[:0] + '####' + line[1:]
|
||||||
html = markdown.markdown(line)
|
html = markdown.markdown(line)
|
||||||
out.write(html)
|
out.write(html)
|
||||||
out.write(footer)
|
out.write(footer)
|
||||||
|
|
||||||
group.append(HTML("htmlout.html").render())
|
group.append(HTML("htmlout.html").render())
|
||||||
print("Rendered page {} of the directory {}".format(
|
print("Rendered page {} of the directory {}".format(
|
||||||
str(i), operating_sys))
|
str(page_number), operating_sys))
|
||||||
i += 1
|
|
||||||
|
|
||||||
allmd.clear()
|
allmd.clear()
|
||||||
|
|
||||||
|
@ -117,19 +116,10 @@ def main(loc, colorscheme):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
# Unless specified otherwise by the user, this is the default colorscheme
|
|
||||||
colorscheme = "basic"
|
|
||||||
|
|
||||||
# Parsing the arguments
|
# Parsing the arguments
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser(prog="tdlr-pages-to-PDF", description="A Python script to generate a single PDF document with all the `tldr` pages.")
|
||||||
parser.add_argument("dir_path", help="Path to the 'pages' directory")
|
parser.add_argument("dir_path", help = "Path to the 'pages' directory")
|
||||||
parser.add_argument("-c",
|
parser.add_argument("-c", "--color", choices=["solarized-light", "solarized-dark", "basic"], default="basic", help="Color scheme of the PDF")
|
||||||
choices=["solarized-light", "solarized-dark"],
|
|
||||||
help="Color scheme of the PDF")
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
loc = args.dir_path
|
main(args.dir_path, args.color)
|
||||||
if args.c == "solarized-light" or args.c == "solarized-dark":
|
|
||||||
colorscheme = args.c
|
|
||||||
|
|
||||||
main(loc, colorscheme)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue