Skip to content

Instantly share code, notes, and snippets.

@cenrak
Created April 23, 2012 04:28
Show Gist options
  • Save cenrak/2468868 to your computer and use it in GitHub Desktop.
Save cenrak/2468868 to your computer and use it in GitHub Desktop.
Hash Tag replacer
// فين المفروض المكتبة تبحث عن الهاش تاق. حاليا تدعم مكان واحد بس
var whereToSearch = 'p.reply';
// التعبير القياسي لشكل الهاش تاق
var howItLooksLike = '\\#[A-Za-z0-9\u0600-\u06ff_]+';
// موقعك
var site = "http://website.com/";
// ما تضيفه المكتبة في الرابط بعد رابط موقعك و قبل إضافة الهاش تاق
var pre_tag = '';
// ما تضيفه المكتبة بعد إضافة الهاش تاق إلى الرابط
var post_tag = '';
// ----------------
// لا تغير أي شئ هنا
$(whereToSearch).each(function() {
var tag_regex = new RegExp(howItLooksLike, 'g');
var tag;
while ((tag = tag_regex.exec($(this).text())) !== null) {
tag = tag + '';
$(this).html($(this).html().replace(tag, '<a href="' + site + pre_tag + tag.replace('#', '') + post_tag + '">' + tag + '</a>'));
}
});​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment