summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/copy_as_gfm.js.es6
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-01-19 13:47:54 -0600
committerDouwe Maan <douwe@selenight.nl>2017-01-19 13:47:54 -0600
commitd89f56161297921f3f3ccdf0d186f39ff1c0a4d3 (patch)
treea04cf4f703850c0afb05b125c409d110c689407b /app/assets/javascripts/copy_as_gfm.js.es6
parent2b37e4c1995284a4871d6d7077b0884e95c2496e (diff)
downloadgitlab-ce-d89f56161297921f3f3ccdf0d186f39ff1c0a4d3.tar.gz
Improve support for linebreaks, tables and nested blockquotes in lists
Diffstat (limited to 'app/assets/javascripts/copy_as_gfm.js.es6')
-rw-r--r--app/assets/javascripts/copy_as_gfm.js.es617
1 files changed, 9 insertions, 8 deletions
diff --git a/app/assets/javascripts/copy_as_gfm.js.es6 b/app/assets/javascripts/copy_as_gfm.js.es6
index 80e30fdf390..9cbeb782270 100644
--- a/app/assets/javascripts/copy_as_gfm.js.es6
+++ b/app/assets/javascripts/copy_as_gfm.js.es6
@@ -92,9 +92,6 @@
},
},
SanitizationFilter: {
- 'br'(el, text) {
- return '<br>';
- },
'dl'(el, text) {
let lines = text.trim().split('\n');
// Add two spaces to the front of subsequent list items lines,
@@ -127,6 +124,10 @@
},
},
MarkdownFilter: {
+ 'br'(el, text) {
+ // Two spaces at the end of a line are turned into a BR
+ return ' ';
+ },
'code'(el, text) {
let backtickCount = 1;
const backtickMatch = text.match(/`+/);
@@ -155,12 +156,12 @@
'li'(el, text) {
const lines = text.trim().split('\n');
const firstLine = `- ${lines.shift()}`;
- // Add two spaces to the front of subsequent list items lines,
+ // Add four 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 ` ${s}`;
});
return `${firstLine}\n${nextLines.join('\n')}`;
@@ -213,7 +214,7 @@
},
'thead'(el, text) {
const cells = _.map(el.querySelectorAll('th'), (cell) => {
- let chars = CopyAsGFM.nodeToGFM(cell).trim().length;
+ let chars = CopyAsGFM.nodeToGFM(cell).trim().length + 2;
let before = '';
let after = '';
@@ -231,14 +232,14 @@
break;
}
- chars = Math.max(chars, 0);
+ chars = Math.max(chars, 3);
const middle = Array(chars + 1).join('-');
return before + middle + after;
});
- return `${text}| ${cells.join(' | ')} |`;
+ return `${text}|${cells.join('|')}|`;
},
'tr'(el, text) {
const cells = _.map(el.querySelectorAll('td, th'), cell => CopyAsGFM.nodeToGFM(cell).trim());