### 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

This is a custom pullquote

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 with
tags. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; void main() { // With custom CSS variable handler final converter = HtmlToDelta( onDetectLineheightCssVariable: (String tag, String key, String value) { if (tag == 'p' && value == 'var(--custom-spacing)') { return 1.5; // Return custom line height value } return null; // Return null to use default behavior }, blackNodesList: ['script', 'style'], // Ignore these HTML tags replaceNormalNewLinesToBr: true, // Convert \n to
); String html = '

Custom 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 `
` tags. ### Request Example ```json { "options": { "onDetectLineheightCssVariable": "(tag, key, value) => { if (tag === 'p' && value === 'var(--custom-spacing)') { return 1.5; } return null; }", "blackNodesList": ["script", "style"], "replaceNormalNewLinesToBr": true } } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the converter has been configured. #### Response Example ```json { "message": "HtmlToDelta converter configured successfully with custom options." } ``` ``` -------------------------------- ### Convert HTML to Quill Delta Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Demonstrates basic and complex HTML to Quill Delta conversion using the HtmlToDelta.convert() method. It shows how to handle text formatting, headings, lists, and links, outputting the Delta operations in JSON format. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; import 'package:dart_quill_delta/dart_quill_delta.dart'; void main() { // Basic HTML to Delta conversion String htmlContent = '

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 = '''

Title

Regular text with italic, bold, and underline.

Link text '''; Delta complexDelta = converter.convert(complexHtml); print(complexDelta.toJson()); } ``` -------------------------------- ### Flutter Quill Delta Dependency in pubspec.yaml Source: https://github.com/cathood0/flutter_quill_delta_from_html/blob/master/README.md This snippet shows how to add the 'flutter_quill_delta_from_html' package as a dependency in your Flutter project's pubspec.yaml file. Ensure you replace '' with the actual latest version number. ```yaml dependencies: flutter_quill_delta_from_html: ``` -------------------------------- ### HTML Headings to Delta Conversion (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts standard HTML heading tags (h1-h6) into Quill Delta operations, applying the 'header' attribute with the corresponding level. Also handles inline styles like text alignment. 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 headingHtml = '''

Heading 1

Heading 2

Centered Heading 3

'''; var delta = converter.convert(headingHtml); print(delta.toJson()); // Output: [ // {"insert": "Heading 1"}, // {"insert": "\n", "attributes": {"header": 1}}, // {"insert": "Heading 2"}, // {"insert": "\n", "attributes": {"header": 2}}, // {"insert": "Centered Heading 3"}, // {"insert": "\n", "attributes": {"header": 3, "align": "center"}}, // {"insert": "\n"} // ] } ``` -------------------------------- ### HTML Text Formatting to Delta Conversion (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts standard HTML text formatting tags (bold, italic, underline, strikethrough, subscript, superscript) into Quill Delta operations. Each formatting tag is mapped to its corresponding Delta attribute. 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(); // Bold, italic, underline, and strikethrough String formattedHtml = '

Bold, italic, underline, strikethrough

'; var delta = converter.convert(formattedHtml); print(delta.toJson()); // Output: [ // {"insert": "Bold", "attributes": {"bold": true}}, // {"insert": ", "}, // {"insert": "italic", "attributes": {"italic": true}}, // {"insert": ", "}, // {"insert": "underline", "attributes": {"underline": true}}, // {"insert": ", "}, // {"insert": "strikethrough", "attributes": {"strike": true}}, // {"insert": "\n"}, // {"insert": "\n"} // ] // Superscript and subscript String scriptHtml = '

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 () into Delta embed operations. It supports extracting attributes like src, alt, style (width, height, margin), and align for proper image rendering in the Delta format. 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 imageHtml = ''' Example Image '''; 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 ''. This allows for specific conversion logic for custom tags, including attribute parsing and application of Delta operations. Requires flutter_quill_delta_from_html and dart_quill_delta packages. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; import 'package:dart_quill_delta/dart_quill_delta.dart'; import 'package:html/dom.dart' as dom; // Custom block handler for elements class PullquoteBlock extends CustomHtmlPart { @override bool matches(dom.Element element) { return element.localName == 'pullquote'; } @override List convert(dom.Element element, {Map? currentAttributes}) { final Delta delta = Delta(); final Map attributes = currentAttributes != null ? Map.from(currentAttributes) : {}; final author = element.attributes['data-author']; final style = element.attributes['data-style']; String text = 'Pullquote: "${element.text}"'; if (author != null) { text += ' by $author'; } if (style != null && style.toLowerCase() == 'italic') { attributes['italic'] = true; } delta.insert(text, attributes); delta.insert('\n'); return delta.toList(); } } void main() { final htmlText = '''

Regular paragraph before

This is a quote

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 List? customBlocks; // You don't need to override this method // since it just call the other methods // when detect the type of HTML tag List resolveCurrentElement(dom.Element element, [int indentLevel = 0]); List brToOp(dom.Element element); List headerToOp(dom.Element element); List listToOp(dom.Element element, [int indentLevel = 0]); List paragraphToOp(dom.Element element); List linkToOp(dom.Element element); List spanToOp(dom.Element element); List imgToOp(dom.Element element); List videoToOp(dom.Element element); List codeblockToOp(dom.Element element); List blockquoteToOp(dom.Element element); } ``` -------------------------------- ### Convert HTML Links to Delta Operations (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts HTML anchor tags () into Delta operations, preserving the link URL as an attribute. This allows for clickable links within the Delta output. 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 linkHtml = '

Visit 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 `` elements. It matches specific HTML tags and converts them into Quill Delta operations, including extracting custom attributes like author and style. This handler can be integrated into the `HtmlToDelta` converter. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; import 'package:html/dom.dart' as dom; /// Custom block handler for elements. class PullquoteBlock extends CustomHtmlPart { @override bool matches(dom.Element element) { //you can put here the validation that you want // // To detect a

, you just need to do something like: // element.localName == 'p' return element.localName == 'pullquote'; } @override List convert(dom.Element element, {Map? currentAttributes}) { final Delta delta = Delta(); final Map attributes = currentAttributes != null ? Map.from(currentAttributes) : {}; // Extract custom attributes from the element // The attributes represents the data into a html tag // at this point, should have these attributes // // // These attributes can be optional, so do you need to ensure to not use "!" // to avoid any null conflict final author = element.attributes['data-author']; final style = element.attributes['data-style']; // Apply custom attributes to the Delta operations if (author != null) { delta.insert('Pullquote: "${element.text}" by $author', attributes); } else { delta.insert('Pullquote: "${element.text}"', attributes); } if (style != null && style.toLowerCase() == 'italic') { attributes['italic'] = true; } delta.insert('\n', attributes); return delta.toList(); } } ``` -------------------------------- ### Convert HTML to Quill Delta in Dart Source: https://github.com/cathood0/flutter_quill_delta_from_html/blob/master/README.md This snippet demonstrates how to use the HtmlToDelta converter from the flutter_quill_delta_from_html package to transform an HTML string into a Quill Delta object. It handles basic text formatting and line height attributes. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; void main() { String htmlContent = '

Hello, world!

'; var delta = HtmlToDelta().convert(htmlContent, transformTableAsEmbed: false); /* { "insert": "hello, " }, { "insert": "world", "attributes": {"bold": true} }, { "insert": "!" }, { "insert": "\n", { 'line-height': 2.0 } } */ } ``` -------------------------------- ### Convert HTML Lists to Delta Operations (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts HTML ordered lists, unordered lists, and check lists into Delta operations. It handles indentation and different list types (bullet, checked, unchecked). 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(); // Unordered list String ulHtml = '''
  • First item
  • Second item
  • Third item
'''; var delta = converter.convert(ulHtml); print(delta.toJson()); // Ordered list String olHtml = '
  1. First
  2. Second
'; delta = converter.convert(olHtml); // Check list String checklistHtml = '''
  • Completed task
  • Incomplete task
'''; 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 = '
function hello() {\n  console.log("Hello");\n}
'; 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
tags. ### Request Example ```json { "htmlContent": "

Hello, world!

", "options": { "replaceNormalNewLinesToBr": true } } ``` ### Response #### Success Response (200) - **delta** (object) - The Quill Delta operations representing the converted HTML. #### Response Example ```json { "delta": [ {"insert": "Hello, "}, {"insert": "world", "attributes": {"bold": true}}, {"insert": "!"}, {"insert": "\n", "attributes": {"line-height": 2.0}}, {"insert": "\n"} ] } ``` ``` -------------------------------- ### Convert HTML Tables to Delta (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts HTML table elements into Delta operations, with an option to transform tables into a single embed. By default, tables are converted into plain text rows and cells. This function requires the HtmlToDelta converter. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; void main() { final converter = HtmlToDelta(); String tableHtml = '''
Cell 1 Cell 2
Cell 3 Cell 4
'''; // 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 = '''

Styled text with highlighted content

'''; var delta = converter.convert(styledHtml); print(delta.toJson()); } ``` -------------------------------- ### Convert Parsed DOM Document to Delta (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Converts a pre-parsed DOM document directly into Quill Delta operations, bypassing HTML string parsing. This method is useful when you already have a parsed HTML document structure. It requires the HtmlToDelta converter and the html package for parsing. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; import 'package:html/parser.dart' as parser; void main() { final converter = HtmlToDelta(); // Parse HTML into DOM document final document = parser.parse('

Hello world

'); // Convert DOM document to Delta final delta = converter.convertDocument(document); print(delta.toJson()); // Output: [ // {"insert": "Hello "}, // {"insert": "world", "attributes": {"bold": true}}, // {"insert": "\n"}, // {"insert": "\n"} // ] } ``` -------------------------------- ### Parse CSS Style Attribute to Delta Attributes (Dart) Source: https://context7.com/cathood0/flutter_quill_delta_from_html/llms.txt Parses CSS style strings into Delta-compatible attribute maps. This utility function is useful for custom processing of inline styles and can handle CSS variables via a callback. It requires the parseStyleAttribute function from the flutter_quill_delta_from_html package. ```dart import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart'; void main() { // Parse inline CSS styles final styleString = 'color: #FF0000; font-size: 16px; text-align: center; font-weight: bold'; final attributes = parseStyleAttribute('p', styleString); print(attributes); // Output: { // 'color': '#FF0000', // 'size': '16', // 'align': 'center', // 'bold': true // } // With CSS variable callback final attributesWithCallback = parseStyleAttribute( 'span', 'line-height: var(--spacing)', onDetectLineheightCssVariable: (tag, key, value) { if (value == 'var(--spacing)') return 2.0; return null; } ); print(attributesWithCallback); // Output: {'line-height': 2.0} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.