mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
Compare commits
7
Commits
phase-3-editor
...
v1.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7131d1a38e | ||
|
|
6d3813e5e9 | ||
|
|
bfe362245d | ||
|
|
5c5cffed83 | ||
|
|
f3e829ca63 | ||
|
|
b0a96f680a | ||
|
|
a6da95b057 |
@@ -1,189 +0,0 @@
|
|||||||
# Pan Converter
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
Pan Converter is a cross-platform desktop application for editing and converting Markdown files using Pandoc. It features a rich markdown editor with live preview, multiple themes, and support for exporting to various formats.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
- **Markdown Editor**: Full-featured editor with syntax highlighting
|
|
||||||
- **Live Preview**: Real-time preview of your markdown content
|
|
||||||
- **Multiple Themes**: Light, Dark, Solarized, Monokai, and GitHub themes
|
|
||||||
- **Format Conversion**: Export to HTML, PDF, DOCX, LaTeX, RTF, ODT, and EPUB using Pandoc
|
|
||||||
- **Cross-Platform**: Runs on Windows, macOS, and Linux
|
|
||||||
- **Auto-Save**: Automatic saving every 30 seconds
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
- **Pandoc**: Must be installed on the system for export functionality
|
|
||||||
- Ubuntu/Debian: `sudo apt-get install pandoc`
|
|
||||||
- macOS: `brew install pandoc`
|
|
||||||
- Windows: Download from https://pandoc.org/installing.html
|
|
||||||
|
|
||||||
## Development Setup
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
- Node.js (v14 or higher)
|
|
||||||
- npm or yarn
|
|
||||||
- Pandoc (for export features)
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
```bash
|
|
||||||
# Clone the repository
|
|
||||||
git clone <repository-url>
|
|
||||||
cd pan-converter
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
npm install
|
|
||||||
|
|
||||||
# Generate icons
|
|
||||||
npm run generate-icons
|
|
||||||
|
|
||||||
# Start the application
|
|
||||||
npm start
|
|
||||||
```
|
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
### Build for Current Platform
|
|
||||||
```bash
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Build for Specific Platforms
|
|
||||||
```bash
|
|
||||||
# Windows
|
|
||||||
npm run build:win
|
|
||||||
|
|
||||||
# macOS
|
|
||||||
npm run build:mac
|
|
||||||
|
|
||||||
# Linux (generates .deb, .AppImage, and .snap)
|
|
||||||
npm run build:linux
|
|
||||||
```
|
|
||||||
|
|
||||||
### Build for All Platforms
|
|
||||||
```bash
|
|
||||||
npm run dist:all
|
|
||||||
```
|
|
||||||
|
|
||||||
## Project Structure
|
|
||||||
```
|
|
||||||
pan-converter/
|
|
||||||
├── src/
|
|
||||||
│ ├── main.js # Main process
|
|
||||||
│ ├── renderer.js # Renderer process
|
|
||||||
│ ├── index.html # Main window HTML
|
|
||||||
│ └── styles.css # Application styles
|
|
||||||
├── assets/
|
|
||||||
│ ├── icon.svg # Source icon
|
|
||||||
│ └── icon.png # Generated icons
|
|
||||||
├── scripts/
|
|
||||||
│ └── generate-icons.js # Icon generation script
|
|
||||||
├── package.json # Project configuration
|
|
||||||
└── CLAUDE.md # This file
|
|
||||||
```
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
### Main Process (`src/main.js`)
|
|
||||||
- Manages application lifecycle
|
|
||||||
- Creates and manages windows
|
|
||||||
- Handles file operations
|
|
||||||
- Manages menu bar
|
|
||||||
- Communicates with renderer via IPC
|
|
||||||
|
|
||||||
### Renderer Process (`src/renderer.js`)
|
|
||||||
- Handles UI interactions
|
|
||||||
- Manages editor state
|
|
||||||
- Renders markdown preview
|
|
||||||
- Handles theme switching
|
|
||||||
- Communicates with main process via IPC
|
|
||||||
|
|
||||||
### Key Libraries
|
|
||||||
- **Electron**: Desktop application framework
|
|
||||||
- **marked**: Markdown parsing
|
|
||||||
- **highlight.js**: Syntax highlighting
|
|
||||||
- **DOMPurify**: HTML sanitization
|
|
||||||
- **electron-store**: Persistent storage
|
|
||||||
- **electron-builder**: Application packaging
|
|
||||||
|
|
||||||
## Features Implementation
|
|
||||||
|
|
||||||
### Markdown Editor
|
|
||||||
- Uses native textarea with custom styling
|
|
||||||
- Supports common markdown shortcuts via toolbar
|
|
||||||
- Tab key inserts 4 spaces for code indentation
|
|
||||||
- Auto-save every 30 seconds when content changes
|
|
||||||
|
|
||||||
### Live Preview
|
|
||||||
- Updates in real-time as you type
|
|
||||||
- Sanitized HTML output for security
|
|
||||||
- Syntax highlighting for code blocks
|
|
||||||
- GitHub-flavored markdown support
|
|
||||||
|
|
||||||
### Theme System
|
|
||||||
- Themes stored in user preferences
|
|
||||||
- Applied via CSS classes on body element
|
|
||||||
- Persists across application restarts
|
|
||||||
- Five built-in themes
|
|
||||||
|
|
||||||
### Export System
|
|
||||||
- Uses Pandoc command-line tool
|
|
||||||
- Supports multiple output formats
|
|
||||||
- Maintains original file structure
|
|
||||||
- Shows error messages if Pandoc not installed
|
|
||||||
|
|
||||||
## Platform-Specific Branches
|
|
||||||
|
|
||||||
The repository maintains separate branches for platform-specific customizations:
|
|
||||||
- `master`: Main development branch
|
|
||||||
- `linux`: Linux-specific configurations
|
|
||||||
- `macos`: macOS-specific configurations
|
|
||||||
- `windows`: Windows-specific configurations
|
|
||||||
|
|
||||||
## Debian Package
|
|
||||||
|
|
||||||
The application can be built as a `.deb` package for Debian-based systems:
|
|
||||||
```bash
|
|
||||||
npm run build:linux
|
|
||||||
```
|
|
||||||
|
|
||||||
The generated `.deb` file will:
|
|
||||||
- Install to `/opt/pan-converter`
|
|
||||||
- Create desktop entry for application menu
|
|
||||||
- Set up proper file associations
|
|
||||||
- Declare Pandoc as dependency
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
### Manual Testing
|
|
||||||
1. File Operations: New, Open, Save, Save As
|
|
||||||
2. Editor Features: Bold, Italic, Headings, Links, Code, Lists, Quotes
|
|
||||||
3. Preview Toggle: Show/hide preview pane
|
|
||||||
4. Theme Switching: Test all five themes
|
|
||||||
5. Export Functions: Test each export format
|
|
||||||
6. Auto-save: Verify 30-second auto-save works
|
|
||||||
|
|
||||||
### Platform Testing
|
|
||||||
Test on:
|
|
||||||
- Windows 10/11
|
|
||||||
- macOS 11+ (Big Sur and later)
|
|
||||||
- Ubuntu 20.04+, Debian 11+
|
|
||||||
|
|
||||||
## Known Issues
|
|
||||||
- ICO and ICNS icons need manual conversion from PNG
|
|
||||||
- Pandoc must be installed separately
|
|
||||||
- Large files may cause performance issues
|
|
||||||
|
|
||||||
## Future Enhancements
|
|
||||||
- [ ] Add spell checking
|
|
||||||
- [ ] Implement find and replace
|
|
||||||
- [ ] Add custom CSS for preview
|
|
||||||
- [ ] Support for markdown extensions
|
|
||||||
- [ ] Plugin system for custom exporters
|
|
||||||
- [ ] Cloud sync capabilities
|
|
||||||
- [ ] Collaborative editing
|
|
||||||
|
|
||||||
## License
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
## Support
|
|
||||||
For issues or feature requests, please open an issue on the GitHub repository.
|
|
||||||
@@ -6,24 +6,47 @@ A cross-platform Markdown editor and converter powered by Pandoc.
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- 📝 **Rich Markdown Editor** - Full-featured editor with syntax highlighting
|
### ✨ Advanced Markdown Editor
|
||||||
- 👁️ **Live Preview** - See your markdown rendered in real-time
|
- 📝 **Rich Text Editor** - Full-featured editor with syntax highlighting and comprehensive toolbar
|
||||||
|
- 🔍 **Find & Replace** - Powerful search and replace with match highlighting and navigation
|
||||||
|
- 🔢 **Line Numbers** - Toggle line numbers for easier code editing and navigation
|
||||||
|
- ↩️ **Smart Auto-Indentation** - Automatic list continuation and intelligent indentation
|
||||||
|
- ⏪ **Undo/Redo** - Full undo/redo support with keyboard shortcuts
|
||||||
|
- ⌨️ **Advanced Shortcuts** - Tab indentation, line selection, and smart text formatting
|
||||||
|
|
||||||
|
### 🎨 Themes & Interface
|
||||||
|
- 👁️ **Live Preview** - See your markdown rendered in real-time with synchronized scrolling
|
||||||
- 🎨 **Multiple Themes** - Choose from Light, Dark, Solarized, Monokai, or GitHub themes
|
- 🎨 **Multiple Themes** - Choose from Light, Dark, Solarized, Monokai, or GitHub themes
|
||||||
- 📤 **Export to Multiple Formats** - Convert to HTML, PDF, DOCX, LaTeX, RTF, ODT, and EPUB
|
- 💾 **Auto-Save** - Never lose your work with automatic saving every 30 seconds
|
||||||
- 💾 **Auto-Save** - Never lose your work with automatic saving
|
|
||||||
- 🖥️ **Cross-Platform** - Works on Windows, macOS, and Linux
|
### 📤 Export & Conversion
|
||||||
|
- 📄 **Document Export** - Convert to HTML, PDF, DOCX, LaTeX, RTF, ODT, EPUB, PowerPoint (PPTX), and OpenDocument Presentation (ODP)
|
||||||
|
- 📊 **Spreadsheet Export** - Export markdown tables to Excel (XLSX/XLS) and OpenDocument Spreadsheet (ODS) formats
|
||||||
|
- 📥 **Document Import & Conversion** - Import various document formats and convert between formats via Pandoc
|
||||||
|
- 📋 **Table Creation Helper** - Built-in table generator for easy markdown table creation
|
||||||
|
|
||||||
|
### 🖥️ Platform Support
|
||||||
|
- **Cross-Platform** - Works seamlessly on Windows, macOS, and Linux
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
- [Pandoc](https://pandoc.org/installing.html) must be installed for export functionality
|
- [Pandoc](https://pandoc.org/installing.html) must be installed for export functionality
|
||||||
|
- **Ubuntu/Debian**: `sudo apt-get install pandoc`
|
||||||
|
- **macOS**: `brew install pandoc`
|
||||||
|
- **Windows**: Download installer from Pandoc website
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
Download the latest release for your platform from the [Releases](https://github.com/yourusername/pan-converter/releases) page.
|
Download the latest release for your platform from the [Releases](https://github.com/amitwh/pan-converter/releases) page.
|
||||||
|
|
||||||
|
#### Linux
|
||||||
|
- **AppImage**: `PanConverter-1.2.0.AppImage` (universal, may require `--no-sandbox` flag)
|
||||||
|
- **Debian Package**: `pan-converter_1.2.0_amd64.deb`
|
||||||
|
- **Snap Package**: `pan-converter_1.2.0_amd64.snap`
|
||||||
|
|
||||||
### Install from Source
|
### Install from Source
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/yourusername/pan-converter.git
|
git clone https://github.com/amitwh/pan-converter.git
|
||||||
cd pan-converter
|
cd pan-converter
|
||||||
npm install
|
npm install
|
||||||
npm start
|
npm start
|
||||||
@@ -31,45 +54,99 @@ npm start
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
### Basic Workflow
|
||||||
1. **Write** - Use the editor to write your Markdown content
|
1. **Write** - Use the editor to write your Markdown content
|
||||||
2. **Preview** - Toggle the preview pane to see rendered output
|
2. **Preview** - Toggle the preview pane to see rendered output
|
||||||
3. **Theme** - Choose your preferred theme from the View menu
|
3. **Theme** - Choose your preferred theme from the View menu
|
||||||
4. **Export** - Export your document to various formats via File > Export
|
4. **Export** - Export your document to various formats
|
||||||
|
|
||||||
|
### Export Options
|
||||||
|
- **Documents**: HTML, PDF, DOCX, LaTeX, RTF, ODT, EPUB
|
||||||
|
- **Presentations**: PowerPoint (PPTX), OpenDocument Presentation (ODP)
|
||||||
|
- **Spreadsheets**: Excel (XLSX/XLS), OpenDocument Spreadsheet (ODS)
|
||||||
|
|
||||||
|
### Import & Conversion
|
||||||
|
- **Import Documents**: Convert DOCX, ODT, RTF, HTML, PDF, and presentation files to Markdown
|
||||||
|
- **Cross-Format Conversion**: Convert current file between multiple formats
|
||||||
|
- **Smart Presentation Handling**: Automatic slide-level formatting for PPTX/ODP exports
|
||||||
|
|
||||||
|
### Table Creation
|
||||||
|
- Click the table button in the toolbar
|
||||||
|
- Specify number of rows and columns
|
||||||
|
- Automatically generates properly formatted Markdown tables
|
||||||
|
|
||||||
## Keyboard Shortcuts
|
## Keyboard Shortcuts
|
||||||
|
|
||||||
|
### File Operations
|
||||||
- `Ctrl/Cmd + N` - New file
|
- `Ctrl/Cmd + N` - New file
|
||||||
- `Ctrl/Cmd + O` - Open file
|
- `Ctrl/Cmd + O` - Open file
|
||||||
- `Ctrl/Cmd + S` - Save file
|
- `Ctrl/Cmd + S` - Save file
|
||||||
- `Ctrl/Cmd + Shift + S` - Save as
|
- `Ctrl/Cmd + Shift + S` - Save as
|
||||||
|
- `Ctrl/Cmd + I` - Import document
|
||||||
|
|
||||||
|
### Editor Features
|
||||||
|
- `Ctrl/Cmd + F` - Find & Replace
|
||||||
|
- `Ctrl/Cmd + Z` - Undo
|
||||||
|
- `Ctrl/Cmd + Shift + Z` - Redo
|
||||||
|
- `Tab` - Indent lines or insert 4 spaces
|
||||||
|
- `Shift + Tab` - Outdent selected lines
|
||||||
|
- `Enter` - Auto-continue lists with proper indentation
|
||||||
|
|
||||||
|
### View & Navigation
|
||||||
- `Ctrl/Cmd + P` - Toggle preview
|
- `Ctrl/Cmd + P` - Toggle preview
|
||||||
- `Ctrl/Cmd + Enter` - Toggle preview (alternative)
|
- `Ctrl/Cmd + Enter` - Toggle preview (alternative)
|
||||||
|
- `Escape` - Close find dialog
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# Install dependencies
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# Generate icons
|
||||||
|
npm run generate-icons
|
||||||
|
|
||||||
# Build for current platform
|
# Build for current platform
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# Build for specific platform
|
# Build for specific platform
|
||||||
npm run build:win
|
npm run build:win # Windows
|
||||||
npm run build:mac
|
npm run build:mac # macOS
|
||||||
npm run build:linux
|
npm run build:linux # Linux (generates .deb, .AppImage, and .snap)
|
||||||
|
|
||||||
# Build for all platforms
|
# Build for all platforms
|
||||||
npm run dist:all
|
npm run dist:all
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Version History
|
||||||
|
|
||||||
|
- **v1.2.0** - Major editor enhancements: Find & Replace, Line Numbers, Undo/Redo, Auto-indentation, PowerPoint export, document conversion menu, table creation helper, spreadsheet export
|
||||||
|
- **v1.1.0** - Added Excel/ODS spreadsheet export, updated author information, renamed to PanConverter
|
||||||
|
- **v1.0.0** - Initial release with basic markdown editing, themes, and Pandoc export
|
||||||
|
|
||||||
|
## Known Issues
|
||||||
|
|
||||||
|
- AppImage may require `--no-sandbox` flag on some Linux systems
|
||||||
|
- Windows/Mac builds require platform-specific build environments
|
||||||
|
- Large files may cause performance issues
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
Contributions are welcome! Please feel free to submit a Pull Request to the [GitHub repository](https://github.com/amitwh/pan-converter).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT License - see LICENSE file for details
|
MIT License - see LICENSE file for details.
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
**Amit Haridas** - [amit.wh@gmail.com](mailto:amit.wh@gmail.com)
|
||||||
|
|
||||||
## Acknowledgments
|
## Acknowledgments
|
||||||
|
|
||||||
- Built with [Electron](https://www.electronjs.org/)
|
- Built with [Electron](https://www.electronjs.org/)
|
||||||
- Markdown parsing by [marked](https://marked.js.org/)
|
- Markdown parsing by [marked](https://marked.js.org/)
|
||||||
- Export functionality powered by [Pandoc](https://pandoc.org/)
|
- Export functionality powered by [Pandoc](https://pandoc.org/)
|
||||||
|
- Syntax highlighting by [highlight.js](https://highlightjs.org/)
|
||||||
|
- Spreadsheet export by [XLSX](https://www.npmjs.com/package/xlsx)
|
||||||
|
- HTML sanitization by [DOMPurify](https://www.npmjs.com/package/dompurify)
|
||||||
+11
-5
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pan-converter",
|
"name": "pan-converter",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"description": "Cross-platform Markdown editor and converter using Pandoc",
|
"description": "Cross-platform Markdown editor and converter using Pandoc",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -14,8 +14,13 @@
|
|||||||
"dist:all": "electron-builder -mwl",
|
"dist:all": "electron-builder -mwl",
|
||||||
"generate-icons": "node scripts/generate-icons.js"
|
"generate-icons": "node scripts/generate-icons.js"
|
||||||
},
|
},
|
||||||
"keywords": ["markdown", "pandoc", "converter", "editor"],
|
"keywords": [
|
||||||
"author": "Your Name",
|
"markdown",
|
||||||
|
"pandoc",
|
||||||
|
"converter",
|
||||||
|
"editor"
|
||||||
|
],
|
||||||
|
"author": "Amit Haridas <amit.wh@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^37.4.0",
|
"electron": "^37.4.0",
|
||||||
@@ -27,7 +32,8 @@
|
|||||||
"dompurify": "^3.2.6",
|
"dompurify": "^3.2.6",
|
||||||
"electron-store": "^10.1.0",
|
"electron-store": "^10.1.0",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
"marked": "^16.2.1"
|
"marked": "^16.2.1",
|
||||||
|
"xlsx": "^0.18.5"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"appId": "com.panconverter.app",
|
"appId": "com.panconverter.app",
|
||||||
@@ -63,7 +69,7 @@
|
|||||||
"pandoc"
|
"pandoc"
|
||||||
],
|
],
|
||||||
"description": "Markdown editor and converter using Pandoc",
|
"description": "Markdown editor and converter using Pandoc",
|
||||||
"maintainer": "Your Name <your.email@example.com>"
|
"maintainer": "Amit Haridas <amit.wh@gmail.com>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,29 @@
|
|||||||
<path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"></path>
|
<path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
<button id="btn-table" title="Insert Table">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
|
||||||
|
<line x1="3" y1="9" x2="21" y2="9"></line>
|
||||||
|
<line x1="3" y1="15" x2="21" y2="15"></line>
|
||||||
|
<line x1="9" y1="3" x2="9" y2="21"></line>
|
||||||
|
<line x1="15" y1="3" x2="15" y2="21"></line>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<div class="toolbar-separator"></div>
|
||||||
|
<button id="btn-find" title="Find & Replace (Ctrl+F)">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<circle cx="11" cy="11" r="8"></circle>
|
||||||
|
<path d="m21 21-4.35-4.35"></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button id="btn-line-numbers" title="Toggle Line Numbers">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<path d="M3 6h18"></path>
|
||||||
|
<path d="M3 12h18"></path>
|
||||||
|
<path d="M3 18h18"></path>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
<div class="toolbar-separator"></div>
|
<div class="toolbar-separator"></div>
|
||||||
<button id="btn-preview-toggle" title="Toggle Preview">
|
<button id="btn-preview-toggle" title="Toggle Preview">
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
@@ -68,10 +91,29 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Find & Replace Dialog -->
|
||||||
|
<div id="find-dialog" class="find-dialog hidden">
|
||||||
|
<div class="find-controls">
|
||||||
|
<input type="text" id="find-input" placeholder="Find...">
|
||||||
|
<input type="text" id="replace-input" placeholder="Replace...">
|
||||||
|
<button id="btn-find-prev" title="Previous">↑</button>
|
||||||
|
<button id="btn-find-next" title="Next">↓</button>
|
||||||
|
<button id="btn-replace" title="Replace">Replace</button>
|
||||||
|
<button id="btn-replace-all" title="Replace All">All</button>
|
||||||
|
<button id="btn-find-close" title="Close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="find-info">
|
||||||
|
<span id="find-count">0 matches</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="editor-container">
|
<div class="editor-container">
|
||||||
<div id="editor-pane" class="pane">
|
<div id="editor-pane" class="pane">
|
||||||
|
<div class="editor-wrapper">
|
||||||
|
<div id="line-numbers" class="line-numbers hidden"></div>
|
||||||
<textarea id="editor"></textarea>
|
<textarea id="editor"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div id="preview-pane" class="pane">
|
<div id="preview-pane" class="pane">
|
||||||
<div id="preview"></div>
|
<div id="preview"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+210
-5
@@ -2,6 +2,7 @@ const { app, BrowserWindow, Menu, dialog, ipcMain, shell } = require('electron')
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
const XLSX = require('xlsx');
|
||||||
|
|
||||||
// Simple storage implementation to replace electron-store
|
// Simple storage implementation to replace electron-store
|
||||||
const settingsPath = path.join(app.getPath('userData'), 'settings.json');
|
const settingsPath = path.join(app.getPath('userData'), 'settings.json');
|
||||||
@@ -84,7 +85,14 @@ function createMenu() {
|
|||||||
{ label: 'LaTeX', click: () => exportFile('latex') },
|
{ label: 'LaTeX', click: () => exportFile('latex') },
|
||||||
{ label: 'RTF', click: () => exportFile('rtf') },
|
{ label: 'RTF', click: () => exportFile('rtf') },
|
||||||
{ label: 'ODT', click: () => exportFile('odt') },
|
{ label: 'ODT', click: () => exportFile('odt') },
|
||||||
{ label: 'EPUB', click: () => exportFile('epub') }
|
{ label: 'EPUB', click: () => exportFile('epub') },
|
||||||
|
{ type: 'separator' },
|
||||||
|
{ label: 'PowerPoint (PPTX)', click: () => exportFile('pptx') },
|
||||||
|
{ label: 'OpenDocument Presentation (ODP)', click: () => exportFile('odp') },
|
||||||
|
{ type: 'separator' },
|
||||||
|
{ label: 'Excel (XLSX)', click: () => exportSpreadsheet('xlsx') },
|
||||||
|
{ label: 'Excel Legacy (XLS)', click: () => exportSpreadsheet('xls') },
|
||||||
|
{ label: 'OpenDocument Spreadsheet (ODS)', click: () => exportSpreadsheet('ods') }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
@@ -99,12 +107,44 @@ function createMenu() {
|
|||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [
|
||||||
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', role: 'undo' },
|
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', role: 'undo' },
|
||||||
{ label: 'Redo', accelerator: 'CmdOrCtrl+Y', role: 'redo' },
|
{ label: 'Redo', accelerator: 'CmdOrCtrl+Shift+Z', role: 'redo' },
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' },
|
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' },
|
||||||
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', role: 'copy' },
|
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', role: 'copy' },
|
||||||
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', role: 'paste' },
|
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', role: 'paste' },
|
||||||
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', role: 'selectAll' }
|
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', role: 'selectAll' },
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Find & Replace',
|
||||||
|
accelerator: 'CmdOrCtrl+F',
|
||||||
|
click: () => mainWindow.webContents.send('toggle-find')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Convert',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Import Document...',
|
||||||
|
accelerator: 'CmdOrCtrl+I',
|
||||||
|
click: importDocument
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Convert Current File',
|
||||||
|
submenu: [
|
||||||
|
{ label: 'To Markdown', click: () => convertToFormat('md') },
|
||||||
|
{ label: 'To HTML', click: () => convertToFormat('html') },
|
||||||
|
{ label: 'To PDF', click: () => convertToFormat('pdf') },
|
||||||
|
{ label: 'To DOCX', click: () => convertToFormat('docx') },
|
||||||
|
{ label: 'To LaTeX', click: () => convertToFormat('latex') },
|
||||||
|
{ label: 'To RTF', click: () => convertToFormat('rtf') },
|
||||||
|
{ label: 'To ODT', click: () => convertToFormat('odt') },
|
||||||
|
{ label: 'To EPUB', click: () => convertToFormat('epub') },
|
||||||
|
{ label: 'To PPTX', click: () => convertToFormat('pptx') },
|
||||||
|
{ label: 'To ODP', click: () => convertToFormat('odp') }
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -144,14 +184,14 @@ function createMenu() {
|
|||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'About PanConverter',
|
title: 'About PanConverter',
|
||||||
message: 'PanConverter',
|
message: 'PanConverter',
|
||||||
detail: 'A cross-platform Markdown editor and converter using Pandoc.\n\nVersion: 1.0.0\nLicense: MIT',
|
detail: 'A cross-platform Markdown editor and converter using Pandoc.\n\nVersion: 1.2.0\nAuthor: Amit Haridas\nEmail: amit.wh@gmail.com\nLicense: MIT\n\nFeatures:\n• Advanced markdown editing with live preview\n• Find & replace with match highlighting\n• Line numbers and auto-indentation\n• Export to multiple formats via Pandoc\n• PowerPoint & presentation export\n• Export tables to Excel/ODS spreadsheets\n• Document import & conversion\n• Table creation helper\n• Multiple themes support\n• Undo/redo functionality',
|
||||||
buttons: ['OK']
|
buttons: ['OK']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Documentation',
|
label: 'Documentation',
|
||||||
click: () => shell.openExternal('https://github.com/yourusername/pan-converter')
|
click: () => shell.openExternal('https://github.com/amitwh/pan-converter')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -223,6 +263,88 @@ function exportFile(format) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exportSpreadsheet(format) {
|
||||||
|
if (!currentFile) {
|
||||||
|
dialog.showErrorBox('Error', 'Please save the file first');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request content from renderer
|
||||||
|
mainWindow.webContents.send('get-content-for-spreadsheet', format);
|
||||||
|
}
|
||||||
|
|
||||||
|
function importDocument() {
|
||||||
|
const files = dialog.showOpenDialogSync(mainWindow, {
|
||||||
|
properties: ['openFile'],
|
||||||
|
filters: [
|
||||||
|
{ name: 'Documents', extensions: ['docx', 'odt', 'rtf', 'html', 'tex', 'epub', 'pdf'] },
|
||||||
|
{ name: 'Presentations', extensions: ['pptx', 'odp'] },
|
||||||
|
{ name: 'All Files', extensions: ['*'] }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (files && files[0]) {
|
||||||
|
const inputFile = files[0];
|
||||||
|
const outputFile = inputFile.replace(/\.[^/.]+$/, '.md');
|
||||||
|
|
||||||
|
// Convert to markdown using pandoc
|
||||||
|
const pandocCmd = `pandoc "${inputFile}" -t markdown -o "${outputFile}"`;
|
||||||
|
|
||||||
|
exec(pandocCmd, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
dialog.showErrorBox('Import Error', `Failed to import: ${error.message}\n\nMake sure Pandoc is installed.`);
|
||||||
|
} else {
|
||||||
|
// Open the converted markdown file
|
||||||
|
currentFile = outputFile;
|
||||||
|
const content = fs.readFileSync(outputFile, 'utf-8');
|
||||||
|
mainWindow.webContents.send('file-opened', { path: outputFile, content });
|
||||||
|
|
||||||
|
dialog.showMessageBox(mainWindow, {
|
||||||
|
type: 'info',
|
||||||
|
title: 'Import Complete',
|
||||||
|
message: `Document imported successfully as ${outputFile}`,
|
||||||
|
buttons: ['OK']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertToFormat(format) {
|
||||||
|
if (!currentFile) {
|
||||||
|
dialog.showErrorBox('Error', 'Please save or open a file first');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputFile = dialog.showSaveDialogSync(mainWindow, {
|
||||||
|
defaultPath: currentFile.replace(/\.[^/.]+$/, `.${format}`),
|
||||||
|
filters: [
|
||||||
|
{ name: format.toUpperCase(), extensions: [format] }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (outputFile) {
|
||||||
|
// For presentations, add slide level for better conversion
|
||||||
|
let pandocCmd = `pandoc "${currentFile}" -o "${outputFile}"`;
|
||||||
|
if (format === 'pptx' || format === 'odp') {
|
||||||
|
pandocCmd = `pandoc "${currentFile}" --slide-level=2 -o "${outputFile}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
exec(pandocCmd, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
dialog.showErrorBox('Conversion Error', `Failed to convert: ${error.message}\n\nMake sure Pandoc is installed.`);
|
||||||
|
} else {
|
||||||
|
dialog.showMessageBox(mainWindow, {
|
||||||
|
type: 'info',
|
||||||
|
title: 'Conversion Complete',
|
||||||
|
message: `File converted successfully to ${outputFile}`,
|
||||||
|
buttons: ['OK']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setTheme(theme) {
|
function setTheme(theme) {
|
||||||
store.set('theme', theme);
|
store.set('theme', theme);
|
||||||
mainWindow.webContents.send('theme-changed', theme);
|
mainWindow.webContents.send('theme-changed', theme);
|
||||||
@@ -247,6 +369,89 @@ ipcMain.on('get-theme', (event) => {
|
|||||||
event.reply('theme-changed', theme);
|
event.reply('theme-changed', theme);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.on('export-spreadsheet', (event, { content, format }) => {
|
||||||
|
const outputFile = dialog.showSaveDialogSync(mainWindow, {
|
||||||
|
defaultPath: currentFile.replace(/\.[^/.]+$/, `.${format}`),
|
||||||
|
filters: [
|
||||||
|
{ name: format.toUpperCase(), extensions: [format] }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (outputFile) {
|
||||||
|
try {
|
||||||
|
// Parse markdown content to extract tables
|
||||||
|
const tables = extractTablesFromMarkdown(content);
|
||||||
|
|
||||||
|
if (tables.length === 0) {
|
||||||
|
dialog.showErrorBox('Export Error', 'No tables found in the markdown content');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create workbook
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
|
||||||
|
tables.forEach((table, index) => {
|
||||||
|
const ws = XLSX.utils.aoa_to_sheet(table);
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, `Table ${index + 1}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Write file
|
||||||
|
XLSX.writeFile(wb, outputFile);
|
||||||
|
|
||||||
|
dialog.showMessageBox(mainWindow, {
|
||||||
|
type: 'info',
|
||||||
|
title: 'Export Complete',
|
||||||
|
message: `Spreadsheet exported successfully to ${outputFile}`,
|
||||||
|
buttons: ['OK']
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
dialog.showErrorBox('Export Error', `Failed to export: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Helper function to extract tables from markdown
|
||||||
|
function extractTablesFromMarkdown(markdown) {
|
||||||
|
const tables = [];
|
||||||
|
const lines = markdown.split('\n');
|
||||||
|
let currentTable = [];
|
||||||
|
let inTable = false;
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.includes('|')) {
|
||||||
|
if (!inTable) {
|
||||||
|
inTable = true;
|
||||||
|
currentTable = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip separator lines (|---|---|)
|
||||||
|
if (!line.match(/^\s*\|?\s*:?-+:?\s*\|/)) {
|
||||||
|
const cells = line.split('|')
|
||||||
|
.map(cell => cell.trim())
|
||||||
|
.filter(cell => cell !== '');
|
||||||
|
|
||||||
|
if (cells.length > 0) {
|
||||||
|
currentTable.push(cells);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (inTable && line.trim() === '') {
|
||||||
|
// End of table
|
||||||
|
if (currentTable.length > 0) {
|
||||||
|
tables.push(currentTable);
|
||||||
|
}
|
||||||
|
currentTable = [];
|
||||||
|
inTable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add last table if exists
|
||||||
|
if (currentTable.length > 0) {
|
||||||
|
tables.push(currentTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
|
|
||||||
app.whenReady().then(createWindow);
|
app.whenReady().then(createWindow);
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
|||||||
+382
-1
@@ -24,11 +24,22 @@ const previewPane = document.getElementById('preview-pane');
|
|||||||
const editorPane = document.getElementById('editor-pane');
|
const editorPane = document.getElementById('editor-pane');
|
||||||
const statusText = document.getElementById('status-text');
|
const statusText = document.getElementById('status-text');
|
||||||
const wordCount = document.getElementById('word-count');
|
const wordCount = document.getElementById('word-count');
|
||||||
|
const lineNumbers = document.getElementById('line-numbers');
|
||||||
|
const findDialog = document.getElementById('find-dialog');
|
||||||
|
const findInput = document.getElementById('find-input');
|
||||||
|
const replaceInput = document.getElementById('replace-input');
|
||||||
|
const findCount = document.getElementById('find-count');
|
||||||
|
|
||||||
// State
|
// State
|
||||||
let isPreviewVisible = true;
|
let isPreviewVisible = true;
|
||||||
let currentContent = '';
|
let currentContent = '';
|
||||||
let isDirty = false;
|
let isDirty = false;
|
||||||
|
let showLineNumbers = false;
|
||||||
|
let findMatches = [];
|
||||||
|
let currentMatchIndex = -1;
|
||||||
|
let undoStack = [];
|
||||||
|
let redoStack = [];
|
||||||
|
let maxUndoSize = 50;
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
@@ -60,8 +71,77 @@ document.getElementById('btn-link').addEventListener('click', () => insertMarkdo
|
|||||||
document.getElementById('btn-code').addEventListener('click', () => insertMarkdown('`', '`'));
|
document.getElementById('btn-code').addEventListener('click', () => insertMarkdown('`', '`'));
|
||||||
document.getElementById('btn-list').addEventListener('click', () => insertMarkdown('- ', ''));
|
document.getElementById('btn-list').addEventListener('click', () => insertMarkdown('- ', ''));
|
||||||
document.getElementById('btn-quote').addEventListener('click', () => insertMarkdown('> ', ''));
|
document.getElementById('btn-quote').addEventListener('click', () => insertMarkdown('> ', ''));
|
||||||
|
document.getElementById('btn-table').addEventListener('click', insertTable);
|
||||||
|
document.getElementById('btn-find').addEventListener('click', toggleFindDialog);
|
||||||
|
document.getElementById('btn-line-numbers').addEventListener('click', toggleLineNumbers);
|
||||||
document.getElementById('btn-preview-toggle').addEventListener('click', togglePreview);
|
document.getElementById('btn-preview-toggle').addEventListener('click', togglePreview);
|
||||||
|
|
||||||
|
// Find dialog handlers
|
||||||
|
document.getElementById('btn-find-close').addEventListener('click', closeFindDialog);
|
||||||
|
document.getElementById('btn-find-next').addEventListener('click', findNext);
|
||||||
|
document.getElementById('btn-find-prev').addEventListener('click', findPrev);
|
||||||
|
document.getElementById('btn-replace').addEventListener('click', replaceOne);
|
||||||
|
document.getElementById('btn-replace-all').addEventListener('click', replaceAll);
|
||||||
|
findInput.addEventListener('input', performFind);
|
||||||
|
replaceInput.addEventListener('keydown', (e) => {
|
||||||
|
if (e.key === 'Enter') replaceOne();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Table insertion function
|
||||||
|
function insertTable() {
|
||||||
|
const rows = prompt('Number of rows:', '3');
|
||||||
|
const cols = prompt('Number of columns:', '3');
|
||||||
|
|
||||||
|
if (!rows || !cols) return;
|
||||||
|
|
||||||
|
const numRows = parseInt(rows);
|
||||||
|
const numCols = parseInt(cols);
|
||||||
|
|
||||||
|
if (isNaN(numRows) || isNaN(numCols) || numRows < 1 || numCols < 1) {
|
||||||
|
alert('Please enter valid numbers for rows and columns');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let table = '\n';
|
||||||
|
|
||||||
|
// Header row
|
||||||
|
table += '|';
|
||||||
|
for (let j = 0; j < numCols; j++) {
|
||||||
|
table += ` Header ${j + 1} |`;
|
||||||
|
}
|
||||||
|
table += '\n';
|
||||||
|
|
||||||
|
// Separator row
|
||||||
|
table += '|';
|
||||||
|
for (let j = 0; j < numCols; j++) {
|
||||||
|
table += ' --- |';
|
||||||
|
}
|
||||||
|
table += '\n';
|
||||||
|
|
||||||
|
// Data rows
|
||||||
|
for (let i = 0; i < numRows; i++) {
|
||||||
|
table += '|';
|
||||||
|
for (let j = 0; j < numCols; j++) {
|
||||||
|
table += ` Cell ${i + 1}-${j + 1} |`;
|
||||||
|
}
|
||||||
|
table += '\n';
|
||||||
|
}
|
||||||
|
table += '\n';
|
||||||
|
|
||||||
|
// Insert table at cursor position
|
||||||
|
const start = editor.selectionStart;
|
||||||
|
const end = editor.selectionEnd;
|
||||||
|
|
||||||
|
editor.value = editor.value.substring(0, start) + table + editor.value.substring(end);
|
||||||
|
|
||||||
|
// Set cursor after the table
|
||||||
|
editor.selectionStart = editor.selectionEnd = start + table.length;
|
||||||
|
editor.focus();
|
||||||
|
|
||||||
|
// Trigger input event
|
||||||
|
editor.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
|
||||||
// Markdown insertion helper
|
// Markdown insertion helper
|
||||||
function insertMarkdown(before, after) {
|
function insertMarkdown(before, after) {
|
||||||
const start = editor.selectionStart;
|
const start = editor.selectionStart;
|
||||||
@@ -191,21 +271,322 @@ ipcRenderer.on('theme-changed', (event, theme) => {
|
|||||||
updateStatus(`Theme: ${theme}`);
|
updateStatus(`Theme: ${theme}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcRenderer.on('get-content-for-spreadsheet', (event, format) => {
|
||||||
|
ipcRenderer.send('export-spreadsheet', { content: editor.value, format });
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcRenderer.on('toggle-find', () => {
|
||||||
|
toggleFindDialog();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enhanced editor input handler with undo/redo and auto-indentation
|
||||||
|
editor.addEventListener('input', (e) => {
|
||||||
|
// Save state for undo
|
||||||
|
if (e.inputType !== 'historyUndo' && e.inputType !== 'historyRedo') {
|
||||||
|
pushUndo();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLineNumbers();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Push current state to undo stack
|
||||||
|
function pushUndo() {
|
||||||
|
if (undoStack.length >= maxUndoSize) {
|
||||||
|
undoStack.shift();
|
||||||
|
}
|
||||||
|
undoStack.push({
|
||||||
|
content: currentContent,
|
||||||
|
selectionStart: editor.selectionStart,
|
||||||
|
selectionEnd: editor.selectionEnd
|
||||||
|
});
|
||||||
|
redoStack = []; // Clear redo stack when new changes are made
|
||||||
|
}
|
||||||
|
|
||||||
|
// Undo function
|
||||||
|
function undo() {
|
||||||
|
if (undoStack.length > 1) {
|
||||||
|
redoStack.push(undoStack.pop());
|
||||||
|
const state = undoStack[undoStack.length - 1];
|
||||||
|
editor.value = state.content;
|
||||||
|
editor.selectionStart = state.selectionStart;
|
||||||
|
editor.selectionEnd = state.selectionEnd;
|
||||||
|
currentContent = state.content;
|
||||||
|
updatePreview();
|
||||||
|
updateWordCount();
|
||||||
|
updateLineNumbers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redo function
|
||||||
|
function redo() {
|
||||||
|
if (redoStack.length > 0) {
|
||||||
|
const state = redoStack.pop();
|
||||||
|
undoStack.push(state);
|
||||||
|
editor.value = state.content;
|
||||||
|
editor.selectionStart = state.selectionStart;
|
||||||
|
editor.selectionEnd = state.selectionEnd;
|
||||||
|
currentContent = state.content;
|
||||||
|
updatePreview();
|
||||||
|
updateWordCount();
|
||||||
|
updateLineNumbers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find & Replace functionality
|
||||||
|
function toggleFindDialog() {
|
||||||
|
if (findDialog.classList.contains('hidden')) {
|
||||||
|
findDialog.classList.remove('hidden');
|
||||||
|
findInput.focus();
|
||||||
|
if (editor.selectionStart !== editor.selectionEnd) {
|
||||||
|
findInput.value = editor.value.substring(editor.selectionStart, editor.selectionEnd);
|
||||||
|
performFind();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
closeFindDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeFindDialog() {
|
||||||
|
findDialog.classList.add('hidden');
|
||||||
|
clearHighlights();
|
||||||
|
editor.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function performFind() {
|
||||||
|
const searchText = findInput.value;
|
||||||
|
clearHighlights();
|
||||||
|
findMatches = [];
|
||||||
|
currentMatchIndex = -1;
|
||||||
|
|
||||||
|
if (!searchText) {
|
||||||
|
findCount.textContent = '0 matches';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = editor.value;
|
||||||
|
let index = 0;
|
||||||
|
while ((index = content.indexOf(searchText, index)) !== -1) {
|
||||||
|
findMatches.push(index);
|
||||||
|
index += searchText.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
findCount.textContent = `${findMatches.length} matches`;
|
||||||
|
|
||||||
|
if (findMatches.length > 0) {
|
||||||
|
currentMatchIndex = 0;
|
||||||
|
highlightMatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findNext() {
|
||||||
|
if (findMatches.length === 0) return;
|
||||||
|
currentMatchIndex = (currentMatchIndex + 1) % findMatches.length;
|
||||||
|
highlightMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
function findPrev() {
|
||||||
|
if (findMatches.length === 0) return;
|
||||||
|
currentMatchIndex = currentMatchIndex === 0 ? findMatches.length - 1 : currentMatchIndex - 1;
|
||||||
|
highlightMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
function highlightMatch() {
|
||||||
|
if (currentMatchIndex === -1 || !findMatches[currentMatchIndex]) return;
|
||||||
|
|
||||||
|
const matchStart = findMatches[currentMatchIndex];
|
||||||
|
const matchEnd = matchStart + findInput.value.length;
|
||||||
|
|
||||||
|
editor.selectionStart = matchStart;
|
||||||
|
editor.selectionEnd = matchEnd;
|
||||||
|
editor.focus();
|
||||||
|
|
||||||
|
// Scroll to match
|
||||||
|
const lineHeight = 20; // Approximate line height
|
||||||
|
const lineNumber = editor.value.substring(0, matchStart).split('\n').length;
|
||||||
|
editor.scrollTop = Math.max(0, (lineNumber - 10) * lineHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceOne() {
|
||||||
|
if (currentMatchIndex === -1 || !findMatches[currentMatchIndex]) return;
|
||||||
|
|
||||||
|
const searchText = findInput.value;
|
||||||
|
const replaceText = replaceInput.value;
|
||||||
|
const matchStart = findMatches[currentMatchIndex];
|
||||||
|
const matchEnd = matchStart + searchText.length;
|
||||||
|
|
||||||
|
editor.value = editor.value.substring(0, matchStart) +
|
||||||
|
replaceText +
|
||||||
|
editor.value.substring(matchEnd);
|
||||||
|
|
||||||
|
editor.selectionStart = matchStart;
|
||||||
|
editor.selectionEnd = matchStart + replaceText.length;
|
||||||
|
|
||||||
|
// Trigger input event
|
||||||
|
editor.dispatchEvent(new Event('input'));
|
||||||
|
|
||||||
|
// Refresh find
|
||||||
|
setTimeout(() => performFind(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceAll() {
|
||||||
|
const searchText = findInput.value;
|
||||||
|
const replaceText = replaceInput.value;
|
||||||
|
|
||||||
|
if (!searchText) return;
|
||||||
|
|
||||||
|
let content = editor.value;
|
||||||
|
let replacements = 0;
|
||||||
|
|
||||||
|
while (content.includes(searchText)) {
|
||||||
|
content = content.replace(searchText, replaceText);
|
||||||
|
replacements++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replacements > 0) {
|
||||||
|
editor.value = content;
|
||||||
|
editor.dispatchEvent(new Event('input'));
|
||||||
|
updateStatus(`Replaced ${replacements} occurrences`);
|
||||||
|
performFind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearHighlights() {
|
||||||
|
// Clear any highlights (in a real implementation, you'd remove highlight spans)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Line Numbers functionality
|
||||||
|
function toggleLineNumbers() {
|
||||||
|
showLineNumbers = !showLineNumbers;
|
||||||
|
if (showLineNumbers) {
|
||||||
|
lineNumbers.classList.remove('hidden');
|
||||||
|
updateLineNumbers();
|
||||||
|
} else {
|
||||||
|
lineNumbers.classList.add('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLineNumbers() {
|
||||||
|
if (!showLineNumbers) return;
|
||||||
|
|
||||||
|
const lines = editor.value.split('\n');
|
||||||
|
const lineNumbersHtml = lines.map((_, index) =>
|
||||||
|
`<span class="line-number">${index + 1}</span>`
|
||||||
|
).join('');
|
||||||
|
lineNumbers.innerHTML = lineNumbersHtml;
|
||||||
|
|
||||||
|
// Sync scroll
|
||||||
|
lineNumbers.scrollTop = editor.scrollTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync line numbers scroll with editor
|
||||||
|
editor.addEventListener('scroll', () => {
|
||||||
|
if (showLineNumbers) {
|
||||||
|
lineNumbers.scrollTop = editor.scrollTop;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto-indentation for lists
|
||||||
|
function handleEnterKey(e) {
|
||||||
|
const cursorPos = editor.selectionStart;
|
||||||
|
const beforeCursor = editor.value.substring(0, cursorPos);
|
||||||
|
const lines = beforeCursor.split('\n');
|
||||||
|
const currentLine = lines[lines.length - 1];
|
||||||
|
|
||||||
|
// Check for list patterns
|
||||||
|
const listMatch = currentLine.match(/^(\s*)([-*+]|\d+\.)\s/);
|
||||||
|
if (listMatch) {
|
||||||
|
e.preventDefault();
|
||||||
|
const indent = listMatch[1];
|
||||||
|
const marker = listMatch[2];
|
||||||
|
|
||||||
|
// If current line is just the marker, remove it
|
||||||
|
if (currentLine.trim() === marker) {
|
||||||
|
const lineStart = beforeCursor.lastIndexOf('\n') + 1;
|
||||||
|
editor.value = editor.value.substring(0, lineStart) +
|
||||||
|
editor.value.substring(cursorPos);
|
||||||
|
editor.selectionStart = editor.selectionEnd = lineStart;
|
||||||
|
} else {
|
||||||
|
// Continue the list
|
||||||
|
let newMarker = marker;
|
||||||
|
if (/^\d+\./.test(marker)) {
|
||||||
|
const num = parseInt(marker) + 1;
|
||||||
|
newMarker = num + '.';
|
||||||
|
}
|
||||||
|
const insertion = '\n' + indent + newMarker + ' ';
|
||||||
|
editor.value = editor.value.substring(0, cursorPos) +
|
||||||
|
insertion +
|
||||||
|
editor.value.substring(cursorPos);
|
||||||
|
editor.selectionStart = editor.selectionEnd = cursorPos + insertion.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
|
// Ctrl/Cmd + F for find
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
|
||||||
|
e.preventDefault();
|
||||||
|
toggleFindDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl/Cmd + Z for undo
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
undo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl/Cmd + Shift + Z for redo
|
||||||
|
if ((e.ctrlKey || e.metaKey) && e.key === 'z' && e.shiftKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
redo();
|
||||||
|
}
|
||||||
|
|
||||||
// Ctrl/Cmd + Enter to toggle preview
|
// Ctrl/Cmd + Enter to toggle preview
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
||||||
togglePreview();
|
togglePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tab key in editor
|
// Enhanced Tab handling in editor
|
||||||
if (e.key === 'Tab' && e.target === editor) {
|
if (e.key === 'Tab' && e.target === editor) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const start = editor.selectionStart;
|
const start = editor.selectionStart;
|
||||||
const end = editor.selectionEnd;
|
const end = editor.selectionEnd;
|
||||||
|
|
||||||
|
if (start === end) {
|
||||||
|
// Simple tab insertion
|
||||||
editor.value = editor.value.substring(0, start) + ' ' + editor.value.substring(end);
|
editor.value = editor.value.substring(0, start) + ' ' + editor.value.substring(end);
|
||||||
editor.selectionStart = editor.selectionEnd = start + 4;
|
editor.selectionStart = editor.selectionEnd = start + 4;
|
||||||
|
} else {
|
||||||
|
// Indent/outdent selected lines
|
||||||
|
const beforeSelection = editor.value.substring(0, start);
|
||||||
|
const selection = editor.value.substring(start, end);
|
||||||
|
const afterSelection = editor.value.substring(end);
|
||||||
|
|
||||||
|
const lines = selection.split('\n');
|
||||||
|
const indentedLines = e.shiftKey ?
|
||||||
|
lines.map(line => line.replace(/^ /, '')) : // Outdent
|
||||||
|
lines.map(line => ' ' + line); // Indent
|
||||||
|
|
||||||
|
const newSelection = indentedLines.join('\n');
|
||||||
|
editor.value = beforeSelection + newSelection + afterSelection;
|
||||||
|
|
||||||
|
editor.selectionStart = start;
|
||||||
|
editor.selectionEnd = start + newSelection.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enter key handling for auto-indentation
|
||||||
|
if (e.key === 'Enter' && e.target === editor) {
|
||||||
|
handleEnterKey(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escape to close find dialog
|
||||||
|
if (e.key === 'Escape' && !findDialog.classList.contains('hidden')) {
|
||||||
|
closeFindDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+136
@@ -460,3 +460,139 @@ body.theme-github .status-bar {
|
|||||||
#editor-pane.full-width {
|
#editor-pane.full-width {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Find & Replace Dialog */
|
||||||
|
.find-dialog {
|
||||||
|
position: absolute;
|
||||||
|
top: 60px;
|
||||||
|
right: 20px;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
||||||
|
z-index: 1000;
|
||||||
|
min-width: 400px;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.find-dialog.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.find-controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.find-controls input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.find-controls button {
|
||||||
|
padding: 6px 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.find-controls button:hover {
|
||||||
|
background: #e5e5e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.find-info {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #666;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Editor Wrapper with Line Numbers */
|
||||||
|
.editor-wrapper {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-numbers {
|
||||||
|
min-width: 40px;
|
||||||
|
padding: 8px 4px;
|
||||||
|
background: #f8f8f8;
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.4;
|
||||||
|
color: #666;
|
||||||
|
text-align: right;
|
||||||
|
user-select: none;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-numbers.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-numbers .line-number {
|
||||||
|
display: block;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust editor when line numbers are shown */
|
||||||
|
.editor-wrapper #editor {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Theme support for find dialog */
|
||||||
|
body.theme-dark .find-dialog {
|
||||||
|
background: #2d2d2d;
|
||||||
|
border-color: #555;
|
||||||
|
color: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-dark .find-controls input {
|
||||||
|
background: #333;
|
||||||
|
border-color: #555;
|
||||||
|
color: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-dark .find-controls button {
|
||||||
|
background: #404040;
|
||||||
|
border-color: #555;
|
||||||
|
color: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-dark .find-controls button:hover {
|
||||||
|
background: #4a4a4a;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-dark .line-numbers {
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-right-color: #555;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Additional theme support for line numbers */
|
||||||
|
body.theme-solarized .line-numbers {
|
||||||
|
background: #fdf6e3;
|
||||||
|
border-right-color: #eee8d5;
|
||||||
|
color: #93a1a1;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-monokai .line-numbers {
|
||||||
|
background: #2f2f2f;
|
||||||
|
border-right-color: #555;
|
||||||
|
color: #75715e;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-github .line-numbers {
|
||||||
|
background: #fafbfc;
|
||||||
|
border-right-color: #e1e4e8;
|
||||||
|
color: #586069;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user