示例#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);
            }

            // 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);
        }