Editorjs2html
A Rust library that converts Editor.js output into clean HTML with semantic CSS classes.
Features
- Comprehensive support for Editor.js block types
- Clean HTML output with semantic CSS classes
- URL validation and HTML escaping for security
- Efficient string handling and memory usage
- Highly configurable styling options
- Built-in accessibility features
Installation
Quick Start
use string_to_html;
Supported Block Types
| Block Type | Class Name | Additional Classes/Notes |
|---|---|---|
| Header / Heading | js-head |
Supports alignment |
| Paragraph | js-para |
Supports alignment |
| List / Nested List | js-list |
Supports ordered/unordered |
| Checklist | js-checklist |
js-checkbox for items |
| Table | js-table |
Supports headers |
| Quote | js-quote |
Supports alignment |
| Code | js-code |
Supports language highlighting |
| Link | js-link |
Opens in new tab |
| Inline Text | js-inline |
Multiple formatting options |
| Warning | warning |
Title + message format |
| Image | js-image |
Multiple display options |
| Embed | js-embed |
Supports various platforms |
| Raw HTML | js-raw |
Direct HTML insertion |
| Alert | js-alert |
Multiple types (see below) |
| Title | js-title |
Custom styling options |
| Attaches | js-attaches |
File attachments |
| Toggle | js-toggle |
Expandable content |
| Delimiter | js-delimiter |
Multiple styles |
| Button | js-button |
Interactive elements |
Block-Specific Details
Alert Types
Available classes for alerts:
js-alert-primaryjs-alert-secondaryjs-alert-infojs-alert-successjs-alert-warningjs-alert-dangerjs-alert-lightjs-alert-dark
Image Modifiers
Additional classes for images:
js-image--stretched- Full widthjs-image--bordered- With borderjs-image--background- With background
Inline Text Formatting
Applied in this order:
bold→<b>italic→<i>underline→<u>marker→<mark>inline_code→<code>
Styling
The library generates semantic HTML with consistent class names for styling. Example:
/* Headers */
}
/* Lists */
}
/* Code blocks */
}
Contributing
- Install development tools:
- Commit messages must follow the format:
<type>: <description>
Types:
- feat: New features
- fix: Bug fixes
- docs: Documentation
- style: Code style changes
- ref: Refactoring
- test: Testing
- perf: Performance
- Submit a pull request
License
Licensed under either:
- Apache License, Version 2.0
- MIT license
at your option.