Skip to content

A simple tool to convert project code to a highlighted pdf file.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

igordejanovic/readcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

readcode

A simple tool for converting codebase to a pdf file.

Motivation

A desire to read code on a eink book reader.

Installation

Make sure you have Rust installed.

Then you can either:

git clone [email protected]:igordejanovic/readcode.git
cargo install readcode

or just

cargo install --git https://github.com/igordejanovic/readcode.git

Run

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.

Current features

  • Recurse over given folder and produces a highlighted text for each file.
  • Ignore all files ignored by .gitignore

Creating TOC

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.

TODO

  • 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.

About

A simple tool to convert project code to a highlighted pdf file.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published