Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump flutter_quill to 9.4.6, sdk to 3.1.0 < 4.0.0 and fix errors #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/src/delta_markdown_decoder.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:collection';
import 'dart:convert';

import 'package:flutter_quill/flutter_quill.dart'
show Attribute, AttributeScope, Delta, LinkAttribute;
import 'package:flutter_quill/flutter_quill.dart' show Attribute, AttributeScope, LinkAttribute;
import 'package:flutter_quill/quill_delta.dart' show Delta;

import 'ast.dart' as ast;
import 'document.dart';
Expand All @@ -19,8 +19,7 @@ class DeltaMarkdownDecoder extends Converter<String, String> {
}

class _DeltaVisitor implements ast.NodeVisitor {
static final _blockTags =
RegExp('h1|h2|h3|h4|h5|h6|hr|pre|ul|ol|blockquote|p|pre');
static final _blockTags = RegExp('h1|h2|h3|h4|h5|h6|hr|pre|ul|ol|blockquote|p|pre');

static final _embedTags = RegExp('hr|img');

Expand Down Expand Up @@ -174,9 +173,7 @@ class _DeltaVisitor implements ast.NodeVisitor {

@override
void visitElementAfter(ast.Element element) {
if (element.tag == 'li' &&
(previousToplevelElement.tag == 'ol' ||
previousToplevelElement.tag == 'ul')) {
if (element.tag == 'li' && (previousToplevelElement.tag == 'ol' || previousToplevelElement.tag == 'ul')) {
delta.insert('\n', activeBlockAttribute?.toJson());
}

Expand Down Expand Up @@ -247,9 +244,14 @@ class _DeltaVisitor implements ast.NodeVisitor {
}

class ImageAttribute extends Attribute<String?> {
ImageAttribute(String? val) : super('image', AttributeScope.EMBEDS, val);
const ImageAttribute(String? val)
: super(
'image',
AttributeScope.embeds,
val,
);
}

class DividerAttribute extends Attribute<String?> {
DividerAttribute() : super('divider', AttributeScope.EMBEDS, 'hr');
const DividerAttribute() : super('divider', AttributeScope.embeds, 'hr');
}
14 changes: 6 additions & 8 deletions lib/src/delta_markdown_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:collection/collection.dart' show IterableExtension;
import 'package:flutter_quill/flutter_quill.dart'
show Attribute, AttributeScope, BlockEmbed, Delta, DeltaIterator, Style;
import 'package:flutter_quill/quill_delta.dart';

class DeltaMarkdownEncoder extends Converter<String, String> {
static const _lineFeedAsciiCode = 0x0A;
Expand Down Expand Up @@ -63,10 +64,9 @@ class DeltaMarkdownEncoder extends Converter<String, String> {
// First close any current styles if needed
final markedForRemoval = <Attribute>[];
// Close the styles in reverse order, e.g. **_ for _**Test**_.
for (final value
in currentInlineStyle.attributes.values.toList().reversed) {
for (final value in currentInlineStyle.attributes.values.toList().reversed) {
// TODO(tillf): Is block correct?
if (value.scope == AttributeScope.BLOCK) {
if (value.scope == AttributeScope.block) {
continue;
}
if (style.containsKey(value.key)) {
Expand All @@ -89,7 +89,7 @@ class DeltaMarkdownEncoder extends Converter<String, String> {
// Now open any new styles.
for (final attribute in style.attributes.values) {
// TODO(tillf): Is block correct?
if (attribute.scope == AttributeScope.BLOCK) {
if (attribute.scope == AttributeScope.block) {
continue;
}
if (currentInlineStyle.containsKey(attribute.key)) {
Expand Down Expand Up @@ -121,10 +121,8 @@ class DeltaMarkdownEncoder extends Converter<String, String> {
// Close any open inline styles.
_handleInline(lineBuffer, '', null);

final lineBlock = Style.fromJson(attributes)
.attributes
.values
.singleWhereOrNull((a) => a.scope == AttributeScope.BLOCK);
final lineBlock =
Style.fromJson(attributes).attributes.values.singleWhereOrNull((a) => a.scope == AttributeScope.block);

if (lineBlock == currentBlockStyle) {
currentBlockLines.add(lineBuffer.toString());
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ description: A library for converting between Markdown and Delta of the
homepage: https://github.com/friebetill/notus_markdown

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=3.1.0 <4.0.0"

dependencies:
args: ^2.0.0
charcode: ^1.2.0
collection: ^1.15.0
flutter_quill: ^7.0.0
flutter_quill: ^9.4.6

dev_dependencies:
build_runner: ^2.0.0
Expand Down