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
Show 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 */
/* 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 */
/*
jshint esversion: 6 */
/*= require lib/utils/common_utils */
/*= require lib/utils/common_utils */
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
TaskListFilter: {
TaskListFilter: {
'input[type=checkbox].task-list-item-checkbox'(el, text) {
'input[type=checkbox].task-list-item-checkbox'(el, text) {
return `[${el.checked ? 'x' : ' '}]`;
return `[${el.checked ? 'x' : ' '}]`;
}
}
,
},
},
ReferenceFilter: {
ReferenceFilter: {
'a.gfm:not([data-link=true])'(el, text) {
'a.gfm:not([data-link=true])'(el, text) {
...
@@ -55,7 +55,7 @@
...
@@ -55,7 +55,7 @@
},
},
VideoLinkFilter: {
VideoLinkFilter: {
'.video-container'(el, text) {
'.video-container'(el, text) {
le
t videoEl = el.querySelector('video');
cons
t videoEl = el.querySelector('video');
if (!videoEl) return false;
if (!videoEl) return false;
return CopyAsGFM.nodeToGFM(videoEl);
return CopyAsGFM.nodeToGFM(videoEl);
...
@@ -66,22 +66,22 @@
...
@@ -66,22 +66,22 @@
},
},
MathFilter: {
MathFilter: {
'pre.code.math[data-math-style=display]'(el, text) {
'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) {
'code.code.math[data-math-style=inline]'(el, text) {
return
'$`' + text + '`$'
;
return
`$\`${text}\`$`
;
},
},
'span.katex-display span.katex-mathml'(el, 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;
if (!mathAnnotation) return false;
return
'```math\n' + CopyAsGFM.nodeToGFM(mathAnnotation) + '\n```'
;
return
`\`\`\`math\n${CopyAsGFM.nodeToGFM(mathAnnotation)}\n\`\`\``
;
},
},
'span.katex-mathml'(el, text) {
'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;
if (!mathAnnotation) return false;
return
'$`' + CopyAsGFM.nodeToGFM(mathAnnotation) + '`$'
;
return
`$\`${CopyAsGFM.nodeToGFM(mathAnnotation)}\`$`
;
},
},
'span.katex-html'(el, text) {
'span.katex-html'(el, text) {
// We don't want to include the content of this element in the copied text.
// We don't want to include the content of this element in the copied text.
...
@@ -89,7 +89,7 @@
...
@@ -89,7 +89,7 @@
},
},
'annotation[encoding="application/x-tex"]'(el, text) {
'annotation[encoding="application/x-tex"]'(el, text) {
return text.trim();
return text.trim();
}
}
,
},
},
SyntaxHighlightFilter: {
SyntaxHighlightFilter: {
'pre.code.highlight'(el, text) {
'pre.code.highlight'(el, text) {
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
if (lang === 'plaintext') {
if (lang === 'plaintext') {
lang = '';
lang = '';
}
}
return
'```' + lang + '\n' + text.trim() + '\n```'
;
return
`\`\`\`${lang}\n${text.trim()}\n\`\`\``
;
},
},
'pre > code'(el, text) {
'pre > code'(el, text) {
// Don't wrap code blocks in ``
// Don't wrap code blocks in ``
...
@@ -107,18 +107,18 @@
...
@@ -107,18 +107,18 @@
MarkdownFilter: {
MarkdownFilter: {
'code'(el, text) {
'code'(el, text) {
let backtickCount = 1;
let backtickCount = 1;
le
t backtickMatch = text.match(/`+/);
cons
t backtickMatch = text.match(/`+/);
if (backtickMatch) {
if (backtickMatch) {
backtickCount = backtickMatch[0].length + 1;
backtickCount = backtickMatch[0].length + 1;
}
}
le
t backticks = new Array(backtickCount + 1).join('`');
cons
t backticks = new Array(backtickCount + 1).join('`');
le
t spaceOrNoSpace = backtickCount > 1 ? ' ' : '';
cons
t spaceOrNoSpace = backtickCount > 1 ? ' ' : '';
return backticks + spaceOrNoSpace + text + spaceOrNoSpace + backticks;
return backticks + spaceOrNoSpace + text + spaceOrNoSpace + backticks;
},
},
'blockquote'(el, text) {
'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) {
'img'(el, text) {
return `![${el.getAttribute('alt')}](${el.getAttribute('src')})`;
return `![${el.getAttribute('alt')}](${el.getAttribute('src')})`;
...
@@ -131,15 +131,14 @@
...
@@ -131,15 +131,14 @@
return `[${text}](${el.getAttribute('href')})`;
return `[${text}](${el.getAttribute('href')})`;
},
},
'li'(el, text) {
'li'(el, text) {
le
t lines = text.trim().split('\n');
cons
t lines = text.trim().split('\n');
let firstLine = '- ' + lines.shift()
;
const firstLine = `- ${lines.shift()}`
;
// Add two spaces to the front of subsequent list items lines,
or leave the line entirely blank.
// Add two spaces to the front of subsequent list items lines,
let nextLines = lines.map(function(s) {
// or leave the line entirely blank.
if (s.trim().length === 0)
{
const nextLines = lines.map((s) =>
{
return '';
if (s.trim().length === 0)
return '';
} else {
return ` ${s}`;
return ` ${s}`;
}
});
});
return `${firstLine}\n${nextLines.join('\n')}`;
return `${firstLine}\n${nextLines.join('\n')}`;
...
@@ -185,13 +184,13 @@
...
@@ -185,13 +184,13 @@
return '-----';
return '-----';
},
},
'table'(el, text) {
'table'(el, text) {
le
t theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead'));
cons
t theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead'));
le
t tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody'));
cons
t tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody'));
return theadText + tbodyText;
return theadText + tbodyText;
},
},
'thead'(el, text) {
'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 chars = CopyAsGFM.nodeToGFM(cell).trim().length;
let before = '';
let before = '';
...
@@ -206,24 +205,24 @@
...
@@ -206,24 +205,24 @@
after = ':';
after = ':';
chars -= 1;
chars -= 1;
break;
break;
default:
break;
}
}
chars = Math.max(chars, 0);
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 before + middle + after;
});
});
return
text + `
| ${cells.join(' | ')} |`;
return
`${text}
| ${cells.join(' | ')} |`;
},
},
'tr'(el, text) {
'tr'(el, text) {
let cells = _.map(el.querySelectorAll('td, th'), function(cell) {
const cells = _.map(el.querySelectorAll('td, th'), cell => CopyAsGFM.nodeToGFM(cell).trim());
return CopyAsGFM.nodeToGFM(cell).trim();
});
return `| ${cells.join(' | ')} |`;
return `| ${cells.join(' | ')} |`;
},
},
}
}
,
};
};
class CopyAsGFM {
class CopyAsGFM {
...
@@ -233,24 +232,24 @@
...
@@ -233,24 +232,24 @@
}
}
handleCopy(e) {
handleCopy(e) {
le
t clipboardData = e.originalEvent.clipboardData;
cons
t clipboardData = e.originalEvent.clipboardData;
if (!clipboardData) return;
if (!clipboardData) return;
le
t documentFragment = window.gl.utils.getSelectedFragment();
cons
t documentFragment = window.gl.utils.getSelectedFragment();
if (!documentFragment) return;
if (!documentFragment) return;
e.preventDefault();
e.preventDefault();
clipboardData.setData('text/plain', documentFragment.textContent);
clipboardData.setData('text/plain', documentFragment.textContent);
le
t gfm = CopyAsGFM.nodeToGFM(documentFragment);
cons
t gfm = CopyAsGFM.nodeToGFM(documentFragment);
clipboardData.setData('text/x-gfm', gfm);
clipboardData.setData('text/x-gfm', gfm);
}
}
handlePaste(e) {
handlePaste(e) {
le
t clipboardData = e.originalEvent.clipboardData;
cons
t clipboardData = e.originalEvent.clipboardData;
if (!clipboardData) return;
if (!clipboardData) return;
le
t gfm = clipboardData.getData('text/x-gfm');
cons
t gfm = clipboardData.getData('text/x-gfm');
if (!gfm) return;
if (!gfm) return;
e.preventDefault();
e.preventDefault();
...
@@ -263,21 +262,21 @@
...
@@ -263,21 +262,21 @@
return node.textContent;
return node.textContent;
}
}
le
t text = this.innerGFM(node);
cons
t text = this.innerGFM(node);
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
return text;
return text;
}
}
for (
le
t filter in gfmRules) {
for (
cons
t filter in gfmRules) {
le
t rules = gfmRules[filter];
cons
t rules = gfmRules[filter];
for (
le
t selector in rules) {
for (
cons
t selector in rules) {
le
t func = rules[selector];
cons
t func = rules[selector];
if (!window.gl.utils.nodeMatchesSelector(node, selector)) continue;
if (!window.gl.utils.nodeMatchesSelector(node, selector)) continue;
le
t result = func(node, text);
cons
t result = func(node, text);
if (result === false) continue;
if (result === false) continue;
return result;
return result;
...
@@ -288,16 +287,16 @@
...
@@ -288,16 +287,16 @@
}
}
static innerGFM(parentNode) {
static innerGFM(parentNode) {
le
t nodes = parentNode.childNodes;
cons
t nodes = parentNode.childNodes;
le
t clonedParentNode = parentNode.cloneNode(true);
cons
t clonedParentNode = parentNode.cloneNode(true);
le
t clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0);
cons
t clonedNodes = Array.prototype.slice.call(clonedParentNode.childNodes, 0);
for (let i = 0; i < nodes.length; i
++
) {
for (let i = 0; i < nodes.length; i
+= 1
) {
le
t node = nodes[i];
cons
t node = nodes[i];
le
t clonedNode = clonedNodes[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.replaceWith(text)` is not yet widely supported
clonedNode.parentNode.replaceChild(document.createTextNode(text), clonedNode);
clonedNode.parentNode.replaceChild(document.createTextNode(text), clonedNode);
...
...
app/assets/javascripts/lib/utils/common_utils.js.es6
View file @
e8a26546
...
@@ -163,34 +163,34 @@
...
@@ -163,34 +163,34 @@
w.gl.utils.getSelectedFragment = () => {
w.gl.utils.getSelectedFragment = () => {
if (!window.getSelection) return null;
if (!window.getSelection) return null;
le
t selection = window.getSelection();
cons
t selection = window.getSelection();
if (!selection.rangeCount || selection.rangeCount === 0) return null;
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) return null;
if (documentFragment.textContent.length === 0) return null;
if (documentFragment.textContent.length === 0) return null;
return documentFragment;
return documentFragment;
}
}
;
w.gl.utils.insertText = (target, text) => {
w.gl.utils.insertText = (target, text) => {
// Firefox doesn't support `document.execCommand('insertText', false, text)` on textareas
// Firefox doesn't support `document.execCommand('insertText', false, text)` on textareas
le
t selectionStart = target.selectionStart;
cons
t selectionStart = target.selectionStart;
le
t selectionEnd = target.selectionEnd;
cons
t selectionEnd = target.selectionEnd;
le
t value = target.value;
cons
t value = target.value;
le
t textBefore = value.substring(0, selectionStart);
cons
t textBefore = value.substring(0, selectionStart);
let textAfter
= value.substring(selectionEnd, value.length);
const textAfter
= value.substring(selectionEnd, value.length);
le
t newText = textBefore + text + textAfter;
cons
t newText = textBefore + text + textAfter;
target.value = newText;
target.value = newText;
target.selectionStart = target.selectionEnd = selectionStart + text.length;
target.selectionStart = target.selectionEnd = selectionStart + text.length;
}
}
;
w.gl.utils.nodeMatchesSelector = (node, selector) => {
w.gl.utils.nodeMatchesSelector = (node, selector) => {
le
t matches = Element.prototype.matches ||
cons
t matches = Element.prototype.matches ||
Element.prototype.matchesSelector ||
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.msMatchesSelector ||
...
@@ -210,9 +210,9 @@
...
@@ -210,9 +210,9 @@
parentNode.appendChild(node);
parentNode.appendChild(node);
}
}
le
t matchingNodes = parentNode.querySelectorAll(selector);
cons
t matchingNodes = parentNode.querySelectorAll(selector);
return Array.prototype.indexOf.call(matchingNodes, node) !== -1;
return Array.prototype.indexOf.call(matchingNodes, node) !== -1;
}
}
;
})(window);
})(window);
}).call(this);
}).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