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

Add additionalFormats to fallback and make formats public #415

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Changes from 2 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
29 changes: 16 additions & 13 deletions packages/fleather/lib/src/widgets/autoformats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
: _autoFormats = autoFormats;

/// Default set of auto formats.
factory AutoFormats.fallback() {
///
/// Use [additionalFormats] to add your autoformats to the default set.
factory AutoFormats.fallback([List<AutoFormat>? additionalFormats]) {
return AutoFormats(autoFormats: [
const _AutoFormatLinks(),
const _MarkdownInlineShortcuts(),
const _MarkdownLineShortcuts(),
const _AutoTextDirection(),
const AutoFormatLinks(),
const MarkdownInlineShortcuts(),
const MarkdownLineShortcuts(),
const AutoTextDirection(),
...?additionalFormats,

Check warning on line 39 in packages/fleather/lib/src/widgets/autoformats.dart

View check run for this annotation

Codecov / codecov/patch

packages/fleather/lib/src/widgets/autoformats.dart#L39

Added line #L39 was not covered by tests
]);
}

Expand Down Expand Up @@ -119,11 +122,11 @@
final int undoPositionCandidate;
}

class _AutoFormatLinks extends AutoFormat {
class AutoFormatLinks extends AutoFormat {
static final _urlRegex =
RegExp(r'^(.?)((?:https?://|www\.)[^\s/$.?#].[^\s]*)');

const _AutoFormatLinks();
const AutoFormatLinks();

@override
AutoFormatResult? apply(
Expand Down Expand Up @@ -166,15 +169,15 @@
}

// Replaces certain Markdown shortcuts with actual inline styles.
class _MarkdownInlineShortcuts extends AutoFormat {
class MarkdownInlineShortcuts extends AutoFormat {
static final rules = <String, ParchmentAttribute>{
'**': ParchmentAttribute.bold,
'*': ParchmentAttribute.italic,
'`': ParchmentAttribute.inlineCode,
'~~': ParchmentAttribute.strikethrough,
};

const _MarkdownInlineShortcuts();
const MarkdownInlineShortcuts();

@override
AutoFormatResult? apply(
Expand Down Expand Up @@ -222,7 +225,7 @@
}

// Replaces certain Markdown shortcuts with actual line or block styles.
class _MarkdownLineShortcuts extends AutoFormat {
class MarkdownLineShortcuts extends AutoFormat {
static final rules = <String, ParchmentAttribute>{
'-': ParchmentAttribute.block.bulletList,
'*': ParchmentAttribute.block.bulletList,
Expand All @@ -236,7 +239,7 @@
'###': ParchmentAttribute.h3,
};

const _MarkdownLineShortcuts();
const MarkdownLineShortcuts();

String? _getLinePrefix(DeltaIterator iter, int index) {
final prefixOps = skipToLineAt(iter, index);
Expand Down Expand Up @@ -383,8 +386,8 @@

// Infers text direction from the input when happens in the beginning of a line.
// This rule also removes alignment and sets it based on inferred direction.
class _AutoTextDirection extends AutoFormat {
const _AutoTextDirection();
class AutoTextDirection extends AutoFormat {
const AutoTextDirection();

final _isRTL = intl.Bidi.startsWithRtl;

Expand Down
Loading