Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extract image from text input that is saved? #72

Closed
ativiper opened this issue Jun 24, 2021 · 5 comments
Closed

How to extract image from text input that is saved? #72

ativiper opened this issue Jun 24, 2021 · 5 comments
Labels
question Further information is requested

Comments

@ativiper
Copy link

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

@ativiper ativiper added the question Further information is requested label Jun 24, 2021
@tneotia
Copy link
Owner

tneotia commented Jun 25, 2021

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!

@ativiper
Copy link
Author

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

@tneotia
Copy link
Owner

tneotia commented Jun 25, 2021

Sure no problem, I will post one this evening.

@tneotia
Copy link
Owner

tneotia commented Jun 27, 2021

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.

@tneotia
Copy link
Owner

tneotia commented Jul 2, 2021

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

@tneotia tneotia closed this as completed Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants