### Register Custom Block with HtmlToDelta in Dart Source: https://github.com/cathood0/flutter_quill_delta_from_html/blob/master/README.md Demonstrates how to register a custom block handler (`PullquoteBlock`) with the `HtmlToDelta` converter. This involves creating an instance of the custom block and passing it within the `customBlocks` list during the `HtmlToDelta` initialization. The example shows a complete conversion process from an HTML string to Delta operations. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; void main() { // Example HTML snippet final htmlText = '''
Regular paragraph before the custom block
Regular paragraph after the custom block
'''; // Registering the custom block final customBlocks = [PullquoteBlock()]; // Initialize HtmlToDelta with the HTML text and custom blocks final converter = HtmlToDelta(customBlocks: customBlocks); // Convert HTML to Delta operations final delta = converter.convert(htmlText); /* This should be resulting delta {"insert": "Regular paragraph before the custom block"}, {"insert": "Pullquote: \"This is a custom pullquote\" by John Doe", "attributes": {"italic": true}}, {"insert": "\n"}, {"insert": "Regular paragraph after the custom block\n"} */ } ``` -------------------------------- ### HtmlToDelta Constructor with Custom Options Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Illustrates the creation of an HtmlToDelta instance with custom configurations. This includes defining a handler for detecting line height from CSS variables, specifying blacklisted HTML nodes to ignore, and enabling the replacement of normal newlines withCustom spacing
'; var delta = converter.convert(html); print(delta.toJson()); // Output: [ // {"insert": "Custom spacing"}, // {"insert": "\n", "attributes": {"line-height": 1.5}}, // {"insert": "\n"} // ] } ``` -------------------------------- ### HtmlToDelta Constructor with Custom Options Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Initializes the HtmlToDelta converter with custom configurations, including CSS variable handlers, blacklisted nodes, and newline handling. ```APIDOC ## POST /api/html-to-delta/configure ### Description Creates an HtmlToDelta instance with custom HTML block handlers, blacklisted nodes, and CSS variable callbacks. ### Method POST ### Endpoint /api/html-to-delta/configure ### Parameters #### Request Body - **options** (object) - Required - Configuration options for the converter. - **onDetectLineheightCssVariable** (function) - Optional - Callback function for custom line height CSS variable detection. It receives tag, key, and value as arguments and should return the processed value or null. - **blackNodesList** (array) - Optional - An array of strings representing HTML tags to be ignored during conversion. - **replaceNormalNewLinesToBr** (boolean) - Optional - If true, normal newline characters in the HTML will be converted to `Hello, world!
'; var converter = HtmlToDelta(); var delta = converter.convert(htmlContent); print(delta.toJson()); // Output: [ // {"insert": "Hello, "}, // {"insert": "world", "attributes": {"bold": true}}, // {"insert": "!"}, // {"insert": "\n", "attributes": {"line-height": 2.0}}, // {"insert": "\n"} // ] // Complex example with multiple formatting String complexHtml = '''Regular text with italic, bold, and underline.
Bold, italic, underline, strikethrough
H2O and E=mc2
'; delta = converter.convert(scriptHtml); print(delta.toJson()); // Output: [ // {"insert": "H"}, // {"insert": "2", "attributes": {"script": "sub"}}, // {"insert": "O and E=mc"}, // {"insert": "2", "attributes": {"script": "super"}}, // {"insert": "\n"}, // {"insert": "\n"} // ] } ``` -------------------------------- ### Convert HTML Images to Delta Operations (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts HTML image tags (
''';
var delta = converter.convert(imageHtml);
print(delta.toJson());
}
```
--------------------------------
### Custom HTML Element to Delta Conversion (Dart)
Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt
Defines and uses a custom handler for non-standard HTML elements like 'Regular paragraph before
Regular paragraph after
'''; final customBlocks = [PullquoteBlock()]; final converter = HtmlToDelta(customBlocks: customBlocks); final delta = converter.convert(htmlText); print(delta.toJson()); // Output: [ // {"insert": "Regular paragraph before\n"}, // {"insert": "Pullquote: \"This is a quote\" by John Doe", "attributes": {"italic": true}}, // {"insert": "\n"}, // {"insert": "Regular paragraph after\n"}, // {"insert": "\n"} // ] } ``` -------------------------------- ### HtmlOperations Abstract Class Definition in Dart Source: https://github.com/cathood0/flutter_quill_delta_from_html/blob/master/README.md Defines the abstract `HtmlOperations` class, which serves as a blueprint for handling HTML to Delta conversion. It includes a list for custom blocks and abstract methods for converting various HTML elements (like headers, lists, paragraphs, links, images, etc.) into Delta operations. This class is intended to be extended for specific conversion logic. ```dart abstract class HtmlOperations { /// custom blocks are passed internally by HtmlToDelta ListVisit Flutter and Dart websites.
'; var delta = converter.convert(linkHtml); print(delta.toJson()); } ``` -------------------------------- ### Create Custom HTML Block Handler in Dart Source: https://github.com/cathood0/flutter_quill_delta_from_html/blob/master/README.md Defines a custom HTML part handler for `, you just need to do something like:
// element.localName == 'p'
return element.localName == 'pullquote';
}
@override
List Hello, world! Hello, world!
Styled text with
highlighted
content
Hello world
''';
var delta = converter.convert(ulHtml);
print(delta.toJson());
// Ordered list
String olHtml = '
';
delta = converter.convert(olHtml);
// Check list
String checklistHtml = '''
''';
delta = converter.convert(checklistHtml);
print(delta.toJson());
}
```
--------------------------------
### Convert HTML Blockquotes and Code Blocks to Delta (Dart)
Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt
Converts HTML blockquote and code block elements into Quill Delta operations. This function processes standard HTML tags and applies corresponding Delta attributes for formatting. It requires the HtmlToDelta converter from the flutter_quill_delta_from_html package.
```dart
import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart';
void main() {
final converter = HtmlToDelta();
// Blockquote
String blockquoteHtml = 'This is a quoted text
';
var delta = converter.convert(blockquoteHtml);
print(delta.toJson());
// Output: [
// {"insert": "This is a quoted text"},
// {"insert": "\n", "attributes": {"blockquote": true}},
// {"insert": "\n"}
// ]
// Code block
String codeHtml = '
';
delta = converter.convert(codeHtml);
print(delta.toJson());
// Output: [
// {"insert": "function hello() {"},
// {"insert": "\n", "attributes": {"code-block": true}},
// {"insert": " console.log(\"Hello\");"},
// {"insert": "\n", "attributes": {"code-block": true}},
// {"insert": "}"},
// {"insert": "\n", "attributes": {"code-block": true}},
// {"insert": "\n"}
// ]
}
```
--------------------------------
### HtmlToDelta.convert()
Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt
Converts an HTML string into Quill Delta operations. This method handles various HTML elements and supports custom styling attributes.
```APIDOC
## POST /api/html-to-delta
### Description
Converts an HTML string into Quill Delta operations with support for custom block handlers and styling attributes.
### Method
POST
### Endpoint
/api/html-to-delta
### Parameters
#### Request Body
- **htmlContent** (string) - Required - The HTML string to convert.
- **options** (object) - Optional - Configuration options for the conversion process.
- **onDetectLineheightCssVariable** (function) - Optional - Callback for custom line height CSS variable detection.
- **blackNodesList** (array) - Optional - List of HTML tags to ignore.
- **replaceNormalNewLinesToBr** (boolean) - Optional - Whether to replace normal newlines with function hello() {\n console.log("Hello");\n}
tags.
### Request Example
```json
{
"htmlContent": "
''';
// Convert table as embed
var delta = converter.convert(tableHtml, transformTableAsEmbed: true);
print(delta.toJson());
// Output will contain table embed structure
// Convert table as plain text (default)
delta = converter.convert(tableHtml, transformTableAsEmbed: false);
// Output: [
// {"insert": "Cell 1\tCell 2\n"},
// {"insert": "Cell 3\tCell 4\n"},
// {"insert": "\n"}
// ]
}
```
--------------------------------
### Convert HTML Inline Styles to Delta Operations (Dart)
Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt
Converts inline CSS styles from HTML into Delta attributes. It supports various styles including text alignment, font size, color, font family, and background color for spans. Requires the flutter_quill_delta_from_html package.
```dart
import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart';
void main() {
final converter = HtmlToDelta();
String styledHtml = '''
Cell 1
Cell 2
Cell 3
Cell 4