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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
ed0423c7
Commit
ed0423c7
authored
Jul 22, 2020
by
Jochen Roth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function to transform selected text to markdown and insert it as quote into textarea
parent
05225715
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
3 deletions
+45
-3
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
+4
-0
app/assets/javascripts/lib/utils/text_markdown.js
app/assets/javascripts/lib/utils/text_markdown.js
+3
-1
app/assets/javascripts/vue_shared/components/markdown/header.vue
...ets/javascripts/vue_shared/components/markdown/header.vue
+27
-1
app/assets/javascripts/vue_shared/components/markdown/toolbar_button.vue
...scripts/vue_shared/components/markdown/toolbar_button.vue
+1
-1
spec/frontend/behaviors/copy_as_gfm_spec.js
spec/frontend/behaviors/copy_as_gfm_spec.js
+10
-0
No files found.
app/assets/javascripts/behaviors/markdown/copy_as_gfm.js
View file @
ed0423c7
...
@@ -180,6 +180,10 @@ export class CopyAsGFM {
...
@@ -180,6 +180,10 @@ export class CopyAsGFM {
})
})
.
catch
(()
=>
{});
.
catch
(()
=>
{});
}
}
static
quoted
(
markdown
)
{
return
`>
${
markdown
.
split
(
'
\n
'
).
join
(
'
\n
>
'
)}
`
;
}
}
}
// Export CopyAsGFM as a global for rspec to access
// Export CopyAsGFM as a global for rspec to access
...
...
app/assets/javascripts/lib/utils/text_markdown.js
View file @
ed0423c7
...
@@ -308,9 +308,11 @@ export function addMarkdownListeners(form) {
...
@@ -308,9 +308,11 @@ export function addMarkdownListeners(form) {
.
off
(
'
click
'
)
.
off
(
'
click
'
)
.
on
(
'
click
'
,
function
()
{
.
on
(
'
click
'
,
function
()
{
const
$this
=
$
(
this
);
const
$this
=
$
(
this
);
const
tag
=
this
.
dataset
.
mdTag
;
return
updateText
({
return
updateText
({
textArea
:
$this
.
closest
(
'
.md-area
'
).
find
(
'
textarea
'
),
textArea
:
$this
.
closest
(
'
.md-area
'
).
find
(
'
textarea
'
),
tag
:
$this
.
data
(
'
mdTag
'
)
,
tag
,
cursorOffset
:
$this
.
data
(
'
mdCursorOffset
'
),
cursorOffset
:
$this
.
data
(
'
mdCursorOffset
'
),
blockTag
:
$this
.
data
(
'
mdBlock
'
),
blockTag
:
$this
.
data
(
'
mdBlock
'
),
wrap
:
!
$this
.
data
(
'
mdPrepend
'
),
wrap
:
!
$this
.
data
(
'
mdPrepend
'
),
...
...
app/assets/javascripts/vue_shared/components/markdown/header.vue
View file @
ed0423c7
<
script
>
<
script
>
import
$
from
'
jquery
'
;
import
$
from
'
jquery
'
;
import
{
GlPopover
,
GlButton
,
GlTooltipDirective
}
from
'
@gitlab/ui
'
;
import
{
GlPopover
,
GlButton
,
GlTooltipDirective
}
from
'
@gitlab/ui
'
;
import
{
getSelectedFragment
}
from
'
~/lib/utils/common_utils
'
;
import
{
CopyAsGFM
}
from
'
../../../behaviors/markdown/copy_as_gfm
'
;
import
ToolbarButton
from
'
./toolbar_button.vue
'
;
import
ToolbarButton
from
'
./toolbar_button.vue
'
;
import
Icon
from
'
../icon.vue
'
;
import
Icon
from
'
../icon.vue
'
;
...
@@ -35,6 +37,11 @@ export default {
...
@@ -35,6 +37,11 @@ export default {
default
:
false
,
default
:
false
,
},
},
},
},
data
()
{
return
{
tag
:
'
>
'
,
};
},
computed
:
{
computed
:
{
mdTable
()
{
mdTable
()
{
return
[
return
[
...
@@ -81,6 +88,24 @@ export default {
...
@@ -81,6 +88,24 @@ export default {
handleSuggestDismissed
()
{
handleSuggestDismissed
()
{
this
.
$emit
(
'
handleSuggestDismissed
'
);
this
.
$emit
(
'
handleSuggestDismissed
'
);
},
},
handleQuote
()
{
const
documentFragment
=
getSelectedFragment
();
const
area
=
this
.
$parent
.
$slots
.
textarea
[
0
].
elm
;
if
(
!
documentFragment
||
!
documentFragment
.
textContent
)
{
this
.
tag
=
'
>
'
;
return
;
}
this
.
tag
=
''
;
const
transformed
=
CopyAsGFM
.
transformGFMSelection
(
documentFragment
);
CopyAsGFM
.
nodeToGFM
(
transformed
)
.
then
(
gfm
=>
{
CopyAsGFM
.
insertPastedText
(
area
,
documentFragment
.
textContent
,
CopyAsGFM
.
quoted
(
gfm
));
})
.
catch
(()
=>
{});
},
},
},
};
};
</
script
>
</
script
>
...
@@ -108,9 +133,10 @@ export default {
...
@@ -108,9 +133,10 @@ export default {
<toolbar-button
tag=
"*"
:button-title=
"__('Add italic text')"
icon=
"italic"
/>
<toolbar-button
tag=
"*"
:button-title=
"__('Add italic text')"
icon=
"italic"
/>
<toolbar-button
<toolbar-button
:prepend=
"true"
:prepend=
"true"
tag=
">
"
:tag=
"tag
"
:button-title=
"__('Insert a quote')"
:button-title=
"__('Insert a quote')"
icon=
"quote"
icon=
"quote"
@
update-tag=
"handleQuote"
/>
/>
</div>
</div>
<div
class=
"d-inline-block ml-md-2 ml-0"
>
<div
class=
"d-inline-block ml-md-2 ml-0"
>
...
...
app/assets/javascripts/vue_shared/components/markdown/toolbar_button.vue
View file @
ed0423c7
...
@@ -65,7 +65,7 @@ export default {
...
@@ -65,7 +65,7 @@ export default {
type=
"button"
type=
"button"
class=
"toolbar-btn js-md"
class=
"toolbar-btn js-md"
data-container=
"body"
data-container=
"body"
@
click=
"() => $emit('click')"
@
click=
"
$emit('update-tag'),
() => $emit('click')"
>
>
<icon
:name=
"icon"
/>
<icon
:name=
"icon"
/>
</button>
</button>
...
...
spec/frontend/behaviors/copy_as_gfm_spec.js
View file @
ed0423c7
...
@@ -123,4 +123,14 @@ describe('CopyAsGFM', () => {
...
@@ -123,4 +123,14 @@ describe('CopyAsGFM', () => {
});
});
});
});
});
});
describe
(
'
CopyAsGFM.quoted
'
,
()
=>
{
const
sampleGFM
=
'
* List 1
\n
* List 2
\n\n
`Some code`
'
;
it
(
'
adds quote char `> ` to each line
'
,
done
=>
{
const
expectedQuotedGFM
=
'
> * List 1
\n
> * List 2
\n
>
\n
> `Some code`
'
;
expect
(
CopyAsGFM
.
quoted
(
sampleGFM
)).
toEqual
(
expectedQuotedGFM
);
done
();
});
});
});
});
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