InlineParser constructor

InlineParser(
  1. String? source,
  2. Document document
)

Implementation

InlineParser(String? source, this.document) : syntaxes = <InlineSyntax>[],
super(source) {
  // User specified syntaxes are the first syntaxes to be evaluated.
  syntaxes.addAll(document.inlineSyntaxes);

  var hasCustomInlineSyntaxes = document.inlineSyntaxes
      .any((s) => !document.extensionSet.inlineSyntaxes.contains(s));

  // This first RegExp matches plain text to accelerate parsing. It's written
  // so that it does not match any prefix of any following syntaxes. Most
  // Markdown is plain text, so it's faster to match one RegExp per 'word'
  // rather than fail to match all the following RegExps at each non-syntax
  // character position.
  if (hasCustomInlineSyntaxes) {
    // We should be less aggressive in blowing past "words".
    syntaxes.add(TextSyntax(r'[A-Za-z0-9]+(?=\s)'));
  } else {
    syntaxes.add(TextSyntax(r'[ \tA-Za-z0-9]*[A-Za-z0-9](?=\s)'));
  }

  // Custom link resolvers go after the generic text syntax.
  syntaxes.addAll([
    LinkSyntax(linkResolver: document.linkResolver),
    ImageSyntax(linkResolver: document.imageLinkResolver)
  ]);

  syntaxes.addAll(_defaultSyntaxes);

  if (_encodeHtml) {
    syntaxes.addAll(_htmlSyntaxes);
  }
}