Exemplo n.º 1
0
        internal void SetHyperlink()
        {
            var textArea = Editor.TextArea;

            if (textArea.Selection.IsEmpty)
            {
                return;
            }

            var selectedText = textArea.Selection.GetText();

            //  Check if the selected text already is a link...
            string text = selectedText, url = string.Empty;
            var    match = Regex.Match(selectedText, @"\[(?<text>(?:[^\\]|\\.)+)\]\((?<url>[^)]+)\)");

            if (match.Success)
            {
                text = match.Groups["text"].Value;
                url  = match.Groups["url"].Value;
            }
            var hyperlink = new MarkPadHyperlink(text, url);

            (DataContext as DocumentViewModel)
            .ExecuteSafely(vm =>
            {
                hyperlink = vm.GetHyperlink(hyperlink);
                if (hyperlink != null)
                {
                    textArea.Selection.ReplaceSelectionWithText(string.Format("[{0}]({1})", hyperlink.Text, hyperlink.Url));
                }
            });
        }
Exemplo n.º 2
0
        internal void SetHyperlink()
        {
            var textArea = Editor.TextArea;
            if (textArea.Selection.IsEmpty)
                return;

            var selectedText = textArea.Selection.GetText();

            //  Check if the selected text already is a link...
            string text = selectedText, url = string.Empty;
            var match = Regex.Match(selectedText, @"\[(?<text>(?:[^\\]|\\.)+)\]\((?<url>[^)]+)\)");
            if (match.Success)
            {
                text = match.Groups["text"].Value;
                url = match.Groups["url"].Value;
            }
            var hyperlink = new MarkPadHyperlink(text, url);

            (DataContext as DocumentViewModel)
                .ExecuteSafely(vm =>
                {
                    hyperlink = vm.GetHyperlink(hyperlink);
                    if (hyperlink != null)
                    {
                        textArea.Selection.ReplaceSelectionWithText(string.Format("[{0}]({1})", hyperlink.Text, hyperlink.Url));
                    }
                });
        }