Example #1
0
        /// <summary>
        /// Exports the specified <see cref="TextDocument"/> to an external markdown file.
        /// </summary>
        /// <param name="document">The document to export.</param>
        /// <param name="fileName">Full name of the Maml file to export to. Note that if exporting to multiple Maml files,
        /// this is the base file name only; the file names will be derived from this name.</param>
        /// <param name="errors">A list that collects error messages.</param>
        public void Export(TextDocument document, string fileName, List <MarkdownError> errors = null)
        {
            if (null == document)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            var basePathName = Path.GetDirectoryName(fileName);


            if (ExpandChildDocuments)
            {
                document = ChildDocumentExpander.ExpandDocumentToNewDocument(document, errors: errors);
            }

            if (RenumerateFigures)
            {
                document.SourceText = FigureRenumerator.RenumerateFigures(document.SourceText);
            }

            // now export the markdown document as Maml file(s)

            // first parse it with Markdig
            var pipeline = new MarkdownPipelineBuilder();

            pipeline = MarkdownUtilities.UseSupportedExtensions(pipeline);

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

            var renderer = new OpenXMLRenderer(
                wordDocumentFileName: OutputFileName,
                localImages: document.Images,
                textDocumentFolder: document.Folder
                );


            if (MaximumImageWidth.HasValue)
            {
                renderer.MaxImageWidthIn96thInch = MaximumImageWidth.Value.AsValueIn(Altaxo.Units.Length.Inch.Instance) * 96.0;
            }
            if (MaximumImageHeight.HasValue)
            {
                renderer.MaxImageHeigthIn96thInch = MaximumImageHeight.Value.AsValueIn(Altaxo.Units.Length.Inch.Instance) * 96.0;
            }
            if (null != ThemeName)
            {
                renderer.ThemeName = ThemeName;
            }
            renderer.RemoveOldContentsOfTemplateFile = RemoveOldContentsOfTemplateFile;
            renderer.ImageResolution                    = ImageResolutionDpi;
            renderer.UseAutomaticFigureNumbering        = UseAutomaticFigureNumbering;
            renderer.DoNotFormatFigureLinksAsHyperlinks = DoNotFormatFigureLinksAsHyperlinks;

            renderer.Render(markdownDocument);
        }
Example #2
0
        /// <summary>
        /// Exports the specified <see cref="TextDocument"/> to an external markdown file.
        /// </summary>
        /// <param name="document">The document to export.</param>
        /// <param name="fileName">Full name of the Maml file to export to. Note that if exporting to multiple Maml files,
        /// this is the base file name only; the file names will be derived from this name.</param>
        /// <param name="errors">A list that collects error messages.</param>
        public void Export(TextDocument document, string fileName, List <MarkdownError> errors = null)
        {
            if (null == document)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            var basePathName = Path.GetDirectoryName(fileName);


            if (ExpandChildDocuments)
            {
                document = ChildDocumentExpander.ExpandDocumentToNewDocument(document, errors: errors);
            }

            if (RenumerateFigures)
            {
                document.SourceText = FigureRenumerator.RenumerateFigures(document.SourceText);
            }

            // remove the old content
            if (EnableRemoveOldContentsOfContentFolder)
            {
                var fullContentFolderName = Path.Combine(basePathName, ContentFolderName);
                MamlRenderer.RemoveOldContentsOfContentFolder(fullContentFolderName);
            }

            // remove old images
            var fullImageFolderName = Path.Combine(basePathName, ImageFolderName);

            if (EnableRemoveOldContentsOfImageFolder)
            {
                MamlRenderer.RemoveOldContentsOfImageFolder(fullImageFolderName);
            }
            if (!Directory.Exists(fullImageFolderName))
            {
                Directory.CreateDirectory(fullImageFolderName);
            }

            // First, export the images
            var(oldToNewImageUrl, listOfReferencedImageFileNames) = ExportImages(document, basePathName);

            // now export the markdown document as Maml file(s)

            // first parse it with Markdig
            var pipeline = new MarkdownPipelineBuilder();

            pipeline = MarkdownUtilities.UseSupportedExtensions(pipeline);

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

            var renderer = new MamlRenderer(
                projectOrContentFileName: fileName,
                contentFolderName: ContentFolderName,
                contentFileNameBase: ContentFileNameBase,
                imageFolderName: ImageFolderName,
                splitLevel: SplitLevel,
                enableHtmlEscape: EnableHtmlEscape,
                autoOutline: EnableAutoOutline,
                enableLinkToPreviousSection: EnableLinkToPreviousSection,
                linkToPreviousSectionLabelText: LinkToPreviousSectionLabelText,
                enableLinkToNextSection: EnableLinkToNextSection,
                linkToNextSectionLabelText: LinkToNextSectionLabelText,
                imagesFullFileNames: listOfReferencedImageFileNames,
                oldToNewImageUris: oldToNewImageUrl,
                bodyTextFontFamily: BodyTextFontFamily,
                bodyTextFontSize: BodyTextFontSize,
                isIntendedForHelp1File: IsIntendedForHtmlHelp1File
                );

            renderer.Render(markdownDocument);
        }
Example #3
0
        /// <summary>
        /// Exports the specified <see cref="TextDocument"/> to an external markdown file.
        /// </summary>
        /// <param name="document">The document to export.</param>
        /// <param name="fileName">Full name of the Html file to export to. Note that if exporting to multiple Html files,
        /// this is the base file name only; the file names will be derived from this name.</param>
        /// <param name="errors">A list that collects error messages.</param>
        public void Export(TextDocument document, string fileName, List <MarkdownError> errors)
        {
            if (null == document)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            var basePathName = Path.GetDirectoryName(fileName);

            if (ExpandChildDocuments)
            {
                document = ChildDocumentExpander.ExpandDocumentToNewDocument(document, errors: errors);
            }

            if (RenumerateFigures)
            {
                document.SourceText = FigureRenumerator.RenumerateFigures(document.SourceText);
            }

            // remove the old content
            if (EnableRemoveOldContentsOfOutputFolder)
            {
                var fullContentFolderName = basePathName;
                HtmlSplitRenderer.RemoveOldContentsOfContentFolder(fullContentFolderName);
            }

            // remove old images
            if (EnableRemoveOldContentsOfImageFolder)
            {
                var fullImageFolderName = Path.Combine(basePathName, ImageFolderName);
                HtmlSplitRenderer.RemoveOldContentsOfImageFolder(fullImageFolderName);
            }

            // First, export the images
            var(oldToNewImageUrl, listOfReferencedImageFileNames) = ExportImages(document, basePathName);

            // now export the markdown document as Html file(s)



            var renderer = new HtmlSplitRenderer(
                projectOrContentFileName: fileName,
                imageFolderName: ImageFolderName,
                splitLevel: SplitLevel,
                enableHtmlEscape: EnableHtmlEscape,
                autoOutline: false,
                enableLinkToPreviousSection: EnableLinkToPreviousSection,
                linkToPreviousSectionLabelText: LinkToPreviousSectionLabelText,
                enableLinkToNextSection: EnableLinkToNextSection,
                linkToNextSectionLabelText: LinkToNextSectionLabelText,
                enableLinkToTableOfContents: EnableLinkToTableOfContents,
                linkToTableOfContentsLabelText: LinkToTableOfContentsLabelText,
                imagesFullFileNames: listOfReferencedImageFileNames,
                oldToNewImageUris: oldToNewImageUrl,
                bodyTextFontFamily: BodyTextFontFamily,
                bodyTextFontSize: BodyTextFontSize
                );

            renderer.Render(document.SourceText);
        }