Advertisement
braveheart1989

wikiParser

Oct 25th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wikiParser(selector) {
  2.     let content = $(selector);
  3.     let text = content.text();
  4.  
  5.     text=replaceTag(text,"'''","b");
  6.     text=replaceTag(text,"''","i");
  7.     text=replaceTag(text,"===","h3");
  8.     text=replaceTag(text,"==","h2");
  9.     text=replaceTag(text,"=","h1");
  10.  
  11.  
  12.  
  13.     function replaceTag(str,symbol,tag) {
  14.         let pattern = `${symbol}(.*?)${symbol}`;
  15.         let regex = new RegExp(pattern,'g');
  16.         return str=str.replace(regex,(m,g) => `<${tag}>${g}</${tag}>`);
  17.  
  18.     }
  19.  
  20.     content.html(text);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement