Fixing lint

pull/1828/head
dbrezack 1 year ago
parent 1e36914bf3
commit 9088107706
  1. 28
      lib/src/packages/quill_markdown/markdown_to_delta.dart

@ -21,7 +21,8 @@ typedef ElementToEmbeddableConvertor = Embeddable Function(
); );
/// Convertor from Markdown string to quill [Delta]. /// Convertor from Markdown string to quill [Delta].
class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor { class MarkdownToDelta extends Converter<String, Delta>
implements md.NodeVisitor {
/// ///
MarkdownToDelta({ MarkdownToDelta({
required this.markdownDocument, required this.markdownDocument,
@ -143,7 +144,9 @@ class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor
if (_isInBlockQuote) { if (_isInBlockQuote) {
renderedText = text.text; renderedText = text.text;
} else if (_isInCodeblock) { } else if (_isInCodeblock) {
renderedText = text.text.endsWith('\n') ? text.text.substring(0, text.text.length - 1) : text.text; renderedText = text.text.endsWith('\n')
? text.text.substring(0, text.text.length - 1)
: text.text;
} else { } else {
renderedText = _trimTextToMdSpec(text.text); renderedText = _trimTextToMdSpec(text.text);
} }
@ -245,7 +248,9 @@ class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor
} }
void _insertNewLineBeforeElementIfNeeded(md.Element element) { void _insertNewLineBeforeElementIfNeeded(md.Element element) {
if (!_isInBlockQuote && _lastTag == 'blockquote' && element.tag == 'blockquote') { if (!_isInBlockQuote &&
_lastTag == 'blockquote' &&
element.tag == 'blockquote') {
_insertNewLine(); _insertNewLine();
return; return;
} }
@ -283,7 +288,10 @@ class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor
return; return;
} }
if (!_justPreviousBlockExit && (_isTopLevelNode(element) || _haveBlockAttrs(element) || element.tag == 'li')) { if (!_justPreviousBlockExit &&
(_isTopLevelNode(element) ||
_haveBlockAttrs(element) ||
element.tag == 'li')) {
_justPreviousBlockExit = true; _justPreviousBlockExit = true;
_insertNewLine(); _insertNewLine();
return; return;
@ -368,7 +376,8 @@ class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor
result = _effectiveElementToInlineAttr()[element.tag]?.call(element); result = _effectiveElementToInlineAttr()[element.tag]?.call(element);
} }
if (result == null) { if (result == null) {
throw Exception('Element $element cannot be converted to inline attribute'); throw Exception(
'Element $element cannot be converted to inline attribute');
} }
return result; return result;
} }
@ -387,7 +396,8 @@ class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor
List<Attribute<dynamic>> _toBlockAttributes(md.Element element) { List<Attribute<dynamic>> _toBlockAttributes(md.Element element) {
final result = _effectiveElementToBlockAttr()[element.tag]?.call(element); final result = _effectiveElementToBlockAttr()[element.tag]?.call(element);
if (result == null) { if (result == null) {
throw Exception('Element $element cannot be converted to block attribute'); throw Exception(
'Element $element cannot be converted to block attribute');
} }
return result; return result;
} }
@ -399,10 +409,12 @@ class MarkdownToDelta extends Converter<String, Delta> implements md.NodeVisitor
}; };
} }
bool _isEmbedElement(md.Element element) => _effectiveElementToEmbed().containsKey(element.tag); bool _isEmbedElement(md.Element element) =>
_effectiveElementToEmbed().containsKey(element.tag);
Embeddable _toEmbeddable(md.Element element) { Embeddable _toEmbeddable(md.Element element) {
final result = _effectiveElementToEmbed()[element.tag]?.call(element.attributes); final result =
_effectiveElementToEmbed()[element.tag]?.call(element.attributes);
if (result == null) { if (result == null) {
throw Exception('Element $element cannot be converted to Embeddable'); throw Exception('Element $element cannot be converted to Embeddable');
} }

Loading…
Cancel
Save