A simple tool for converting codebase to a pdf file.
A desire to read code on a eink book reader.
Make sure you have Rust installed.
Then you can either:
git clone git@github.com:igordejanovic/readcode.git
cargo install readcode
or just
cargo install --git https://github.com/igordejanovic/readcode.git
readcode <path to project>
readcode
will recursivelly walk the given directory and for all valid utf-8
files not ignored by .gitignore it will perform syntax highlight and add it to a
pdf together with the file path as the title of the section. At the end you will
get output.pdf
file containing all the code from the project.
*Note: * The amount of code in a popular projects can be huge and this will make
readcode
to run out of memory. This might be mitigated in the next versions by
auto-splitting across multiple pdf files but for now give it a subfolder with
the amount of code that can be reasonable for a single pdf.
- Recurse over given folder and produces a highlighted text for each file.
- Ignore all files ignored by .gitignore
See this tool.
Basically what you need to do after creating output.pdf
with this tools is:
cat > recipe.toml << EOF
[[heading]]
level = 1
greedy = true
font.size = 14
EOF
pdftocgen output.pdf < recipe.toml > toc
# Workaround for empty lines
sed -i '/"File:"/d' toc
# Remove File prefixes
sed -i 's/"File: /"/' toc
# check toc file to see if the outline is correct
# create pdf with TOC
pdftocio -o output-toc.pdf output.pdf < toc
Note: At the root of this repo is a script readcode-toc.sh
which will do
this for you.
- Improve title detection. E.g. using
File:
prefix instead of font size. - Make TOC which respects directory nesting.
- Do auto-splitting of pdf for larger repositories.
- Make options for excluding folders.
- Make option to filter by file extensions.