Esempio n. 1
0
 public TextDocumentRenameValidator(TextDocument doc)
   : base("The text document's name must not be empty! Please enter a valid name.")
 {
   _doc = doc;
 }
Esempio n. 2
0
 public static void ShowPropertyDialog(this TextDocument doc)
 {
   var propHierarchy = new Altaxo.Main.Properties.PropertyHierarchy(PropertyExtensions.GetPropertyBags(doc));
   Current.Gui.ShowDialog(new object[] { propHierarchy }, "Text document properties", true);
 }
Esempio n. 3
0
        public string Import(string fileName)
        {
            var errors = new System.Text.StringBuilder();

            string markdownDirectory = System.IO.Path.GetDirectoryName(fileName);
            string markdownText      = null;

            using (var stream = new StreamReader(fileName, Encoding.UTF8, true))
            {
                markdownText = stream.ReadToEnd();
            }

            // Parse the markdown

            var pipeline = new MarkdownPipelineBuilder();

            pipeline = UseSupportedExtensions(pipeline);

            var markdownDocument = Markdig.Markdown.Parse(markdownText, pipeline.Build());

            var textDocument = new TextDocument();

            var images = new List <(Markdig.Syntax.Inlines.LinkInline link, MemoryStreamImageProxy proxy)>();

            foreach (var mdo in EnumerateAllMarkdownObjectsRecursively(markdownDocument))
            {
                if (mdo is Markdig.Syntax.Inlines.LinkInline link && link.IsImage)
                {
                    var url = link.Url;

                    if (string.IsNullOrEmpty(url) || !Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
                    {
                        continue;
                    }

                    var uri = new Uri(url, UriKind.RelativeOrAbsolute);

                    string imgFileName = null;

                    if (uri.IsAbsoluteUri)
                    {
                        imgFileName = uri.AbsolutePath;
                    }
                    else
                    {
                        imgFileName = System.IO.Path.Combine(markdownDirectory, uri.OriginalString);
                    }

                    try
                    {
                        var imgProxy = MemoryStreamImageProxy.FromFile(imgFileName);
                        textDocument.AddImage(imgProxy);
                        images.Add((link, imgProxy));
                    }
                    catch (Exception ex)
                    {
                        errors.AppendFormat("File {0} could not be imported, error: {1}\r\n", imgFileName, ex.Message);
                    }
                }
            }

            // now we have to replace all urls
            var text = new System.Text.StringBuilder(markdownText);

            for (int i = images.Count - 1; i >= 0; --i)
            {
                var(link, proxy) = images[i];

                text.Remove(link.UrlSpan.Value.Start, link.UrlSpan.Value.End + 1 - link.UrlSpan.Value.Start);
                text.Insert(link.UrlSpan.Value.Start, ImagePretext.LocalImagePretext + proxy.ContentHash);
            }

            textDocument.SourceText = text.ToString();

            Current.Project.TextDocumentCollection.Add(textDocument);

            Current.ProjectService.ShowDocumentView(textDocument);

            return(errors.Length == 0 ? null : errors.ToString());
        }