Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Replacement.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* jshint -W101 */
  2. var Smileys = require("./smileys.json");
  3. /**
  4. * Processes links and smileys in "body"
  5. */
  6. function processReplacements(body)
  7. {
  8. //make links clickable
  9. body = linkify(body);
  10. //add smileys
  11. body = smilify(body);
  12. return body;
  13. }
  14. /**
  15. * Finds and replaces all links in the links in "body"
  16. * with their <a href=""></a>
  17. */
  18. function linkify(inputText)
  19. {
  20. var replacedText, replacePattern1, replacePattern2, replacePattern3;
  21. //URLs starting with http://, https://, or ftp://
  22. replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
  23. replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
  24. //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
  25. replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
  26. replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
  27. //Change email addresses to mailto:: links.
  28. replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
  29. replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
  30. return replacedText;
  31. }
  32. /**
  33. * Replaces common smiley strings with images
  34. */
  35. function smilify(body)
  36. {
  37. if(!body) {
  38. return body;
  39. }
  40. var regexs = Smileys.regexs;
  41. for(var smiley in regexs) {
  42. if(regexs.hasOwnProperty(smiley)) {
  43. body = body.replace(regexs[smiley],
  44. '<img class="smiley" src="images/smileys/' + smiley + '.svg">');
  45. }
  46. }
  47. return body;
  48. }
  49. module.exports = {
  50. processReplacements: processReplacements,
  51. linkify: linkify
  52. };