escapeSpecialCharacters static method

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

escapes any markdown characters during markdown serialization to avoid breaking syntax

Implementation

static void escapeSpecialCharacters(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))) {
    content = content.replaceAllMapped(
        RegExp(r'[\\\`\*\_\{\}\[\]\(\)\#\+\-\.\!\>\<]'), (match) {
      return '\\${match[0]}';
    });
  }
  out.write(content);
}