RichTextNode constructor

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

Implementation

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

  _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();
}