Markdown to PDF Converter
A browser-only markdown editor with live preview and PDF export capabilities. Built from scratch with a custom markdown parser (no external markdown libraries). No server required - just open the HTML file in your browser!
Features
- ✅ Custom Markdown Parser - Built from scratch without external libraries
Quick Start
Prerequisites
- Just a modern web browser! (Chrome, Firefox, Safari, Edge)
Installation & Usage
Method 1: Direct Open (Easiest)
1. Download or clone this repository
82-markdown-to-pdf folder
3. Double-click index.html or right-click and choose "Open with" → your browser
4. Start editing! ✨Method 2: Open from Browser
1. Open your browser
2. Press Ctrl+O (or Cmd+O on Mac)
3. Navigate to 82-markdown-to-pdf/index.html
4. Select and open
Method 3: Drag and Drop
1. Open your browser
2. Drag index.html onto the browser window
3. Start editing!
Optional - Using a Server (for development)
If you prefer to use a server:
cd 82-markdown-to-pdfPython
python3 -m http.server 8000Or use the included app.py
python3 app.pyNode.js (if you have it)
npx http-server -p 8000
Then open http://localhost:8000
But remember: The server is completely optional! The editor works perfectly without it.
Usage
Basic Editing
1. Type markdown in the left editor pane 2. See preview in the right pane (updates automatically) 3. Use toolbar for quick formatting 4. Content auto-saves to browser storage
Formatting Toolbar
- B - Bold (text)
text) code ))))Keyboard Shortcuts
| Shortcut | Action |
| Bold selected text |
| Ctrl/Cmd + I | Italic selected text |
| Ctrl/Cmd + K | Insert link |
| Ctrl/Cmd + E | Inline code |
| Ctrl/Cmd + S | Save (also auto-saves) |
| Ctrl/Cmd + P | Export to PDF |Customization
1. Click ⚙️ Settings button
2. Customize:
- Font family (Serif, Sans-serif, Monospace, etc.)
- Font sizes for body and headings (H1-H3)
- Colors (background, text, headings, links)
3. Or choose a preset theme:
- Default - Clean, GitHub-style
- Dark - Dark mode with bright accents
- Minimal - Clean and simple
- Classic Serif - Traditional book-style
Settings are saved automatically.
Exporting to PDF
1. Click 📄 Export PDF button (or press
Ctrl/Cmd + P)
2. Browser print dialog opens
3. Select "Save as PDF" as destination
4. Choose options:
- Page size (A4, Letter, etc.)
- Margins
- Headers/footers
5. Click "Save"The PDF will match your preview exactly, including custom styling.
Supported Markdown Syntax
Headers
Heading 1
Heading 2
Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
Emphasis
italic or _italic_
bold or __bold__
bold italic
~~strikethrough~~
Lists
Unordered:
- Item 1
Item 2
- Nested item
Ordered:
1. First item
2. Second item
3. Third item
Links and Images
Link text
!Alt text
Code
Inline:
Use inline code for short snippets
Blocks:
python
def hello():
print("Hello, World!")
Syntax highlighting class is added (language-python) but coloring requires external CSS library.
Blockquotes
> This is a blockquote
> Multiple lines supported
Tables
| Header 1 | Header 2 | Header 3 |
|----------|:--------:|---------:|
| Left | Center | Right |
| Cell | Cell | Cell |
Alignment supported:
|----------| - Left (default)
|:--------:| - Center
|---------:| - RightHorizontal Rules
---
*
___
Architecture
Browser-Only Design
This application is completely client-side - no server required!
Main File:
index.html (40KB standalone file)
Contains all HTML, CSS, and JavaScript inline
Works by simply opening in a browser
No build process needed
No dependencies to installHow It Works:
1. Open index.html in any modern browser
2. JavaScript parser runs in browser
3. Content saves to browser LocalStorage
4. PDF export uses browser's print functionalityCustom Markdown Parser
The parser is built from scratch with no external libraries:
JavaScript version (included in
index.html)
Client-side parsing for live preview
Regex-based pattern matching
Block-level parsing (headers, lists, code blocks, tables)
Inline parsing (bold, italic, links, code)
HTML escaping for securityOptional Python version (
markdown_parser.py)
For server-side scenarios if needed
Same logic as JavaScript version
Not required for browser-only usageParsing Strategy:
1. Tokenization - Split markdown into lines
2. Block Detection - Identify block elements (headers, lists, etc.)
3. Inline Processing - Process emphasis, links within blocks
4. HTML Generation - Convert to HTML elementsFile Structure
82-markdown-to-pdf/
├── index.html # ⭐ Main file - open this in browser!
├── app.py # Optional: Python web server
├── markdown_parser.py # Optional: Python parser
├── templates/
│ └── index.html # Main application HTML
├── static/
│ ├── css/
│ │ └── styles.css # Application styles
│ └── js/
│ ├── parser.js # Markdown parser (JavaScript)
│ └── app.js # Application logic
├── docs/
│ └── implementation.md # Technical documentation
└── README.md # This file
Technologies Used
Frontend:
HTML5
CSS3 (Grid, Flexbox, Animations)
Vanilla JavaScript (ES6+)
No external libraries (jQuery, React, etc.)Backend:
Python 3
Built-in http.server module
No external dependenciesWhy No Libraries?
This project demonstrates building core functionality from scratch:
Custom markdown parsing (no marked, markdown-it, etc.)
No CSS frameworks (Bootstrap, Tailwind)
No JavaScript frameworks (React, Vue)
Minimal dependencies (educational purpose)Implementation Highlights
Real-Time Preview
markdownEditor.addEventListener('input', () => {
const markdown = markdownEditor.value;
const html = parser.parse(markdown);
preview.innerHTML = html;
applyCustomStyles();
});
Custom Styling
Styles are dynamically generated and applied:
const css =.preview-content { font-family: ${settings.fontFamily}; font-size: ${settings.bodySize}px; color: ${settings.textColor}; };
PDF Export
Uses browser's built-in print functionality:
function exportPDF() {
// Apply print-specific CSS
const printStyles = generatePrintCSS();
document.head.appendChild(printStyle); // Trigger print dialog
window.print();
}
Print CSS ensures the PDF matches the preview.
Browser Compatibility
Tested on:
Features used:
Limitations
Current Limitations
1. Tables - Basic support (no advanced features like colspan)
Not Implemented (Bonus Features)
These were listed as "Going Further" in the challenge:
- Export as HTML (could be added easily)
Development
Project Structure
markdown_parser.py:
classstatic/js/parser.js:
static/js/app.js:
Adding Features
To add new markdown syntax:
1. Add pattern detection in parse() method
)
3. Add inline processing if needed
4. Update both Python and JavaScript parsersTo add new settings:
1. Add to
state.settings in app.js
2. Add form input in index.html
3. Update generateCustomCSS() to use new setting
4. Add to preset themesTesting
Test with various markdown files:
Create test file
cat > test.md << 'EOF'
Test Document
This tests bold, italic, and
code.Lists
- Item 1
Item 2| Table | Header |
|-------|--------|
| Cell | Cell |
EOFOpen in editor, paste content, verify rendering
Troubleshooting
Application won't load
Check:
Python is installed: python3 --version
Server is running: python3 app.py`
Preview not updating
Solutions:
PDF export not working
Solutions:
Styles not applying to PDF
Cause: Print CSS might not be loading
Solution:
Performance
Tested with:
Optimizations:
Security
HTML Escaping:
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
LocalStorage:
License
MIT License - Feel free to use, modify, and distribute.
Acknowledgments
- Challenge from CodingChallenges.fyi
Contributing
Suggestions and improvements welcome!
Ideas for contributions:
Author
Created as part of the Coding Challenges series.
---
Happy Markdown Editing! 📝