示例#1
0
        public void ShouldCompileHeaderMarkdown()
        {
            // setup
            const string original = @"#hello world#";
            var          expected = @"<p><h1>hello world</h1></p>" + Environment.NewLine;

            // execute
            var actual = _markdownSharp.Transform(original);

            // assert
            Assert.AreEqual(expected, actual);
        }
        private void RenderMarkdownAndBindContent(string markdown)
        {
            if (string.IsNullOrWhiteSpace(markdown))
            {
                return;
            }

            var rendered = _markdownSharp.Transform(markdown);

            var html = new StringBuilder();

            html.Append("<html>");
            html.Append(string.Format("<style>{0}</style>", _styleString));
            html.Append("<body>");
            html.Append(rendered);
            html.Append("</body>");
            html.Append("</html>");

            var contentDirectoryPath = Path.Combine(NSBundle.MainBundle.BundlePath, "Content/");

            _webView.LoadHtmlString(html.ToString(), new NSUrl(contentDirectoryPath, true));

            HandleHtmlContentChanged();
        }
示例#3
0
 /// <summary>
 /// Gets the markdown converted body of the tag that is not sanitized.
 /// </summary>
 /// <param name="transformer">The Markdown object used to convert markdown to html. Optional.</param>
 /// <returns>A string containing the Html that was produced from the markdown.</returns>
 public string GetConvertedBody(MarkdownSharp.Markdown transformer = null)
 {
     if (transformer == null)
     {
         return (new MarkdownSharp.Markdown(true)).Transform(MarkdownBody);
     }
     else
     {
         return transformer.Transform(MarkdownBody);
     }
 }
示例#4
0
        static ConvertFileResponse ConvertFile(MarkdownSharp.Markdown markdownToHtml, string inputFileName, string language, IEnumerable<string> languagesLinksToGenerate, OutputFormat format = OutputFormat.HTML)
        {
            var result = ConvertFileResponse.NoChange;
            var targetFileName = GetTargetFileName(inputFileName, language);

            //Set up parameters in Markdown to aid in processing and generating html
            Markdown.MetadataErrorIfMissing = MetadataErrorIfMissing;
            Markdown.MetadataInfoIfMissing = MetadataInfoIfMissing;
            markdownToHtml.DoNotPublishAvailabilityFlag = Settings.Default.DoNotPublishAvailabilityFlag;
            markdownToHtml.PublishFlags = PublishFlags.ToList();
            markdownToHtml.AllSupportedAvailability = AllSupportedAvailability;

            var fileOutputDirectory = FileHelper.GetRelativePath(
                SourceDirectory, Path.GetDirectoryName(inputFileName));

            var currentFolderDetails = new FolderDetails(
                GetRelativeHTMLPath(targetFileName), OutputDirectory, SourceDirectory, fileOutputDirectory,
                Settings.Default.APIFolderLocation,
                (new DirectoryInfo(inputFileName).Parent).FullName.Replace(
                    SourceDirectory + Path.DirectorySeparatorChar.ToString(), "")
                                                         .Replace(SourceDirectory, "")
                                                         .Replace(Path.DirectorySeparatorChar.ToString(), " - "),
                language);

            markdownToHtml.DefaultTemplate = DefaultTemplate;

            markdownToHtml.ThisIsPreview = ThisIsPreview;

            if (language != "INT")
            {
                currentFolderDetails.DocumentTitle += " - " + language;
            }

            if (ThisIsPreview)
            {
                currentFolderDetails.DocumentTitle += " - PREVIEW!";
            }

            markdownToHtml.SupportedLanguages = SupportedLanguages;

            //Pass the default conversion settings to Markdown for use in the image details creation.
            markdownToHtml.DefaultImageDoCompress = DoCompressImages;
            markdownToHtml.DefaultImageFormatExtension = CompressImageType;
            markdownToHtml.DefaultImageFillColor = DefaultImageFillColor;
            markdownToHtml.DefaultImageFormat = CompressImageFormat;
            markdownToHtml.DefaultImageQuality = JpegCompressionRate;

            var errorList = new List<ErrorDetail>();
            var imageDetails = new List<ImageConversion>();
            var attachNames = new List<AttachmentConversionDetail>();

            var output = markdownToHtml.Transform(FileContents(inputFileName), errorList, imageDetails, attachNames, currentFolderDetails, languagesLinksToGenerate, format != OutputFormat.HTML);

            var noFailedErrorReport = true;
            var stopProcessing = false;

            //If output empty then treat as failed, we are not converting most likely due to the publish flags and availability settings
            if (String.IsNullOrWhiteSpace(output))
            {
                noFailedErrorReport = false;
                stopProcessing = true;
                result = ConvertFileResponse.NoChange;
                log.Info(MarkdownSharp.Language.Message("NotConverted", inputFileName));
            }
            else
            {
                //Need to check for error types prior to processing to output log messages in the correct order.
                foreach (var errorInfo in errorList)
                {
                    if (errorInfo.ClassOfMessage == MessageClass.Error || errorInfo.ClassOfMessage == MessageClass.Warning)
                    {
                        log.Info(MarkdownSharp.Language.Message("FileFailed", inputFileName));
                        noFailedErrorReport = false;
                        break;
                    }
                }
            }

            if (noFailedErrorReport)
            {
                log.Info(MarkdownSharp.Language.Message("Converted", inputFileName));
            }

            //On warnings or errors stop processing the file to the publish folder but allow to continue if in preview.
            if (errorList.Count > 0)
            {
                Console.Write("\n");

                foreach (MarkdownSharp.ErrorDetail ErrorInfo in errorList)
                {
                    switch (ErrorInfo.ClassOfMessage)
                    {
                        case MarkdownSharp.MessageClass.Error:
                            log.Error(ErrorInfo.Path ?? inputFileName, ErrorInfo.Line, ErrorInfo.Column, ErrorInfo.Message);
                            if (!ThisIsPreview)
                            {
                                stopProcessing = true;
                                result = ConvertFileResponse.Failed;
                            }
                            break;
                        case MarkdownSharp.MessageClass.Warning:
                            log.Warn(ErrorInfo.Path ?? inputFileName, ErrorInfo.Line, ErrorInfo.Column, ErrorInfo.Message);
                            if (!ThisIsPreview)
                            {
                                stopProcessing = true;
                                result = ConvertFileResponse.Failed;
                            }
                            break;
                        default:
                            log.Info(ErrorInfo.Path ?? inputFileName, ErrorInfo.Line, ErrorInfo.Column, ErrorInfo.Message);
                            break;
                    }
                }
            }

            if (!stopProcessing)
            {
                if (ThisIsPreview || !ThisIsLogOnly)
                {
                    CommonUnrealFunctions.CopyDocumentsImagesAndAttachments(inputFileName, log, OutputDirectory, language, fileOutputDirectory, imageDetails, attachNames);
                }

                var expected = FileContents(targetFileName);

                if (output == expected)
                {
                    result = ConvertFileResponse.NoChange;
                }
                else
                {
                    if (!stopProcessing)
                    {
                        if (!AlreadyCreatedCommonDirectories)
                        {
                            AlreadyCreatedCommonDirectories = CommonUnrealFunctions.CreateCommonDirectories(OutputDirectory, SourceDirectory, log);
                        }

                        Console.Write("\n");
                        if (ThisIsPreview || !ThisIsLogOnly)
                        {
                            //Check output directory exists, if not create the full html structure for this language
                            CommonUnrealFunctions.GenerateDocsFolderStructure(OutputDirectory, fileOutputDirectory, language);

                            CommonUnrealFunctions.SetFileAttributeForReplace(new FileInfo(targetFileName));
                            File.WriteAllText(targetFileName, output);

                            if (format == OutputFormat.PDF)
                            {
                                PdfHelper.CreatePdfFromHtml(targetFileName);
                            }
                        }

                        result = ConvertFileResponse.Converted;
                    }
                }
            }
            return result;
        }