Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. // VeiwCustomizerに登録すること
  2.  
  3. $(function(){
  4.  
  5. $(document).on('paste', '#issue_description, #issue_notes', function(event){
  6.  
  7. const e = event.originalEvent;
  8. if (e.clipboardData.types.indexOf('text/html') == -1) {
  9. return;
  10. }
  11. const df = document.createDocumentFragment();
  12. const htmlTag = document.createElement('html');
  13. htmlTag.innerHTML = e.clipboardData.getData('text/html');
  14. df.appendChild(htmlTag);
  15.  
  16. const css = df.querySelector('style').textContent.replace(/[\r\n\t ]+/g,' ').replace(/mso-.*?;/g,'');
  17.  
  18. const textileTable = Array.prototype.map.call(df.querySelectorAll('table'), function(table){
  19. var txt = "";
  20. table.querySelectorAll('tr').forEach(function(tr){
  21. txt += '|';
  22. tr.querySelectorAll('td').forEach(function(td){
  23. var attribute = "";
  24. if (td.colSpan > 1) {
  25. attribute += '\\' + td.colSpan;
  26. }
  27. if (td.rowSpan > 1) {
  28. attribute += '/' + td.rowSpan;
  29. }
  30. if (td.className) {
  31. const pattern = new RegExp(td.className + '[ ]*\{(.*?)\}');
  32. //const pattern = '/' + td.className + '[ ]*\{(.*?)\}/';
  33. attribute += '{' + css.match(pattern)[1].trim() + '}';
  34. }
  35. if (attribute) {
  36. txt += attribute + ".";
  37. }
  38. txt += td.innerText + "|";
  39. });
  40. txt += '\n';
  41. });
  42. txt += '\n';
  43. return txt;
  44. });
  45.  
  46. var start = this.selectionStart;
  47. var end = this.selectionEnd;
  48. const $this = $(this);
  49. $this.val($this.val().substring(0, start) + textileTable[0] + $this.val().substring(end));
  50. e.preventDefault();
  51. });
  52. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement