RichTextNode constructor

RichTextNode({
  1. required String path,
  2. required String rawPath,
  3. required Map<String, String> modifiers,
  4. required String raw,
  5. required String? comment,
  6. required bool shouldEscape,
  7. required StringInterpolation interpolation,
  8. required CaseStyle? paramCase,
  9. Map<String, Set<String>>? linkParamMap,
})

Implementation

RichTextNode({
  required super.path,
  required super.rawPath,
  required super.modifiers,
  required super.raw,
  required super.comment,
  required super.shouldEscape,
  required super.interpolation,
  required super.paramCase,
  Map<String, Set<String>>? linkParamMap,
}) {
  final rawParsedResult = _parseInterpolation(
    raw: shouldEscape ? _escapeContent(raw, interpolation) : raw,
    interpolation: interpolation,
    defaultType: 'ignored', // types are ignored
    paramCase: null, // param case will be applied later
  );

  _params = <String>{};
  for (final key in rawParsedResult.params.keys) {
    final parsedParam = parseParamWithArg(
      rawParam: key,
      paramCase: paramCase,
    );
    _params.add(parsedParam.paramName);
    _paramTypeMap[parsedParam.paramName] =
        parsedParam.arg == null ? 'InlineSpan' : 'InlineSpanBuilder';
  }

  if (linkParamMap != null) {
    _params.addAll(linkParamMap.values.expand((e) => e));
  }

  _links = {};
  _spans = _splitWithMatchAndNonMatch(
    rawParsedResult.parsedContent,
    RegexUtils.argumentsDartRegex,
    onNonMatch: (text) {
      final parsedLinksResult = _parseLinks(
        input: text,
        linkParamMap: linkParamMap,
      );
      _links.addAll(parsedLinksResult.links);
      return LiteralSpan(
        literal: parsedLinksResult.parsedContent,
        isConstant: parsedLinksResult.links.isEmpty,
        links: parsedLinksResult.links,
      );
    },
    onMatch: (match) {
      final parsed = parseParamWithArg(
        rawParam: (match.group(1) ?? match.group(2))!,
        paramCase: paramCase,
      );
      final parsedArg = parsed.arg;
      if (parsedArg != null) {
        final parsedLinksResult = _parseLinks(
          input: parsedArg,
          linkParamMap: linkParamMap,
        );
        _links.addAll(parsedLinksResult.links);
        return FunctionSpan(
          functionName: parsed.paramName,
          arg: parsedLinksResult.parsedContent,
          links: parsedLinksResult.links,
        );
      } else {
        return VariableSpan(parsed.paramName);
      }
    },
  ).toList();
}