130 lines
3.1 KiB
Markdown
130 lines
3.1 KiB
Markdown
# kindle2notes
|
|
|
|
`kindle2notes` is a small C++17 command-line utility that converts Amazon
|
|
Kindle `My Clippings.txt` exports into structured notes.
|
|
|
|
Supported output formats:
|
|
|
|
- LaTeX (`--type=latex`)
|
|
- Markdown (`--type=md`)
|
|
|
|
Highlights are grouped by book title while preserving the order in which
|
|
books first appear in the input file.
|
|
|
|
## Input format
|
|
|
|
Each Kindle clipping is expected to have the following structure:
|
|
|
|
```text
|
|
Book Title
|
|
- Your Highlight on Location 123-125 | Added on ...
|
|
|
|
Highlighted text line 1
|
|
Highlighted text line 2
|
|
==========
|
|
```
|
|
|
|
The final clipping is processed even when the file does not end with the
|
|
`==========` separator. Incomplete clipping blocks are ignored.
|
|
|
|
## Output formats
|
|
|
|
### LaTeX
|
|
|
|
Books become sections, clipping metadata becomes subsections, and every
|
|
highlight receives an empty notes subsection:
|
|
|
|
```latex
|
|
\section {Book Title}
|
|
\subsection {- Your Highlight on Location 123-125 | Added on ...}
|
|
Highlighted text line 1
|
|
Highlighted text line 2
|
|
\subsubsection{notes}
|
|
```
|
|
|
|
LaTeX special characters are escaped automatically.
|
|
|
|
### Markdown
|
|
|
|
Books and clipping metadata become headings. Highlight text is emitted as a
|
|
Markdown block quote, followed by an empty notes heading:
|
|
|
|
```markdown
|
|
# Book Title
|
|
|
|
## - Your Highlight on Location 123-125 | Added on ...
|
|
|
|
> Highlighted text line 1
|
|
> Highlighted text line 2
|
|
|
|
### Notes
|
|
```
|
|
|
|
Empty lines inside highlights are preserved as `>` lines, and Markdown syntax
|
|
characters are escaped automatically.
|
|
|
|
## Architecture
|
|
|
|
Input parsing is implemented as a stage-driven pipeline with one handler for
|
|
each stage: title, metadata, and body. Handlers are registered and created
|
|
through the generic `TypeFactory` template, then cached for reuse while the
|
|
input is read.
|
|
|
|
Output generation uses a common abstract `Converter` interface. Concrete
|
|
converters are registered in another `TypeFactory` under their command-line
|
|
type names. The selected converter is created at runtime and invoked through
|
|
the common virtual `save()` method. Adding a new output format requires a new
|
|
`Converter` subclass and a corresponding factory registration.
|
|
|
|
## Build
|
|
|
|
The project has no Qt dependency. It requires a C++17 compiler and CMake 3.16
|
|
or newer.
|
|
|
|
```bash
|
|
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
|
cmake --build build --parallel
|
|
```
|
|
|
|
The resulting executable is:
|
|
|
|
```text
|
|
build/kindle2notes
|
|
```
|
|
|
|
## Usage
|
|
|
|
Generate LaTeX:
|
|
|
|
```bash
|
|
./build/kindle2notes \
|
|
--input "My Clippings.txt" \
|
|
--output notes.tex \
|
|
--type=latex
|
|
```
|
|
|
|
Generate Markdown:
|
|
|
|
```bash
|
|
./build/kindle2notes \
|
|
--input "My Clippings.txt" \
|
|
--output notes.md \
|
|
--type=md
|
|
```
|
|
|
|
Short options are also available:
|
|
|
|
```bash
|
|
./build/kindle2notes -i input.txt -o notes.md -t md
|
|
```
|
|
|
|
| Argument | Short form | Description |
|
|
| --- | --- | --- |
|
|
| `--input` | `-i` | Path to the Kindle clippings file |
|
|
| `--output` | `-o` | Path to the generated file |
|
|
| `--type` | `-t` | Output format: `latex` or `md` |
|
|
| `--help` | `-h` | Show usage information |
|
|
|
|
If an unsupported output type is requested, the program prints the list of
|
|
available formats and exits without creating an output file.
|