A clean, responsive PHP 8 web application that converts any URL to a Markdown file with live preview functionality.
- URL to Markdown Conversion: Convert any webpage to clean Markdown format
- Real-time Progress Tracking: Step-by-step conversion process with progress bar
- Side-by-side Preview: View both raw Markdown and rendered HTML output
- Download Functionality: Download the converted Markdown as a .md file
- Responsive Design: Works seamlessly on desktop and mobile devices
- Error Handling: Comprehensive error handling with user-friendly messages
- MVC Architecture: Clean separation of concerns following PHP best practices
- PHP 8+: Modern PHP with type declarations and latest features
- MVC Pattern: Organized code structure with Controllers, Models, and Views
- cURL/file_get_contents: Robust URL fetching with fallback mechanisms
- Real-time Progress: AJAX-based progress tracking with session storage
- Responsive CSS: Mobile-first design with CSS Grid and Flexbox
- Vanilla JavaScript: No external dependencies for frontend functionality
url2md/
├── app/
│ ├── controllers/
│ │ ├── homecontroller.php # Main page controller
│ │ └── convertcontroller.php # Conversion logic controller
│ ├── models/
│ │ └── urlconverter.php # Core conversion model
│ └── views/
│ └── home.php # Main page template
├── config/
│ └── config.php # Application configuration
├── public/
│ ├── css/
│ │ └── style.css # Application styles
│ └── js/
│ └── app.js # Frontend JavaScript
├── storage/
│ ├── downloads/ # Generated Markdown files
│ └── temp/ # Temporary files
├── tests/
│ └── url-converter.spec.js # Playwright test suite
├── index.php # Application entry point
├── playwright.config.js # Test configuration
└── package.json # Node.js dependencies for testing
-
Clone the repository:
git clone <repository-url> cd url2md
-
Ensure PHP 8+ is installed:
php --version
-
Start the development server:
php -S localhost:8000
-
Open in browser: Navigate to
http://localhost:8000
- Enter a URL: Input any valid HTTP/HTTPS URL in the form
- Start Conversion: Click "Convert to Markdown" to begin the process
- Monitor Progress: Watch the real-time progress bar and step-by-step log
- View Results: See both raw Markdown and rendered HTML preview
- Download: Click "Download Markdown File" to save the .md file
- New Conversion: Use "Convert Another URL" to start over
The application includes comprehensive Playwright tests covering:
- Main page functionality
- Form validation
- URL conversion process
- Progress tracking
- Error handling
- Responsive design
- Download functionality
-
Install test dependencies:
npm install
-
Install Playwright browsers:
npx playwright install
-
Run all tests:
npm test -
Run tests with visible browser:
npm run test:headed
-
View test report:
npx playwright show-report
The application follows these steps for URL conversion:
- URL Validation: Validates the input URL format and scheme
- Content Fetching: Downloads the webpage content using cURL or file_get_contents
- HTML Parsing: Parses and cleans the HTML using DOMDocument
- Markdown Conversion: Converts HTML elements to Markdown syntax
- File Storage: Saves the Markdown file for download
- Preview Generation: Creates HTML preview for side-by-side display
Key configuration options in config/config.php:
USER_AGENT: HTTP user agent string for requestsREQUEST_TIMEOUT: Timeout for URL fetching (default: 30 seconds)STORAGE_PATH: Directory for file storagePROGRESS_STEPS: Conversion step definitions
- Chrome/Chromium (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
The application follows PHP 8 best practices:
- Type Declarations: Strict typing throughout the codebase
- Error Handling: Comprehensive exception handling
- Security: Input validation and sanitization
- Performance: Efficient DOM parsing and conversion
- Maintainability: Clean MVC architecture
This project is open source and available under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request