A high-density, web-based Markdown editor and pagination engine designed to transform raw Markdown into perfectly formatted, multi-column A4 printable cheat sheets and PDFs.
The 2-in-1 A4 Markdown PDF Generator is a pure client-side web application built for students, developers, engineers, and researchers who need to generate compact, highly organized cheat sheets, revision notes, and reference guides.
Standard Markdown parsers and print tools suffer from awkward page breaks, orphaned headings, ugly overflow, and rigid single-column layouts. This project solves those problems by implementing a custom DOM-based virtual pagination and height measurement engine that automatically splits content across physical A4 sheets in real time.
Whether you want a traditional 1-column portrait document, a compact 2-in-1 landscape cheat sheet, or an ultra-dense 3-in-1 layout, this application handles paragraph splitting, code block line wrapping, list item unpacking, LaTeX math, diagrams, syntax highlighting, and orphan heading prevention automatically.
- 1 Column (1-in-1): Standard A4 Portrait sheet (210mm x 297mm).
- 2 Columns (2-in-1): A4 Landscape sheet (297mm x 210mm) divided into two logical portrait column pages. Perfect for exam cheat sheets.
- 3 Columns (3-in-1): A4 Landscape sheet divided into three high-density logical columns for maximum information packing.
- Pixel-Perfect Heights: Uses a hidden DOM measuring container (
#measuring-container) to dynamically calculate column heights before rendering into A4 sheets. - Paragraph Word-Splitting: Breaks paragraphs at precise word boundaries when they cross column/page limits.
- Code Block Line-Splitting: Splits
<pre><code>blocks line-by-line across column boundaries without cutting code in half. - List Item Unpacking: Unpacks unordered (
<ul>) and ordered (<ol>) lists into individual items so long lists flow seamlessly across page columns while preserving list numbering. - Blockquote Splitting: Intelligently breaks blockquotes into upper and lower halves.
- Toggleable Neat Layout feature automatically detects section headers (
<h1>–<h6>,<hr>, or key-value label lines ending with:) at the very bottom of a column page. - If a heading is left without sufficient content below it, the engine automatically pushes the heading to the top of the next column page, preventing awkward orphan titles.
- LaTeX Math (KaTeX): Full inline (
$E=mc^2$) and block ($$\sum_{i=1}^n i$$) rendering. - Diagrams & Flowcharts (Mermaid.js): Renders code blocks tagged
mermaidinto sharp SVG diagrams. - Syntax Highlighting (Highlight.js): Code highlighting styled for clean black-and-white or color printing (GitHub style).
- GitHub-Style Callout Alerts: Supports
> [!NOTE],> [!TIP],> [!IMPORTANT],> [!WARNING], and> [!CAUTION]. - Extended Markdown Syntax:
- Highlights:
==highlighted text== - Subscripts & Superscripts:
~subscript~and^superscript^ - Emojis:
:smile:,:rocket:,:star:,:check:,:fire:,:bulb:, etc. - Footnotes:
[^1]with automatic bottom reference rendering. - Definition Lists:
: definitionformat. - Abbreviations:
*[ABBR]: Full Title.
- Highlights:
- Flexible Font Sizing: Fine-tune font sizes from 6px to 16px (in 0.5px increments) with instant re-pagination.
- Zoom Controls: Zoom In (
+), Zoom Out (-), and Auto-Fit Page (Fit Page), as well asCtrl+ Mouse Wheel zooming. - Page Numbering: Toggleable page number footers on each column page with reserved height to maintain stable text alignment.
- Mobile-Responsive Dual-Pane UI: Split view for desktop; tabbed switching (Editor vs Preview) for mobile devices.
- Integrated Print / Save PDF trigger invoking
window.print(). - Custom
@media printrules hide editor toolbars, reset margins, and configure native@page { size: A4 landscape; margin: 0; }or@page { size: A4 portrait; margin: 0; }for seamless PDF exports.
| Layer | Technology / Library | Purpose |
|---|---|---|
| Structure | HTML5 | Application shell, controls toolbar, dual-pane flex containers |
| Styling | Vanilla CSS3 | Modular CSS variables, flexbox/grid layout, A4 paper simulation, print media queries |
| Logic Engine | Vanilla JavaScript (ES6+) | Preprocessing, DOM measurement, node splitting, dynamic sheet rendering |
| Markdown Parser | Marked.js | High-performance Markdown to HTML conversion |
| Math Renderer | KaTeX | Fast LaTeX math parsing and HTML/SVG rendering |
| Diagram Engine | Mermaid.js | Flowcharts, sequence diagrams, and architecture visualizations |
| Code Highlighting | Highlight.js | Code block syntax highlighting |
clever-borg/
├── index.html # Main application layout, toolbar controls, CDN dependencies
├── app.js # Engine core: preprocessor, layout measurement, pagination & print logic
├── style.css # Responsive styling system, A4 screen simulation & @media print styles
├── sample.md # Comprehensive default study guide sample (demonstrating tables, math & notes)
└── PROJECT_DESCRIPTION.md # Detailed technical and functional project description
- Input & Debounce: When the user edits text in
#markdown-inputor adjusts controls (Font Size, Columns, Neat Layout toggle), thedebouncedRender()function triggers. - Preprocessing:
preprocessMarkdown()scans for custom syntax like KaTeX math ($...$,$$...$$), highlights (==...==), subscripts, superscripts, footnotes, and abbreviations before passing tomarked.parse(). - DOM Post-Processing:
postProcessDOM()converts GitHub alert blockquotes into styled callouts, processes definition lists, highlights code snippets usinghljs, and asynchronously rendersmermaidSVG diagrams. - List Unpacking: Lists are unpacked into individual items to enable mid-list column splits while preserving numerical sequences.
- DOM Height Measurement & Node Splitting:
- Nodes are tested against
getAvailablePageHeight()inside an off-screen container. - If a node overflows,
splitParagraphNode(),splitPreNode(), orsplitBlockquoteNode()breaks the element down to the exact line or word that fits. preventOrphanschecks if trailing nodes on a page are isolated headings, carrying them over to the next page if needed.
- Nodes are tested against
- Sheet Assembly: Logical column pages are grouped into physical
div.a4-sheetcontainers according to the selected column count (1, 2, or 3) and rendered into the preview container.
- No Build Step Required: This is a pure static web app.
- Open in Browser: Simply double-click
index.htmlor open it with any web browser (Chrome, Edge, Firefox, Safari). - Local Server (Optional): Run a local static server if desired:
npx serve . - Exporting to PDF:
- Click Print / Save PDF (or press
Ctrl+P). - Select Save as PDF in the browser print dialog.
- Ensure background graphics are enabled and margins are set to None / Default.
- Click Print / Save PDF (or press
- Student Exam Cheat Sheets: Create dense 2-in-1 or 3-in-1 formula sheets and revision summaries.
- Developer Quick Reference Sheets: Printable cheat sheets for CLI commands, API endpoints, or language syntaxes.
- Meeting & Project Notes: Compact printed summaries for presentations or review sessions.
- LaTeX Math Handouts: Print-ready assignments and formula reference cards.