1

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.

lin
  • 17,956
  • 4
  • 59
  • 83
Lucifer
  • 1,069
  • 4
  • 16
  • 26

1 Answers1

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'
);
Community
  • 1
  • 1
lin
  • 17,956
  • 4
  • 59
  • 83