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
d89f5616
Commit
d89f5616
authored
Jan 19, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve support for linebreaks, tables and nested blockquotes in lists
parent
2b37e4c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
15 deletions
+31
-15
app/assets/javascripts/copy_as_gfm.js.es6
app/assets/javascripts/copy_as_gfm.js.es6
+9
-8
spec/features/copy_as_gfm_spec.rb
spec/features/copy_as_gfm_spec.rb
+22
-7
No files found.
app/assets/javascripts/copy_as_gfm.js.es6
View file @
d89f5616
...
...
@@ -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());
...
...
spec/features/copy_as_gfm_spec.rb
View file @
d89f5616
...
...
@@ -236,8 +236,6 @@ describe 'Copy as GFM', feature: true, js: true do
it
'supports SanitizationFilter'
do
verify
(
<<-
GFM
.
strip_heredoc
BR: <br>
<sub>sub</sub>
<dl>
...
...
@@ -284,6 +282,8 @@ describe 'Copy as GFM', feature: true, js: true do
it
'supports MarkdownFilter'
do
verify
(
"Line with two spaces at the end
\n
to insert a linebreak"
,
'`code`'
,
'`` code with ` ticks ``'
,
...
...
@@ -308,7 +308,7 @@ describe 'Copy as GFM', feature: true, js: true do
# multiline list item
<<-
GFM
.
strip_heredoc
,
- Multiline
List item
List item
GFM
# nested lists
...
...
@@ -316,7 +316,14 @@ describe 'Copy as GFM', feature: true, js: true do
- Nested
- Lists
- Lists
GFM
# list with blockquote
<<-
GFM
.
strip_heredoc
,
- List
> Blockquote
GFM
'1. Numbered list item'
,
...
...
@@ -324,7 +331,7 @@ describe 'Copy as GFM', feature: true, js: true do
# multiline numbered list item
<<-
GFM
.
strip_heredoc
,
1. Multiline
Numbered list item
Numbered list item
GFM
# nested numbered list
...
...
@@ -332,7 +339,7 @@ describe 'Copy as GFM', feature: true, js: true do
1. Nested
1. Numbered lists
1. Numbered lists
GFM
'# Heading'
,
...
...
@@ -355,10 +362,18 @@ describe 'Copy as GFM', feature: true, js: true do
# table
<<-
GFM
.
strip_heredoc
,
| Centered | Right | Left |
|
:------: | ----: | ----
|
|
:--------:|------:|------
|
| Foo | Bar | **Baz** |
| Foo | Bar | **Baz** |
GFM
# table with empty heading
<<-
GFM
.
strip_heredoc
,
| | x | y |
|---|---|---|
| a | 1 | 0 |
| b | 0 | 1 |
GFM
)
end
...
...
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