paperforge-notes 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,477 @@
1
+ Metadata-Version: 2.4
2
+ Name: paperforge-notes
3
+ Version: 0.1.0
4
+ Summary: Themed ReportLab notes toolkit with markdown, HTML, PPTX, and flashcard exports
5
+ Author: Bharat Dangi
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: reportlab>=4.5.1
12
+ Requires-Dist: pygments>=2.20.0
13
+ Requires-Dist: paperforge-diagrams>=0.1.0
14
+ Provides-Extra: full
15
+ Requires-Dist: pymupdf>=1.25.0; extra == "full"
16
+ Requires-Dist: genanki>=0.13.1; extra == "full"
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=9.0.3; extra == "dev"
19
+ Requires-Dist: pytest-cov>=6.0; extra == "dev"
20
+ Requires-Dist: ruff>=0.9.0; extra == "dev"
21
+ Requires-Dist: mypy>=1.11.0; extra == "dev"
22
+
23
+ ![PaperForge](../assets/paperforge_logo_black.svg)
24
+ # 📝 paperforge_notes
25
+
26
+ [![Python Version](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/)
27
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
28
+ [![Format](https://img.shields.io/badge/format-PDF%20%7C%20HTML%20%7C%20PPTX%20%7C%20Anki-orange.svg)](#)
29
+
30
+ A themed ReportLab notes template generator with a built-in markdown compiler CLI.
31
+
32
+ It provides a simple, structured Python API to build beautiful academic notes, question banks, study guides, slides, and flashcards with unified dark/light themes and native vector diagrams.
33
+
34
+ ---
35
+
36
+ ## 🚀 Features
37
+
38
+ * **Premium Cover Pages**: Screenshot-worthy covers with `linear`, `notion`, `academic_modern`, `catppuccin`, `hero`, `book`, `diagram`, `modern`, `minimal`, `corporate`, `gradient`, `standard`, `academic`, and `textbook` styles. Tags, icons, and SVG background illustrations.
39
+ * **Built-in Presets**: One-line presets (`pn.cover_preset()`) for instant professional covers: `engineering`, `research-paper`, `course-notes`, `networking`, `database`, `programming`.
40
+ * **Table Column Control & Wrapping**: Custom column widths in `pn.info_table` and `pn.toc(style="index")`. Cells automatically wrap long words (>24 characters) using zero-width font-size spaces, avoiding clipping and missing-glyph black boxes in standard PDF fonts.
41
+ * **Mathematical Formulas**: Render LaTeX syntax inline or as centered equation blocks (`pn.formula()`, `pn.formula_block()`).
42
+ * **Textbook Callouts**: Semantic helper blocks including `warning()`, `important()`, `exam()`, `definition()`, `theorem()`, and `proof()`.
43
+ * **Study & Revision**: Build integrated study materials using `pn.question()`, `pn.qbox()`, `pn.answer()`, and `pn.mcq()`.
44
+ * **Flashcards & Anki Export**: Automatically compile definitions into interactive flashcards via `pn.flashcard()` and export directly to Anki `.apkg` format.
45
+ * **Multi-Format Publishing**: Export a single source document to PDF, HTML (`pn.build_html()`), and PowerPoint (`pn.build_pptx()`).
46
+ * **Themed Layouts**: 15 preset configurations for document-wide visual themes (Notion, GitHub, Linear, Academic, Textbook, Catppuccin, Sepia, etc.).
47
+ * **ThemeBuilder**: Custom dynamic theming engine to construct bespoke document layouts.
48
+ * **Prebuilt Templates**: Optimized formatting defaults like `EngineeringNotes` (technical manuals) and `QuestionBank` (exam papers/worksheets).
49
+ * **LaTeX-like Features**: Support for footnotes, cross-reference anchors, and compiled index tables.
50
+ * **Modular Compilation**: Combine multiple sub-scripts or markdown chapters using `pn.include_chapter()` and `pn.include_markdown()`.
51
+ * **Document Splitting**: Automate partitioning large documents by chapter boundaries or page ranges via `pn.build_split_doc()`.
52
+ * **Markdown CLI Compiler**: Compile standard Markdown files (with alerts and diagram blocks) directly to themed PDFs.
53
+
54
+ ---
55
+
56
+ ## 📦 Installation
57
+
58
+ Install the package locally:
59
+
60
+ ```bash
61
+ # Core: notes, diagrams, PDF export, syntax highlighting
62
+ pip install ./paperforge_notes
63
+
64
+ # Full: adds PPTX export, document splitting, and Anki export
65
+ pip install ./paperforge_notes[full]
66
+ ```
67
+
68
+ ---
69
+
70
+ ## 🐍 Python API Usage
71
+
72
+ ### 1. Premium Cover Pages
73
+
74
+ Create screenshot-worthy covers with modern styles, tags, icons, and background illustrations.
75
+
76
+ ```python
77
+ import paperforge_notes as pn
78
+
79
+ # Simple cover with built-in preset
80
+ pn.cover_preset(
81
+ "engineering",
82
+ title="Computer Networks",
83
+ subtitle="Complete Study Guide",
84
+ author="Bharat Dangi",
85
+ date="June 2026",
86
+ )
87
+
88
+ # Or build a custom premium cover
89
+ pn.cover_card(
90
+ title="Computer Networks",
91
+ subtitle="Complete Engineering Notes",
92
+ author="Bharat Dangi",
93
+ cover_theme="linear", # or style="linear"
94
+ icon="💻", # emoji or text icon
95
+ tags=[
96
+ "Networking",
97
+ "Semester IV",
98
+ "Exam Notes"
99
+ ],
100
+ )
101
+
102
+ # Add a faint SVG background illustration (optional svglib for native vector)
103
+ pn.cover_image(
104
+ "asset_images/network_topology.svg",
105
+ opacity=0.06,
106
+ placement="background",
107
+ )
108
+
109
+ pn.br()
110
+ ```
111
+
112
+ ### Cover Gallery
113
+
114
+ **Built-in Presets** (`pn.cover_preset(name)`):
115
+ | Preset | Style | Icon | Best For |
116
+ | ------ | ----- | ---- | -------- |
117
+ | `engineering` | `linear` | 💻 | SaaS docs, engineering guides |
118
+ | `research-paper` | `academic_modern` | 📐 | Research papers, peer review |
119
+ | `course-notes` | `catppuccin` | 📘 | Course notes, study guides |
120
+ | `networking` | `notion` | 🔗 | CCNA, network diagrams |
121
+ | `database` | `academic_modern` | 🗃️ | Database systems, SQL |
122
+ | `programming` | `linear` | 🐘 | Programming, software engineering |
123
+
124
+ **Cover Styles** (`pn.cover_card(style=...)`):
125
+ | Style | Best For |
126
+ | ----- | -------- |
127
+ | `linear` | SaaS docs, engineering guides — huge typography, gradient corner |
128
+ | `notion` | Clean, minimalist docs — icon-heavy, generous whitespace |
129
+ | `academic_modern` | O'Reilly / Manning inspired — structured, professional |
130
+ | `catppuccin` | Developer-focused — soft pastels, rounded cards |
131
+ | `textbook` | Student notes — thick accent bar, nested metadata |
132
+ | `modern` | General purpose — rounded card with accent border |
133
+ | `minimal` | Ultra clean — thin left bar, elegant typography |
134
+ | `gradient` | Colorful — diagonal corner split with dual accents |
135
+ | `corporate` | Business — top/bottom frame layout |
136
+ | `academic` | Formal — double frame with corner ornaments |
137
+ | `standard` | Legacy boxed card |
138
+ | `hero` | Massive typography, generous whitespace |
139
+ | `book` | Classic textbook aesthetic with surface color blocks |
140
+ | `diagram` | SVG background illustration with accent text |
141
+
142
+ ### 2. Basic Note Structuring
143
+
144
+ ```python
145
+ import paperforge_notes as pn
146
+
147
+ # Choose a theme
148
+ pn.set_theme(pn.DARK)
149
+
150
+ # Create a cover page
151
+ pn.bookmark("Cover Page")
152
+ pn.suppress_footer(page_only=True)
153
+ pn.sp(40)
154
+ pn.cover_card("Computer Science Notes", "Unit I: Basics", style="modern", author="Bharat Dangi")
155
+ pn.br()
156
+
157
+ # IMPORTANT: Do not call pn.bookmark() manually for standard sections!
158
+ # pn.chap_box() and pn.section() automatically register themselves in the TOC.
159
+
160
+ # Add Table of Contents
161
+ pn.suppress_footer(page_only=True)
162
+ pn.toc(style="standard")
163
+
164
+ # Main content
165
+ pn.footer(left="Algorithms", right="Unit I", show_page_num=True)
166
+ pn.part_box(
167
+ "Unit I: Basic Algorithms",
168
+ subtitle="Analysis of sorting and search methods",
169
+ topics=["Complexity Theory", "Divide & Conquer", "Pivot Selection"]
170
+ )
171
+ pn.chap_box("1.1 Sorting")
172
+ pn.section("Quick Sort")
173
+ pn.body("Quick Sort is a divide-and-conquer sorting algorithm.")
174
+ pn.tip("Average case time complexity is O(N log N).")
175
+ pn.note("Worst case time complexity is O(N^2) when the pivot is poorly chosen.")
176
+
177
+ # Compile the document
178
+ pn.build_doc("sorting_notes.pdf")
179
+ ```
180
+
181
+ ### 3. Code Blocks and Tables
182
+
183
+ ```python
184
+ import paperforge_notes as pn
185
+
186
+ # Syntax-highlighted code block with Dracula theme
187
+ pn.code_block("""
188
+ public static void main(String[] args) {
189
+ System.out.println("Hello, World!");
190
+ }
191
+ """, lang="java", theme=pn.DRACULA)
192
+
193
+ # Multi-column information tables with custom column widths
194
+ pn.info_table(
195
+ ["Algorithm", "Best Case", "Worst Case"],
196
+ [
197
+ ["Quick Sort", "O(N log N)", "O(N^2)"],
198
+ ["Merge Sort", "O(N log N)", "O(N log N)"],
199
+ ],
200
+ col_widths=["40%", "30%", "30%"]
201
+ )
202
+ ```
203
+
204
+ ### 4. Images (Local & Remote)
205
+
206
+ You can render images from local paths or remote URLs directly into your document. Remote URLs are automatically downloaded and cached locally in `.paperforge_cache/images` for offline access and speed.
207
+
208
+ #### Sizing and Hyperlink Example
209
+
210
+ ```python
211
+ import paperforge_notes as pn
212
+
213
+ # Local image with caption and hyperlink
214
+ pn.image(
215
+ "asset_images/von_neumann.png",
216
+ caption="Fig 1: Von Neumann Architecture (Local)",
217
+ link="https://en.wikipedia.org/wiki/Von_Neumann_architecture"
218
+ )
219
+
220
+ # Remote image from a URL (will be auto-cached) with specific size
221
+ pn.image(
222
+ "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png",
223
+ caption="Fig 2: Google Logo (Remote)",
224
+ width=200,
225
+ height=68,
226
+ link="https://www.google.com"
227
+ )
228
+ ```
229
+
230
+ #### Fallbacks & Warning Placeholders
231
+
232
+ The image system includes two layers of fallback protection:
233
+ 1. **User-defined Fallbacks**: You can supply one or more fallback image sources via the `fallbacks` parameter.
234
+ 2. **Default Placeholder Box**: If all sources fail, the compiler renders a styled warning placeholder box.
235
+
236
+ ```python
237
+ import paperforge_notes as pn
238
+
239
+ pn.image(
240
+ "https://invalid-domain.com/nonexistent_image.png",
241
+ fallbacks=[
242
+ "https://alternative-invalid.com/backup.jpg",
243
+ "asset_images/von_neumann.png"
244
+ ],
245
+ caption="Von Neumann (Loaded via Fallbacks)"
246
+ )
247
+ ```
248
+
249
+ ### 5. LaTeX-like Features & References
250
+
251
+ ```python
252
+ # Label a section
253
+ pn.section("Advanced Sorting")
254
+ pn.label("sec_adv_sort")
255
+
256
+ # Add a footnote and index entry
257
+ pn.body(f"We can use random pivots{pn.footnote('A random pivot yields O(N log N) average complexity with high probability.')}.")
258
+ pn.index_entry("Randomized Quick Sort")
259
+
260
+ # Cross-reference
261
+ pn.body(f"For details on advanced sorting, see the section on Page {pn.ref('sec_adv_sort')}.")
262
+
263
+ # Print the generated index table
264
+ pn.print_index()
265
+ ```
266
+
267
+ ### 6. Advanced Styling, Custom Layouts & Overrides
268
+
269
+ ```python
270
+ import paperforge_notes as pn
271
+
272
+ # Custom Print Theme with Double Page Borders
273
+ print_theme = pn.LIGHT.copy_with(
274
+ name="Print Light",
275
+ body_font="Times-Roman",
276
+ heading_font="Times-Bold",
277
+ size_body=10.0,
278
+ size_question=12.0,
279
+ double_page_border=True,
280
+ page_border_margin=15.0,
281
+ page_border_gap=3.0,
282
+ plain_questions=True,
283
+ )
284
+ pn.set_theme(print_theme)
285
+
286
+ # Three-Column Running Headers & Footers
287
+ pn.set_global_header(
288
+ left="Indian Constitution Notes",
289
+ center="Semester – IV",
290
+ right="Session-Jan-June 2025"
291
+ )
292
+ pn.set_global_footer(
293
+ left="Name: Bharat Dangi",
294
+ center="Enrollment no: 0101IT241013",
295
+ show_page_num=True
296
+ )
297
+
298
+ # Suppression of Headers/Footers on Specific Pages
299
+ pn.bookmark("Cover Page")
300
+ pn.suppress_header(page_only=True)
301
+ pn.suppress_footer(page_only=True)
302
+ pn.cover_card("Indian Constitution", "Unit 1: Basics")
303
+ pn.br()
304
+
305
+ # Multi-Page Grid-Based INDEX / Table of Contents
306
+ pn.toc(style="index", col_widths=["10%", "29%", "10%", "16%", "14%", "7%", "14%"])
307
+
308
+ # Component-Level Typography and Color Overrides
309
+ pn.qbox(
310
+ "What is Constitutionalism?",
311
+ font_name="Times-Bold",
312
+ font_size=12,
313
+ text_color="#ff0000",
314
+ bg_color="#ffffff",
315
+ border_color="#000000"
316
+ )
317
+ pn.body("Constitutionalism refers to the limitation of government by law.")
318
+ ```
319
+
320
+ ### 7. Textbook Callouts & Study Helpers
321
+
322
+ ```python
323
+ import paperforge_notes as pn
324
+
325
+ pn.warning("High voltage! Do not touch or operate this equipment without safety gear.")
326
+ pn.important("Amdahl's Law defines the theoretical speedup in latency of execution.")
327
+ pn.exam("Amdahl's law is a frequent question on computer organization exams!")
328
+ pn.theorem("For any right-angled triangle, a^2 + b^2 = c^2.")
329
+ pn.proof("By constructing four identical triangles around a square...")
330
+
331
+ pn.question("State the difference between latency and throughput.")
332
+ pn.answer("Latency is the time delay for a single task; throughput is tasks per unit time.")
333
+ pn.qbox("Draw and explain the Von Neumann architecture.")
334
+
335
+ pn.mcq(
336
+ "Which algorithm is quickest in the worst-case scenario?",
337
+ ["Quick Sort", "Bubble Sort", "Merge Sort", "Insertion Sort"],
338
+ correct_index=2
339
+ )
340
+
341
+ pn.revision_card("Key Metrics", [
342
+ "Average Latency",
343
+ "Tail Latency (p99)",
344
+ "Throughput",
345
+ "Resource Utilization"
346
+ ])
347
+
348
+ pn.flashcard("Von Neumann Bottleneck", "The throughput limitation between CPU and memory.")
349
+ ```
350
+
351
+ ### 8. Frame and Packet Formats
352
+
353
+ ```python
354
+ import paperforge_notes as pn
355
+
356
+ pn.frame_format(
357
+ "Ethernet Frame Structure",
358
+ [
359
+ ("PREAMBLE", "7B"),
360
+ ("SFD", "1B"),
361
+ ("DEST MAC", "6B"),
362
+ ("SRC MAC", "6B"),
363
+ ("TYPE", "2B"),
364
+ ("PAYLOAD", "46-1500B"),
365
+ ("FCS", "4B"),
366
+ ]
367
+ )
368
+
369
+ pn.packet_format(
370
+ "IPv4 Header Format",
371
+ [
372
+ ("Version", 4),
373
+ ("IHL", 4),
374
+ ("DSCP", 6),
375
+ ("ECN", 2),
376
+ ("Total Length", 16),
377
+ ("Identification", 16),
378
+ ("Flags", 3),
379
+ ("Fragment Offset", 13),
380
+ ("TTL", 8),
381
+ ("Protocol", 8),
382
+ ("Header Checksum", 16),
383
+ ("Source IP Address", 32),
384
+ ("Destination IP Address", 32),
385
+ ],
386
+ bit_ruler=True
387
+ )
388
+ ```
389
+
390
+ ---
391
+
392
+ ## 💻 Markdown CLI Compiler
393
+
394
+ You can compile markdown notes files directly to PDF via the command line interface using either `paperforge` or `pdfnotes`:
395
+
396
+ ```bash
397
+ paperforge input.md --output output.pdf --theme catppuccin-mocha
398
+ ```
399
+
400
+ ### Options:
401
+ * `input`: Path to input markdown file.
402
+ * `-o, --output`: Custom output path (defaults to input path with `.pdf` extension).
403
+ * `-t, --theme`: Theme name (default: `dark`).
404
+ * `--title`: Custom document title.
405
+ * `--author`: Custom document author.
406
+
407
+ ### Supported Themes:
408
+ * `dark` (default)
409
+ * `light`
410
+ * `ocean-dark`
411
+ * `forest-dark`
412
+ * `sunset-dark`
413
+ * `midnight-dark`
414
+ * `ocean-light`
415
+ * `sepia`
416
+ * `catppuccin-latte`
417
+ * `catppuccin-mocha`
418
+
419
+ ### Alert Boxes Mapping:
420
+ GitHub-style alert blocks are parsed and compiled automatically:
421
+ * `> [!NOTE]` → Yellow note box (via `pn.note`)
422
+ * `> [!TIP]` → Green exam-tip box (via `pn.tip`)
423
+ * `> [!WARNING]` / `> [!CAUTION]` → Yellow-bordered container box (via `pn.highlight`)
424
+
425
+ ### Embedded Diagrams Syntax:
426
+ You can embed diagrams inside markdown using simple text DSL blocks:
427
+
428
+ ```markdown
429
+ ```flowchart
430
+ width = 400
431
+ height = 200
432
+ caption = Fig 1: Basic Process Flow
433
+ direction = LR
434
+ scale_factor = 1.0
435
+ terminal start "START"
436
+ process step "Compute Value"
437
+ terminal end "END"
438
+
439
+ edge start step
440
+ edge step end
441
+ ```
442
+ ```
443
+
444
+ *Supported diagram block types:* `flowchart`, `sequence`, `layeredstack`, `schema`/`er`, `git`, `architecture`/`arch`, `c4`/`c4container`, `aws`/`cloud`. (Other diagram types like `classdiagram` or `statemachine` must be compiled using Python script).
445
+
446
+ ---
447
+
448
+ ## 📝 Diagram Integration & Static Type Checking
449
+
450
+ When integrating diagrams created with `paperforge_diagrams` into a notes document, always use `pn.add(diagram.as_flowable())` instead of manipulating the internal `story` list directly.
451
+
452
+ ### Resolving Pyright / Pylance Warnings
453
+ Static type checkers (like Pyright or Pylance in VS Code) might flag a type mismatch warning when passing a diagram list to `add()` if the signature is not correctly handled:
454
+ > `Argument of type "list[Unknown]" cannot be assigned to parameter "x" of type "Flowable" in function "add"`
455
+
456
+ This happens because `as_flowable()` returns a `list[Flowable]` (which packages the drawing flowable along with its optional caption Paragraph flowable) rather than a single `Flowable`.
457
+
458
+ **Solution:**
459
+ The `pn.add()` API accepts a union of a single flowable or a list of flowables and flattens them automatically:
460
+ ```python
461
+ def add(x: Flowable | list[Flowable] | tuple[Flowable, ...]) -> None:
462
+ ```
463
+
464
+ ---
465
+
466
+ ## 📋 Requirements & License
467
+
468
+ * **Python** >= 3.11
469
+ * **reportlab** >= 4.5.1
470
+ * **pygments** >= 2.20.0
471
+ * **paperforge-diagrams** >= 0.1.0
472
+
473
+ Optional (extended features — install with `[full]`):
474
+ * **pymupdf** >= 1.25.0 (PPTX export, document splitting)
475
+ * **genanki** >= 0.13.1 (Anki `.apkg` export)
476
+
477
+ Licensed under the **MIT License**.