escapeSpecialCharactersRelaxed static method

void escapeSpecialCharactersRelaxed(
  1. QuillText text,
  2. StringSink out
)

escapes markdown characters during markdown serialization but tries to avoid escaping characters when text is not formatted at all

Implementation

static void escapeSpecialCharactersRelaxed(QuillText text, StringSink out) {
  final style = text.style;
  var content = text.value;
  if (!(style.containsKey(Attribute.codeBlock.key) ||
      style.containsKey(Attribute.inlineCode.key) ||
      (text.parent?.style.containsKey(Attribute.codeBlock.key) ?? false))) {
    if (style.attributes.isNotEmpty) {
      content = content.replaceAllMapped(
          RegExp(r'[\\\`\*\_\{\}\[\]\(\)\#\+\-\.\!\>\<]'), (match) {
        return '\\${match[0]}';
      });
    }
  }
  out.write(content);
}