Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // VeiwCustomizerに登録すること
- $(function(){
- $(document).on('paste', '#issue_description, #issue_notes', function(event){
- const e = event.originalEvent;
- if (e.clipboardData.types.indexOf('text/html') == -1) {
- return;
- }
- const df = document.createDocumentFragment();
- const htmlTag = document.createElement('html');
- htmlTag.innerHTML = e.clipboardData.getData('text/html');
- df.appendChild(htmlTag);
- const css = df.querySelector('style').textContent.replace(/[\r\n\t ]+/g,' ').replace(/mso-.*?;/g,'');
- const textileTable = Array.prototype.map.call(df.querySelectorAll('table'), function(table){
- var txt = "";
- table.querySelectorAll('tr').forEach(function(tr){
- txt += '|';
- tr.querySelectorAll('td').forEach(function(td){
- var attribute = "";
- if (td.colSpan > 1) {
- attribute += '\\' + td.colSpan;
- }
- if (td.rowSpan > 1) {
- attribute += '/' + td.rowSpan;
- }
- if (td.className) {
- const pattern = new RegExp(td.className + '[ ]*\{(.*?)\}');
- //const pattern = '/' + td.className + '[ ]*\{(.*?)\}/';
- attribute += '{' + css.match(pattern)[1].trim() + '}';
- }
- if (attribute) {
- txt += attribute + ".";
- }
- txt += td.innerText + "|";
- });
- txt += '\n';
- });
- txt += '\n';
- return txt;
- });
- var start = this.selectionStart;
- var end = this.selectionEnd;
- const $this = $(this);
- $this.val($this.val().substring(0, start) + textileTable[0] + $this.val().substring(end));
- e.preventDefault();
- });
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement