Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. var markdown_editor = function (labfile, markdown) {
  2. var markdown_arr = Object.keys(markdown);
  3.  
  4. var mapping = markdown_arr.map(function(task_name) {
  5. var task_md = markdown[task_name];
  6. var md_finder = new RegExp("\/\\*( |\n)*?@(" + task_name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + ")( |\n)((.|\n)*?)\\*\/","gm");
  7. return [labfile.match(md_finder)[0], "/*@" + task_name + "\n" + task_md + "*/"];
  8. });
  9. var result = labfile;
  10. mapping.forEach(function(arr) { result = result.replace(arr[0],arr[1]);});
  11. return result;
  12. };
  13.  
  14. var labfile = "hi im bob\n/*@potato this is old potato right here.*/ momo /*@orange\nold orange here */";
  15. var markdown = {potato: "new potato", orange: "new orange is:\nthis"};
  16. var res = markdown_editor(labfile,markdown);
  17. console.log(res);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement