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

Regex pattern failing #323

Open
SaadArdati opened this issue Sep 22, 2020 · 3 comments
Open

Regex pattern failing #323

SaadArdati opened this issue Sep 22, 2020 · 3 comments

Comments

@SaadArdati
Copy link

SaadArdati commented Sep 22, 2020

I tried to implement my own font inline parser, but it seems the regex refuses to match despite it being valid in my testing.

Here's my class:

import 'package:markdown/markdown.dart';

const fonts = [
  'Roboto',
  'Roboto Mono',
  'Roboto Slab',
  'Dancing Script',
];

class FontSyntax extends TextSyntax {
  final String fontFamily;

  FontSyntax(int count, this.fontFamily) : super(r'\(:{1}\)\[([^\]]+)\]');

// This never fires
  @override
  bool onMatch(InlineParser parser, Match match) {
    return true; // Can't do anything with this because theres no font node in html?
  }
}

I'm using it like so:

                  MarkdownBody(
                    data: body,
                    selectable: true,
                    extensionSet: md.ExtensionSet.gitHubFlavored
                      ..inlineSyntaxes.addAll([
                        FontSyntax(1, GoogleFonts.roboto().fontFamily),
                        FontSyntax(2, GoogleFonts.robotoMono().fontFamily),
                        FontSyntax(3, GoogleFonts.robotoSlab().fontFamily),
                        FontSyntax(
                            4,
                            GoogleFonts.dancingScriptTextTheme()
                                .bodyText1
                                .fontFamily),
                      ]),
                    imageBuilder: (uri, title, alt) => CachedNetworkImage(
                      imageUrl: uri.toString(),
                      progressIndicatorBuilder:
                          (context, url, downloadProgress) => Center(
                        child: CircularProgressIndicator(
                            value: downloadProgress.progress),
                      ),
                      errorWidget: (context, url, error) => Icon(Icons.error),
                    ),
                  ),

I set it to the regex is \(:{1}\)\[([^\]]+)\
this will match text like so: [:](text here)

But it wont fire at all.

Regexr results:
image

@srawlins
Copy link
Member

I would remove the flutter markdown package from the equation. Have you tried with just plain package:markdown? and, for example, the renderToHtml function?

@SaadArdati
Copy link
Author

@srawlins

print(md.markdownToHtml(
                                            branch.body,
                                            extensionSet:
                                                md.ExtensionSet.gitHubFlavored
                                                  ..inlineSyntaxes.addAll([
                                                    FontSyntax(
                                                        1,
                                                        GoogleFonts.roboto()
                                                            .fontFamily),
                                                    FontSyntax(
                                                        2,
                                                        GoogleFonts.robotoMono()
                                                            .fontFamily),
                                                    FontSyntax(
                                                        3,
                                                        GoogleFonts.robotoSlab()
                                                            .fontFamily),
                                                    FontSyntax(
                                                        4,
                                                        GoogleFonts
                                                                .dancingScriptTextTheme()
                                                            .bodyText1
                                                            .fontFamily),
                                                  ]),
                                          ));

<p>(::::)[this is so cool)</p>

@mjordan56
Copy link
Contributor

@srawlins and @SwissCheese5 this looks like the problem I fixed in PR #309 which isn't in the current released 2.1.8 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants