InlineParser constructor

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

Implementation

InlineParser(this.source, this.document) : _stack = <TagState>[] {
  // User specified syntaxes are the first syntaxes to be evaluated.
  syntaxes.addAll(document.inlineSynTaxes);

  final documentHasCustomInlineSynTaxes =
      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 (documentHasCustomInlineSynTaxes) {
    // 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)'));
  }

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