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
Jérome Perrin
gitlab-ce
Commits
bd2880bb
Commit
bd2880bb
authored
Jan 19, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve handling of code blocks containing triple backticks
parent
d89f5616
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
app/assets/javascripts/copy_as_gfm.js.es6
app/assets/javascripts/copy_as_gfm.js.es6
+19
-3
spec/features/copy_as_gfm_spec.rb
spec/features/copy_as_gfm_spec.rb
+11
-1
No files found.
app/assets/javascripts/copy_as_gfm.js.es6
View file @
bd2880bb
...
@@ -116,7 +116,19 @@
...
@@ -116,7 +116,19 @@
if (lang === 'plaintext') {
if (lang === 'plaintext') {
lang = '';
lang = '';
}
}
return `\`\`\`${lang}\n${text.trim()}\n\`\`\``;
text = text.trim();
// Prefixes lines with 4 spaces if the code contains triple backticks
if (lang === '' && text.match(/^```/gm)) {
return text.split('\n').map((s) => {
s = s.trim();
if (s.length === 0) return '';
return ` ${s}`;
}).join('\n');
}
return `\`\`\`${lang}\n${text}\n\`\`\``;
},
},
'pre > code'(el, text) {
'pre > code'(el, text) {
// Don't wrap code blocks in ``
// Don't wrap code blocks in ``
...
@@ -207,8 +219,12 @@
...
@@ -207,8 +219,12 @@
return '-----';
return '-----';
},
},
'table'(el, text) {
'table'(el, text) {
const theadText = CopyAsGFM.nodeToGFM(el.querySelector('thead'));
const theadEl = el.querySelector('thead');
const tbodyText = CopyAsGFM.nodeToGFM(el.querySelector('tbody'));
const tbodyEl = el.querySelector('tbody');
if (!theadEl || !tbodyEl) return false;
const theadText = CopyAsGFM.nodeToGFM(theadEl);
const tbodyText = CopyAsGFM.nodeToGFM(tbodyEl);
return theadText + tbodyText;
return theadText + tbodyText;
},
},
...
...
spec/features/copy_as_gfm_spec.rb
View file @
bd2880bb
...
@@ -270,13 +270,23 @@ describe 'Copy as GFM', feature: true, js: true do
...
@@ -270,13 +270,23 @@ describe 'Copy as GFM', feature: true, js: true do
```
```
GFM
GFM
<<-
GFM
.
strip_heredoc
<<-
GFM
.
strip_heredoc
,
```ruby
```ruby
def foo
def foo
bar
bar
end
end
```
```
GFM
GFM
<<-
GFM
.
strip_heredoc
Foo
This is an example of GFM
```js
Code goes here
```
GFM
)
)
end
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