visitText method

  1. @override
StringSink visitText(
  1. QuillText text, [
  2. StringSink? output
])

Implementation

@override
StringSink visitText(QuillText text, [StringSink? output]) {
  final out = output ??= StringBuffer();
  final style = text.style;
  _handleAttribute(
    _textAttrsHandlers,
    text,
    output,
    () {
      var content = text.value;
      if (!(style.containsKey(Attribute.codeBlock.key) ||
          style.containsKey(Attribute.inlineCode.key) ||
          (text.parent?.style.containsKey(Attribute.codeBlock.key) ??
              false))) {
        content = content.replaceAllMapped(
            RegExp(r'[\\\`\*\_\{\}\[\]\(\)\#\+\-\.\!\>\<]'), (match) {
          return '\\${match[0]}';
        });
      }
      out.write(content);
    },
    sortedAttrsBySpan: true,
  );
  return out;
}