tneotia/html-editor-enhanced

How to extract image from text input that is saved?

ativiper opened this issue · 5 comments

I have saved text input using the toolbar in an ios app. If I want to return certain parts of the saved text, like the title and first image that I have saved. How can I achieve this?

Thanks

You would have to parse the HTML yourself using the html package. You can check the elements for the first image and first title item and extract those.

Let me know if you need more help!

I have saved text input using the toolbar in an ios app. If I want to return certain parts of the saved text, like the title and first image that I have saved. How can I achieve this?

Thanks

Hi

If you could explain further, maybe with an example it would be a great help.

Thank you

Sure no problem, I will post one this evening.

Sorry for getting back to you so late. Something like this could work:

import 'package:html/parser.dart' as htmlparser;

String html = "<h1>Title</h1><p>some stuff we don't want</p><img src='image_src'/>";

var parsed = htmlparser.parse(html);
var title = parsed.getElementsByTagName("h1")[0];
var image = parsed.getElementsByTagName("img")[0];
//don't know if this works, I haven't tested this behavior yet
String partialHtml = title.toString() + image.toString();

If that last line doesn't work then maybe .outerHtml would work? Let me know if it doesn't help or you have any other questions.

Closing for now. Feel free to update here if the above answer doesn't work!