# MDRender
A lightweight, customizable markdown renderer for web applications. MDRender converts markdown text into styled HTML with support for dark mode and custom theming.
## Features
- 📝 Full markdown support including:
- Headings (h1-h6)
- Bold and italic text
- Code blocks with language highlighting
- Inline code
- Lists (ordered and unordered)
- Blockquotes
- Links
- Tables
- Images
- 🎨 Customizable themes via CSS variables
- 🌙 Built-in dark mode support
- 🎯 Zero dependencies
- 📱 Responsive design
- 🚀 Simple API
## Getting Started
### 1. Include the Required Files
```html
```
### 2. Initialize the Renderer
```javascript
const renderer = new MDRenderer();
```
### 3. Convert Markdown to HTML
```javascript
const markdown = "# Hello World\nThis is **markdown**!";
const html = renderer.render(markdown);
// Output:
Hello World
This is markdown!
```
### 4. Display the Result
```javascript
document.getElementById('output').innerHTML = html;
```
## Customizing Styles
### Basic Theme Customization
Override the default colors by setting CSS variables:
```css
.mdrender {
--md-text: #333; /* Main text color */
--md-header: #2c3e50; /* Heading color */
--md-code-bg: #f8f9fa; /* Code background */
--md-blockquote: #666; /* Blockquote text color */
--md-link: #3498db; /* Link color */
--md-border: #ddd; /* Border color */
}
```
### Dark Mode Support
Add dark mode styles by using the `data-theme` attribute:
```css
[data-theme="dark"] .mdrender {
--md-text: #e0e0e0;
--md-header: #60a5fa;
--md-code-bg: #2d2d2d;
--md-blockquote: #a0a0a0;
--md-link: #60a5fa;
--md-border: #404040;
}
```
Toggle dark mode with JavaScript:
```javascript
// Enable dark mode
document.documentElement.setAttribute('data-theme', 'dark');
// Enable light mode
document.documentElement.setAttribute('data-theme', 'light');
```
## Complete Example
Here's a complete example showing how to use MDRender in your project:
```html
MDRender Example
```
## Supported Markdown Syntax
- Headings: `# H1` through `###### H6`
- Bold: `**bold text**`
- Italic: `*italic text*`
- Code blocks: ````javascript code here```
- Inline code: `` `code` ``
- Lists:
- Unordered: `- item`
- Ordered: `1. item`
- Blockquotes: `> quote`
- Links: `[text](url)`
- Images: ``
- Tables:
```
| Header | Header |
|--------|--------|
| Cell | Cell |
```
## Browser Support
MDRender works in all modern browsers:
- Chrome
- Firefox
- Safari
- Edge
## Contributing
Feel free to submit issues and enhancement requests!
## License
MIT License - feel free to use this in your own projects!