Rename project to kindle2notes
This commit is contained in:
1 parent
15ff70b4c3
commit
432a1dc223
7 files changed
+110
-124
No files matched your search
@@ -1,68 +1,21 @@
|
||||
# Kindle Clippings → LaTeX Converter
|
||||
# kindle2notes
|
||||
|
||||
A small console utility that converts Amazon Kindle *My Clippings* text exports into structured LaTeX.
|
||||
`kindle2notes` is a small C++17 command-line utility that converts Amazon
|
||||
Kindle `My Clippings.txt` exports into structured notes.
|
||||
|
||||
The tool parses Kindle highlights and groups them by book title, producing a LaTeX structure with:
|
||||
Supported output formats:
|
||||
|
||||
* `\section{}` — per book
|
||||
* `\subsection{}` — per highlight (metadata line)
|
||||
* Highlight text — inserted as plain LaTeX content
|
||||
* `\subsubsection{notes}` — placeholder for future comments
|
||||
- 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.
|
||||
|
||||
## Architecture
|
||||
## Input format
|
||||
|
||||
This project demonstrates **two different parsing approaches** solving the same problem:
|
||||
Each Kindle clipping is expected to have the following structure:
|
||||
|
||||
### 1️⃣ FSM-based parser
|
||||
|
||||
Implemented using a template-based finite state machine (`fsm.h`).
|
||||
|
||||
Characteristics:
|
||||
|
||||
* Compile-time validated transitions
|
||||
* Strong type safety
|
||||
* Explicit state/event model
|
||||
* Strict contract enforcement
|
||||
|
||||
This version is useful when:
|
||||
|
||||
* The input format is more complex
|
||||
* You want compile-time guarantees for state transitions
|
||||
* The parsing logic may grow over time
|
||||
|
||||
---
|
||||
|
||||
### 2️⃣ TypeFactory-based parser
|
||||
|
||||
Implemented using a registration-based factory (`typefactory.h`).
|
||||
|
||||
Characteristics:
|
||||
|
||||
* Stage-driven pipeline
|
||||
* One handler per parsing stage
|
||||
* Runtime validation of handler registration
|
||||
* No per-line allocations (handlers cached once)
|
||||
|
||||
This version is:
|
||||
|
||||
* Simpler
|
||||
* More readable
|
||||
* Easier to debug
|
||||
* Well suited for linear, protocol-like formats
|
||||
|
||||
Both implementations produce identical LaTeX output.
|
||||
|
||||
---
|
||||
|
||||
## Input Format
|
||||
|
||||
Expected input is a standard Kindle `My Clippings.txt` export.
|
||||
|
||||
Each clipping block follows this structure:
|
||||
|
||||
```
|
||||
```text
|
||||
Book Title
|
||||
- Your Highlight on Location 123-125 | Added on ...
|
||||
|
||||
@@ -71,65 +24,106 @@ 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 Format
|
||||
## Output formats
|
||||
|
||||
Generated LaTeX structure:
|
||||
### 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 ...}
|
||||
\section {Book Title}
|
||||
\subsection {- Your Highlight on Location 123-125 | Added on ...}
|
||||
Highlighted text line 1
|
||||
Highlighted text line 2
|
||||
\subsubsection{notes}
|
||||
```
|
||||
|
||||
Highlights are grouped by book title.
|
||||
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
|
||||
|
||||
Requires a C++17-compatible compiler.
|
||||
The project has no Qt dependency. It requires a C++17 compiler and CMake 3.16
|
||||
or newer.
|
||||
|
||||
```bash
|
||||
g++ -std=gnu++17 -Wall -Wextra -O2 -o kindle2latex main.cpp
|
||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --parallel
|
||||
```
|
||||
|
||||
---
|
||||
The resulting executable is:
|
||||
|
||||
```text
|
||||
build/kindle2notes
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Generate LaTeX:
|
||||
|
||||
```bash
|
||||
./kindle2latex --input input.txt --output output.tex
|
||||
./build/kindle2notes \
|
||||
--input "My Clippings.txt" \
|
||||
--output notes.tex \
|
||||
--type=latex
|
||||
```
|
||||
|
||||
Arguments:
|
||||
Generate Markdown:
|
||||
|
||||
| Argument | Description |
|
||||
| ---------- | ----------------------------- |
|
||||
| `--input` | Path to Kindle clippings file |
|
||||
| `--output` | Path to generated LaTeX file |
|
||||
```bash
|
||||
./build/kindle2notes \
|
||||
--input "My Clippings.txt" \
|
||||
--output notes.md \
|
||||
--type=md
|
||||
```
|
||||
|
||||
---
|
||||
Short options are also available:
|
||||
|
||||
## Design Notes
|
||||
```bash
|
||||
./build/kindle2notes -i input.txt -o notes.md -t md
|
||||
```
|
||||
|
||||
* No dynamic allocations per input line (handlers are cached).
|
||||
* Order of books is preserved as in the original file.
|
||||
* LaTeX special characters are escaped automatically.
|
||||
* Incomplete clipping blocks are safely ignored.
|
||||
* The final block is flushed even if the file does not end with `==========`.
|
||||
| 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 |
|
||||
|
||||
---
|
||||
|
||||
## Why Two Implementations?
|
||||
|
||||
This repository intentionally keeps two different parsing styles:
|
||||
|
||||
* The FSM version demonstrates strict compile-time state control.
|
||||
* The TypeFactory version demonstrates a clean, extensible runtime pipeline.
|
||||
|
||||
The goal is architectural exploration and comparison, not just solving the parsing task.
|
||||
If an unsupported output type is requested, the program prints the list of
|
||||
available formats and exits without creating an output file.
|
||||
Reference in new issue
Block a user