I am new to angular js and I'm using tinymce in one of my projects.In the editor they can upload any no. of images . I want to check if there is any way to extract all the images using angularJs or tinymce plugin.
Asked
Active
Viewed 691 times
1
-
Are you using https://github.com/angular-ui/ui-tinymce ? – lin Feb 25 '17 at 12:05
-
yes. I am using that one only – Lucifer Feb 25 '17 at 14:34
-
Ok, what exactly you mean by saying "extract images"? Which logical part of a image is needed? – lin Feb 25 '17 at 14:36
-
I want the image src to be extracted – Lucifer Feb 26 '17 at 05:21
1 Answers
1
You can extract all image src attributes by using regex. This simple fiddle demo shows you how to make it work with tinymce. I've took the getAtttrFromString() function from this question.
function getAttrFromString(str, node, attr) {
var regex = new RegExp('<' + node + ' .*?' + attr + '="(.*?)"', "gi"), result, res = [];
while ((result = regex.exec(str))) {
res.push(result[1]);
}
return res;
}
var arrayOfImageSrcs = getAttrFromString(
'<img src="http://placekitten.com/350/300"><img src="http://placekitten.com/350/300">',
'img',
'src'
);