markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Regex pattern failing

Open SaadArdati opened this issue 4 years ago • 3 comments

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

SaadArdati avatar Sep 22 '20 19:09 SaadArdati

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

srawlins avatar Sep 22 '20 19:09 srawlins

@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>

SaadArdati avatar Sep 23 '20 09:09 SaadArdati

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

mjordan56 avatar Oct 01 '20 04:10 mjordan56