markdownToQuill function

String? markdownToQuill(
  1. String? content
)

Implementation

String? markdownToQuill(String? content) {
  try {
    return jsonEncode(notusMarkdown.decode(content))
        .toString()
        .replaceAll('"heading":1', '"header":1')
        .replaceAll('"heading":2', '"header":2')
        .replaceAll('"heading":3', '"header":3')
        .replaceAll('"b":true', '"bold":true')
        .replaceAll('"i":true', '"italic":true')
        .replaceAll('"block":"quote"', '"blockquote":"true"')
        .replaceAll('"block":"ul"', '"list":"bullet"')
        .replaceAll('"block":"ol"', '"list":"ordered"')
        .replaceAll('"block":"code"', '"code-block":true')
        .replaceAllMapped(RegExp(r',"attributes":{(.*?)"a":"(.+?)"(.*?)}'),
            (Match m) => ',"attributes":{${m[1]}"link":"${m[2]}"${m[3]}}')
        .replaceAll('{"insert":"​","attributes":{"embed":{"type":"hr"}}},', '')
        .replaceAll('{"insert":"​","attributes":{"embed":{"type":"hr"}}}', '');
  } catch (error) {
    print(error);
    return null;
  }
}