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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
4678e22b
Commit
4678e22b
authored
Jun 27, 2016
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markdown toolbar inserts code blocks
Closes #19173
parent
a9dbd394
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
12 deletions
+37
-12
app/assets/javascripts/lib/utils/text_utility.js.coffee
app/assets/javascripts/lib/utils/text_utility.js.coffee
+35
-10
app/views/projects/_md_preview.html.haml
app/views/projects/_md_preview.html.haml
+2
-2
No files found.
app/assets/javascripts/lib/utils/text_utility.js.coffee
View file @
4678e22b
...
...
@@ -10,17 +10,41 @@
gl
.
text
.
selectedText
=
(
text
,
textarea
)
->
text
.
substring
(
textarea
.
selectionStart
,
textarea
.
selectionEnd
)
gl
.
text
.
insertText
=
(
textArea
,
text
,
tag
,
selected
,
wrap
)
->
gl
.
text
.
lineBefore
=
(
text
,
textarea
)
->
split
=
text
.
substring
(
0
,
textarea
.
selectionStart
).
trim
().
split
(
'
\n
'
)
split
[
split
.
length
-
1
]
gl
.
text
.
lineAfter
=
(
text
,
textarea
)
->
text
.
substring
(
textarea
.
selectionEnd
).
trim
().
split
(
'
\n
'
)[
0
]
gl
.
text
.
blockTagText
=
(
text
,
textArea
,
blockTag
,
selected
)
->
lineBefore
=
@
lineBefore
(
text
,
textArea
)
lineAfter
=
@
lineAfter
(
text
,
textArea
)
if
lineBefore
is
blockTag
and
lineAfter
is
blockTag
# To remove the block tag we have to select the line before & after
if
blockTag
?
textArea
.
selectionStart
=
textArea
.
selectionStart
-
(
blockTag
.
length
+
1
)
textArea
.
selectionEnd
=
textArea
.
selectionEnd
+
(
blockTag
.
length
+
1
)
selected
else
"
#{
blockTag
}
\n
#{
selected
}
\n
#{
blockTag
}
"
gl
.
text
.
insertText
=
(
textArea
,
text
,
tag
,
blockTag
,
selected
,
wrap
)
->
selectedSplit
=
selected
.
split
(
'
\n
'
)
startChar
=
if
not
wrap
and
textArea
.
selectionStart
>
0
then
'
\n
'
else
''
if
selectedSplit
.
length
>
1
and
not
wrap
insertText
=
selectedSplit
.
map
((
val
)
->
if
val
.
indexOf
(
tag
)
is
0
"
#{
val
.
replace
(
tag
,
''
)
}
"
else
"
#{
tag
}#{
val
}
"
).
join
(
'
\n
'
)
if
selectedSplit
.
length
>
1
and
(
not
wrap
or
blockTag
?
)
if
blockTag
?
insertText
=
@
blockTagText
(
text
,
textArea
,
blockTag
,
selected
)
else
insertText
=
selectedSplit
.
map
((
val
)
->
if
val
.
indexOf
(
tag
)
is
0
"
#{
val
.
replace
(
tag
,
''
)
}
"
else
"
#{
tag
}#{
val
}
"
).
join
(
'
\n
'
)
else
insertText
=
"
#{
startChar
}#{
tag
}#{
selected
}#{
if
wrap
then
tag
else
' '
}
"
...
...
@@ -51,7 +75,7 @@
textArea
.
setSelectionRange
pos
,
pos
gl
.
text
.
updateText
=
(
textArea
,
tag
,
wrap
)
->
gl
.
text
.
updateText
=
(
textArea
,
tag
,
blockTag
,
wrap
)
->
$textArea
=
$
(
textArea
)
oldVal
=
$textArea
.
val
()
textArea
=
$textArea
.
get
(
0
)
...
...
@@ -59,7 +83,7 @@
selected
=
@
selectedText
(
text
,
textArea
)
$textArea
.
focus
()
@
insertText
(
textArea
,
text
,
tag
,
selected
,
wrap
)
@
insertText
(
textArea
,
text
,
tag
,
blockTag
,
selected
,
wrap
)
gl
.
text
.
init
=
(
form
)
->
self
=
@
...
...
@@ -70,6 +94,7 @@
self
.
updateText
(
$this
.
closest
(
'.md-area'
).
find
(
'textarea'
),
$this
.
data
(
'md-tag'
),
$this
.
data
(
'md-block'
),
not
$this
.
data
(
'md-prepend'
)
)
...
...
app/views/projects/_md_preview.html.haml
View file @
4678e22b
...
...
@@ -12,13 +12,13 @@
%li
.confidential-issue-warning
=
icon
(
'warning'
)
%span
This is a confidential issue. Your comment will not be visible to the public.
%li
.pull-right
.toolbar-group
=
markdown_toolbar_button
({
icon:
"bold fw"
,
data:
{
"md-tag"
=>
"**"
},
title:
"Add bold text"
})
=
markdown_toolbar_button
({
icon:
"italic fw"
,
data:
{
"md-tag"
=>
"*"
},
title:
"Add italic text"
})
=
markdown_toolbar_button
({
icon:
"quote-right fw"
,
data:
{
"md-tag"
=>
"> "
,
"md-prepend"
=>
true
},
title:
"Insert a quote"
})
=
markdown_toolbar_button
({
icon:
"code fw"
,
data:
{
"md-tag"
=>
"`"
},
title:
"Insert code"
})
=
markdown_toolbar_button
({
icon:
"code fw"
,
data:
{
"md-tag"
=>
"`"
,
"md-block"
=>
"```"
},
title:
"Insert code"
})
=
markdown_toolbar_button
({
icon:
"list-ul fw"
,
data:
{
"md-tag"
=>
"* "
,
"md-prepend"
=>
true
},
title:
"Add a bullet list"
})
=
markdown_toolbar_button
({
icon:
"list-ol fw"
,
data:
{
"md-tag"
=>
"1. "
,
"md-prepend"
=>
true
},
title:
"Add a numbered list"
})
=
markdown_toolbar_button
({
icon:
"check-square-o fw"
,
data:
{
"md-tag"
=>
"* [ ] "
,
"md-prepend"
=>
true
},
title:
"Add a task list"
})
...
...
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