summaryrefslogtreecommitdiff
path: root/app/assets
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-10-26 07:56:32 +0000
committerPhil Hughes <me@iamphill.com>2018-10-26 07:56:32 +0000
commit2bbfca8240c605e3b1c4aed18cadda4f6403e138 (patch)
treee2f0c8686d6b1f6ffd09fe4c6927c8133a4f8693 /app/assets
parentf659f8cf878bcce1e4fbf4763ec8daaeb3300f32 (diff)
parent861772846bd7725eb630a0bda40a3be1ec112af4 (diff)
downloadgitlab-ce-2bbfca8240c605e3b1c4aed18cadda4f6403e138.tar.gz
Merge branch '52115-Link-button-in-markdown-editor-should-recognize-URLs' into 'master'
Link button in markdown editor recognize URLs Closes #52115 See merge request gitlab-org/gitlab-ce!22547
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/lib/utils/text_markdown.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/text_markdown.js b/app/assets/javascripts/lib/utils/text_markdown.js
index e26a6b986be..c52cfb806a2 100644
--- a/app/assets/javascripts/lib/utils/text_markdown.js
+++ b/app/assets/javascripts/lib/utils/text_markdown.js
@@ -2,6 +2,8 @@
import $ from 'jquery';
import { insertText } from '~/lib/utils/common_utils';
+const LINK_TAG_PATTERN = '[{text}](url)';
+
function selectedText(text, textarea) {
return text.substring(textarea.selectionStart, textarea.selectionEnd);
}
@@ -76,6 +78,21 @@ export function insertMarkdownText({ textArea, text, tag, blockTag, selected, wr
removedFirstNewLine = false;
currentLineEmpty = false;
+ // check for link pattern and selected text is an URL
+ // if so fill in the url part instead of the text part of the pattern.
+ if (tag === LINK_TAG_PATTERN) {
+ if (URL) {
+ try {
+ const ignoredUrl = new URL(selected);
+ // valid url
+ tag = '[text]({text})';
+ select = 'text';
+ } catch (e) {
+ // ignore - no valid url
+ }
+ }
+ }
+
// Remove the first newline
if (selected.indexOf('\n') === 0) {
removedFirstNewLine = true;