/// <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); } }
/// <summary> /// Gets the markdown converted body of the tag that is sanizited. /// </summary> /// <param name="transformer">The Markdown object used to convert markdown to html. Optional.</param> /// <param name="sanitizer">The IHtmlSanitizer object used to sanitize the html produced by the converter.</param> /// <returns>A string containing the Html that was produced and then sanitized from the markdown.</returns> public string GetSanitizedBody(MarkdownSharp.Markdown transformer = null, IHtmlSanitizer sanitizer = null) { if (sanitizer == null) { return new HtmlSanitizer().GetHtml(GetConvertedBody(transformer)); } else { return sanitizer.GetHtml(GetConvertedBody(transformer)); } }
public MarkdownTextTransform(MarkdownSharp.Markdown markdown) { this.markdown = markdown; }
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; }
public void Setup() { _markdownSharp = new MarkdownSharp(); }
public MarkdownViewRenderer() { _markdownSharp = new MarkdownSharp(); }
public static string TestCase(string inputFileName, List<ErrorDetail> errorList = null) { var errors = errorList ?? new List<ErrorDetail>(); var targetFileName = GetTargetFileName(inputFileName); var sourceDirectory = Regex.Replace(Settings.Default.SourceDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2"); var outputDirectory = Regex.Replace(Settings.Default.OutputDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2"); Language.LangID = "INT"; Language.Init( Path.Combine(sourceDirectory, Settings.Default.IncludeDirectory, Settings.Default.InternationalizationDirectory)); var markdown = new Markdown(); Markdown.MetadataErrorIfMissing = Settings.Default.MetadataErrorIfMissing.Split(','); Markdown.MetadataInfoIfMissing = Settings.Default.MetadataInfoIfMissing.Split(','); markdown.PublishFlags = new List<string>() { "Licensee", "Public" }; markdown.AllSupportedAvailability = (Settings.Default.SupportedAvailability + ",Public").ToLower().Split(',').ToList(); markdown.DoNotPublishAvailabilityFlag = "NoPublish"; markdown.DefaultTemplate = Settings.Default.DefaultTemplate; markdown.ThisIsPreview = false; markdown.SupportedLanguages = Settings.Default.SupportedLanguages.ToUpper().Split(','); //Pass the default conversion settings to Markdown for use in the imagedetails creation. markdown.DefaultImageDoCompress = Settings.Default.DoCompressImages; markdown.DefaultImageFormatExtension = Settings.Default.CompressImageType; markdown.DefaultImageFillColor = ImageConversion.GetColorFromHexString(Settings.Default.ImageFillColor); markdown.DefaultImageFormat = ImageConversion.GetImageFormat(Settings.Default.CompressImageType); markdown.DefaultImageQuality = Settings.Default.ImageJPGCompressionValue; var imageDetails = new List<ImageConversion>(); var attachNames = new List<AttachmentConversionDetail>(); var languagesLinksToGenerate = new[] { "INT " }; var fileOutputDirectory = (new DirectoryInfo(inputFileName).Parent).FullName.Replace( sourceDirectory + Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), "") .Replace(sourceDirectory, ""); var currentFolderDetails = new FolderDetails( GetRelativeHTMLPath(targetFileName, outputDirectory), new DirectoryInfo(outputDirectory).FullName, new DirectoryInfo(sourceDirectory).FullName, "Temp", "API", (new DirectoryInfo(inputFileName).Parent).FullName.Replace( sourceDirectory + Path.DirectorySeparatorChar.ToString(), "") .Replace(sourceDirectory, "") .Replace(Path.DirectorySeparatorChar.ToString(), " - "), GetLanguage(inputFileName)); var text = File.ReadAllText(inputFileName); var actual = markdown.Transform( text, errors, imageDetails, attachNames, currentFolderDetails, languagesLinksToGenerate); return actual; }