Akash Bansal
Akash Bansal

Reputation: 138

How to store markdown text in Firestore?

I am using Flutter-Fire stack (Flutter for Frontend and Firebase For Backend) I want to use Markdown Text in my app and data needs to be fetched from Firestore. now When I send data to Firestore using admin or directly paste in the field of Firestore Document then All data mashup means white space got removed and In such a situation data shown by the app is totally different from what I want. I am using this package Markdown screenshots For more Explanation are:

what I want and raw data:

Upvotes: 2

Views: 4018

Answers (2)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12373

Store them in Firebase Storage, as .md files, they'll be downloaded as they are. Just as if you are fetching images or any other blobs, works great. Check it out, documentation here.

Upvotes: 6

Meet Chaudhari
Meet Chaudhari

Reputation: 1

You can use this approach with firebase by explicitly converting the multiline content using following javascript function as an example, you can easily write it in dart and simply use this function to store content and parse it again whenever required

function multilineToSingleLine(text) {
    return text.replace(/\n/g, '#NEWLINE#');
}

function singleLineToMultiline(text) {
    return text.replace(/#NEWLINE#/g, '\n');
}

Upvotes: 0

Related Questions