DEV Community

Cover image for I built a VS Code extension that lets you read books as source code
Saad
Saad

Posted on

I built a VS Code extension that lets you read books as source code

Every developer has dead time. A 12-minute CI run. A long build. A meeting that starts late. I wanted to read a few pages in those gaps, but opening a book app means leaving my editor, and a novel on my second monitor is not exactly low profile.

So I built Plain Sight Reader, a VS Code extension that opens PDF and EPUB books as a normal editor tab, rendered to look like something else.

Plain Sight Reader demo

What it does

Import a book, and its text appears in an editor tab in one of three disguise modes:

  • code: the text becomes comments inside a source file, in the language of your choice (8 supported), split into small groups so it looks like documented code
  • markdown: reads like a docs page or README
  • log: a stream of timestamped log lines

You can switch modes with one command, page through with the keyboard, jump between sections, and hit a panic key that closes the reader tab immediately.

Why it works well as an editor extension

  • No context switch. The book is a tab next to your code.
  • Keyboard-driven. Next/previous page and section without touching the mouse.
  • It resumes. Your position is saved per book and restored when you reopen it.
  • Offline. No accounts, no telemetry, no network calls. Books stay on your machine.

How it works (the interesting bits)

  • PDF text extraction uses pdf-parse, followed by heuristics to detect sections.
  • EPUBs are unzipped with jszip, then I walk the OPF spine and convert each XHTML chapter to plain text.
  • Pagination splits each section into pages, and a disguise renderer wraps those pages as code comments, markdown, or log lines.
  • The reader is a virtual document, so nothing gets written to your workspace and there is nothing to accidentally commit.

Limits (being honest)

Text extraction favours readability over exact layout. Footnotes, tables and multi-column PDFs may be reflowed, and images and formatting are dropped. Library sync across machines is manual.

Try it

Search for Plain Sight Reader in the Extensions view, or run:

code --install-extension saad-works.plain-sight-reader
Enter fullscreen mode Exit fullscreen mode

Source (MIT): https://github.com/saad-works/plain-sight-reader

What disguise would you add? If you have a PDF that breaks the extractor, open an issue and I'll take a look.

Top comments (0)