-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CatHood0
committed
Jul 9, 2024
1 parent
27a58db
commit d587585
Showing
7 changed files
with
367 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,47 @@ | ||
import 'package:dart_quill_delta/dart_quill_delta.dart'; | ||
import 'package:html/dom.dart' as dom; | ||
|
||
/// Interface for defining a custom block handler. | ||
/// Interface for defining a custom block handler for HTML to Delta conversion. | ||
abstract class CustomHtmlPart { | ||
/// Determines if this custom block handler matches the given HTML element. | ||
/// If you want to detect, by example, a `<div>` you need to make something like | ||
/// `element.localName == 'div'` | ||
/// And this just will match with any `<div>` tag | ||
/// | ||
/// Implement this method to specify the conditions under which this handler | ||
/// should be used to convert an HTML element to Delta operations. | ||
/// | ||
/// Parameters: | ||
/// - [element]: The HTML element to evaluate. | ||
/// | ||
/// Returns: | ||
/// `true` if this handler should be used for the given HTML element, `false` otherwise. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// class MyCustomBlock implements CustomHtmlPart { | ||
/// bool matches(dom.Element element) { | ||
/// return element.localName == 'div' && element.classes.contains('my-custom-class'); | ||
/// } | ||
/// } | ||
/// ``` | ||
bool matches(dom.Element element); | ||
|
||
/// Converts the `HTML` element into `Delta` operations. | ||
/// It's called when `matches` return true | ||
List<Operation> convert(dom.Element element, | ||
{Map<String, dynamic>? currentAttributes}); | ||
/// Converts the HTML element into Delta operations. | ||
/// | ||
/// Implement this method to convert the matched HTML element into a list of Delta operations. | ||
/// | ||
/// Parameters: | ||
/// - [element]: The HTML element to convert. | ||
/// - [currentAttributes]: Optional. The current attributes to apply to the Delta operations. | ||
/// | ||
/// Returns: | ||
/// A list of Delta operations representing the converted content of the HTML element. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// class MyCustomBlock implements CustomHtmlPart { | ||
/// List<Operation> convert(dom.Element element, {Map<String, dynamic>? currentAttributes}) { | ||
/// // Conversion logic here | ||
/// } | ||
/// } | ||
/// ``` | ||
List<Operation> convert(dom.Element element, {Map<String, dynamic>? currentAttributes}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.