Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
e8a26546
Commit
e8a26546
authored
Jan 18, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Satisfy eslint
parent
c463dfb6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
65 deletions
+64
-65
app/assets/javascripts/copy_as_gfm.js.es6
app/assets/javascripts/copy_as_gfm.js.es6
+51
-52
app/assets/javascripts/lib/utils/common_utils.js.es6
app/assets/javascripts/lib/utils/common_utils.js.es6
+13
-13
No files found.
app/assets/javascripts/copy_as_gfm.js.es6
View file @
e8a26546
/* eslint-disable class-methods-use-this */
/*jshint esversion: 6 */
/* eslint-disable class-methods-use-this
, object-shorthand, no-unused-vars, no-use-before-define, no-new, max-len, no-restricted-syntax, guard-for-in, no-continue
*/
/*
jshint esversion: 6 */
/*= require lib/utils/common_utils */
...
...
@@ -23,7 +23,7 @@
TaskListFilter: {
'input[type=checkbox].task-list-item-checkbox'(el, text) {
return `[${el.checked ? 'x' : ' '}]`;
}
}
,
},
ReferenceFilter: {
'a.gfm:not([data-link=true])'(el, text) {
...
...
@@ -55,7 +55,7 @@
},
VideoLinkFilter: {
'.video-container'(el, text) {
le
t videoEl = el.querySelector('video');
cons
t videoEl = el.querySelector('video');
if (!videoEl) return false;
return CopyAsGFM.nodeToGFM(videoEl);
...
...
@@ -66,22 +66,22 @@
},
MathFilter: {
'pre.code.math[data-math-style=display]'(el, text) {
return
'```math\n' + text.trim() + '\n```'
;
return
`\`\`\`math\n${text.trim()}\n\`\`\``
;
},
'code.code.math[data-math-style=inline]'(el, text) {
return
'$`' + text + '`$'
;
return
`$\`${text}\`$`
;
},
'span.katex-display span.katex-mathml'(el, text) {
le
t mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
cons
t mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
if (!mathAnnotation) return false;
return
'```math\n' + CopyAsGFM.nodeToGFM(mathAnnotation) + '\n```'
;
return
`\`\`\`math\n${CopyAsGFM.nodeToGFM(mathAnnotation)}\n\`\`\``
;
},
'span.katex-mathml'(el, text) {
le
t mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
cons
t mathAnnotation = el.querySelector('annotation[encoding="application/x-tex"]');
if (!mathAnnotation) return false;
return
'$`' + CopyAsGFM.nodeToGFM(mathAnnotation) + '`$'
;
return
`$\`${CopyAsGFM.nodeToGFM(mathAnnotation)}\`$`
;
},
'span.katex-html'(el, text) {
// We don't want to include the content of this element in the copied text.
...
...
@@ -89,7 +89,7 @@
},
'annotation[encoding="application/x-tex"]'(el, text) {
return text.trim();
}
}
,
},
SyntaxHighlightFilter: {
'pre.code.highlight'(el, text) {
...
...
@@ -97,7 +97,7 @@
if (lang === 'plaintext') {
lang = '';
}
return
'```' + lang + '\n' + text.trim() + '\n```'
;
return
`\`\`\`${lang}\n${text.trim()}\n\`\`\``
;
},
'pre > code'(el, text) {
// Don't wrap code blocks in ``
...
...
@@ -107,18 +107,18 @@
MarkdownFilter: {
'code'(el, text) {
let backtickCount = 1;
le
t backtickMatch = text.match(/`+/);
cons
t backtickMatch = text.match(/`+/);
if (backtickMatch) {
backtickCount = backtickMatch[0].length + 1;
}
le
t backticks = new Array(backtickCount + 1).join('`');
le
t spaceOrNoSpace = backtickCount > 1 ? ' ' : '';
cons
t backticks = new Array(backtickCount + 1).join('`');
cons
t spaceOrNoSpace = backtickCount > 1 ? ' ' : '';
return backticks + spaceOrNoSpace + text + spaceOrNoSpace + backticks;
},
'blockquote'(el, text) {
return text.trim().split('\n').map(
(s)
=> `> ${s}`.trim()).join('\n');
return text.trim().split('\n').map(
s
=> `> ${s}`.trim()).join('\n');
},
'img'(el, text) {
return `![${el.getAttribute('alt')}](${el.getAttribute('src')})`;
...
...
@@ -131,15 +131,14 @@
return `[${text}](${el.getAttribute('href')})`;
},
'li'(el, text) {
let lines = text.trim().split('\n');
let firstLine = '- ' + lines.shift();
// Add two spaces to the front of subsequent list items lines, or leave the line entirely blank.
let nextLines = lines.map(function(s) {
if (s.trim().length === 0) {
return '';
} else {
return ` ${s}`;
}
const lines = text.trim().split('\n');
const firstLine = `- ${lines.shift()}`;
// Add two spaces to the front of subsequent list items lines,
// or leave the line entirely blank.
const nextLines = lines.map((s) => {
if (s.trim().length === 0) return '';
return ` ${s}`;
});
return `${firstLine}\n${nextLines.join('\n')}`;
...
...
@@ -185,13 +184,13 @@
return '-----';
},
'table'(el, text) {
le
t theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead'));
le
t tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody'));
cons
t theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead'));
cons
t tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody'));
return theadText + tbodyText;
},
'thead'(el, text) {
let cells = _.map(el.querySelectorAll('th'), function(cell)
{
const cells = _.map(el.querySelectorAll('th'), (cell) =>
{
let chars = CopyAsGFM.nodeToGFM(cell).trim().length;
let before = '';
...
...
@@ -206,24 +205,24 @@
after = ':';
chars -= 1;
break;
default:
break;
}
chars = Math.max(chars, 0);
le
t middle = new Array(chars + 1).join('-');
cons
t middle = new Array(chars + 1).join('-');
return before + middle + after;
});
return
text + `
| ${cells.join(' | ')} |`;
return
`${text}
| ${cells.join(' | ')} |`;
},
'tr'(el, text) {
let cells = _.map(el.querySelectorAll('td, th'), function(cell) {
return CopyAsGFM.nodeToGFM(cell).trim();
});
const cells = _.map(el.querySelectorAll('td, th'), cell => CopyAsGFM.nodeToGFM(cell).trim());
return `| ${cells.join(' | ')} |`;
},
}
}
,
};
class CopyAsGFM {
...
...
@@ -233,24 +232,24 @@
}
handleCopy(e) {
le
t clipboardData = e.originalEvent.clipboardData;
cons
t clipboardData = e.originalEvent.clipboardData;
if (!clipboardData) return;
le
t documentFragment = window.gl.utils.getSelectedFragment();
cons
t documentFragment = window.gl.utils.getSelectedFragment();
if (!documentFragment) return;
e.preventDefault();
clipboardData.setData('text/plain', documentFragment.textContent);
le
t gfm = CopyAsGFM.nodeToGFM(documentFragment);
cons
t gfm = CopyAsGFM.nodeToGFM(documentFragment);
clipboardData.setData('text/x-gfm', gfm);
}
handlePaste(e) {
le
t clipboardData = e.originalEvent.clipboardData;
cons
t clipboardData = e.originalEvent.clipboardData;
if (!clipboardData) return;
le
t gfm = clipboardData.getData('text/x-gfm');
cons
t gfm = clipboardData.getData('text/x-gfm');
if (!gfm) return;
e.preventDefault();
...
...
@@ -263,21 +262,21 @@
return node.textContent;
}
le
t text = this.innerGFM(node);
cons
t text = this.innerGFM(node);
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
return text;
}
for (
le
t filter in gfmRules) {
le
t rules = gfmRules[filter];
for (
cons
t filter in gfmRules) {
cons
t rules = gfmRules[filter];
for (
le
t selector in rules) {
le
t func = rules[selector];
for (
cons
t selector in rules) {
cons
t func = rules[selector];
if (!window.gl.utils.nodeMatchesSelector(node, selector)) continue;
le
t result = func(node, text);
cons
t result = func(node, text);
if (result === false) continue;
return result;
...
...
@@ -288,16 +287,16 @@
}
static innerGFM(parentNode) {
le
t nodes = parentNode.childNodes;
cons
t nodes = parentNode.childNodes;
le
t clonedParentNode = parentNode.cloneNode(true);
le
t clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0);
cons
t clonedParentNode = parentNode.cloneNode(true);
cons
t clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0);
for (let i = 0; i < nodes.length; i
++
) {
le
t node = nodes[i];
le
t clonedNode = clonedNodes[i];
for (let i = 0; i < nodes.length; i
+= 1
) {
cons
t node = nodes[i];
cons
t clonedNode = clonedNodes[i];
le
t text = this.nodeToGFM(node);
cons
t text = this.nodeToGFM(node);
// `clonedNode.replaceWith(text)` is not yet widely supported
clonedNode.parentNode.replaceChild(document.createTextNode(text), clonedNode);
...
...
app/assets/javascripts/lib/utils/common_utils.js.es6
View file @
e8a26546
...
...
@@ -163,34 +163,34 @@
w.gl.utils.getSelectedFragment = () => {
if (!window.getSelection) return null;
le
t selection = window.getSelection();
cons
t selection = window.getSelection();
if (!selection.rangeCount || selection.rangeCount === 0) return null;
le
t documentFragment = selection.getRangeAt(0).cloneContents();
cons
t documentFragment = selection.getRangeAt(0).cloneContents();
if (!documentFragment) return null;
if (documentFragment.textContent.length === 0) return null;
return documentFragment;
}
}
;
w.gl.utils.insertText = (target, text) => {
// Firefox doesn't support `document.execCommand('insertText', false, text)` on textareas
le
t selectionStart = target.selectionStart;
le
t selectionEnd = target.selectionEnd;
le
t value = target.value;
cons
t selectionStart = target.selectionStart;
cons
t selectionEnd = target.selectionEnd;
cons
t value = target.value;
le
t textBefore = value.substring(0, selectionStart);
let textAfter
= value.substring(selectionEnd, value.length);
le
t newText = textBefore + text + textAfter;
cons
t textBefore = value.substring(0, selectionStart);
const textAfter
= value.substring(selectionEnd, value.length);
cons
t newText = textBefore + text + textAfter;
target.value = newText;
target.selectionStart = target.selectionEnd = selectionStart + text.length;
}
}
;
w.gl.utils.nodeMatchesSelector = (node, selector) => {
le
t matches = Element.prototype.matches ||
cons
t matches = Element.prototype.matches ||
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
...
...
@@ -210,9 +210,9 @@
parentNode.appendChild(node);
}
le
t matchingNodes = parentNode.querySelectorAll(selector);
cons
t matchingNodes = parentNode.querySelectorAll(selector);
return Array.prototype.indexOf.call(matchingNodes, node) !== -1;
}
}
;
})(window);
}).call(this);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment