It is supposed that my function should calmly replace the content of each element detected by the each, and in turn, also look for the appearance of attachment to later perform a function with each attachment sought, but not what works within while
works if I do not put return Cualquiercosa
, and if I put return
, what follows after while , is omitted with the last function being $(this).html(content)
. I do not really know what's happening, or what's going on, it's as if I did not read some lines ...
$(".x").each(function(){
content = $(this).text();
content = content.replace(/\@(.*?)\#([0-9]{5})/g, '<a class="x" x="@$1#$2">$&</a>');
content = content.replace(/\*{2}(.*?)\*{2}/g, '<text-b>$1</text-b>');
content = content.replace(/\-{2}(.*?)\-{2}/g, '<text-t>$1</text-t>');
content = content.replace(/\~{2}(.*?)\~{2}/g, '<text-s>$1</text-s>');
attachment = /\{{2}attachment:(.*?)\}{2}/g;
attachmentsCount = (content.match(attachment) || []).length;
while((image = attachment.exec(content))) {
$("<img>").attr("src", "url=" + image[1]).appendTo($(this).children("x"));
}
var content = content.replace(attachment, '')
$(this).html(content);
})