/// <summary> /// Identifies the <see cref="WikiLink"/>s in the given <paramref name="markdown"/>. /// </summary> /// <param name="options">An <see cref="WikiOptions"/> instance.</param> /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param> /// <param name="markdown">The markdown.</param> /// <param name="title">The title of the item.</param> /// <param name="wikiNamespace">The namespace of the item.</param> /// <returns> /// A <see cref="List{T}"/> of <see cref="WikiLink"/>s. /// </returns> protected static List <WikiLink> GetWikiLinks( IWikiOptions options, IDataStore dataStore, string?markdown, string?title = null, string?wikiNamespace = null) => string.IsNullOrEmpty(markdown) ? new List <WikiLink>() : Markdown.Parse(markdown, WikiConfig.GetMarkdownPipeline(options, dataStore)) .Descendants <WikiLinkInline>() .Where(x => !x.IsWikipedia &&
/// <summary> /// Gets a preview of the given markdown's rendered HTML. /// </summary> /// <param name="options">An <see cref="IWikiOptions"/> instance.</param> /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param> /// <param name="markdown">The markdown content.</param> /// <returns>A preview of the rendered HTML.</returns> public static string RenderPreview(IWikiOptions options, IDataStore dataStore, string?markdown) { if (string.IsNullOrWhiteSpace(markdown)) { return(string.Empty); } var document = Markdown.Parse(markdown, WikiConfig.GetMarkdownPipeline(options, dataStore)); if (AnyPreviews(document)) { TrimNonPreview(document); } else { var minCharactersAvailable = PreviewCharacterMin; var maxCharactersAvailable = PreviewCharacterMax; Trim(document, ref minCharactersAvailable, ref maxCharactersAvailable); } string html; using (var writer = new StringWriter()) { var renderer = new HtmlRenderer(writer); WikiConfig.GetMarkdownPipeline(options, dataStore).Setup(renderer); renderer.Render(document); html = writer.ToString(); } if (!string.IsNullOrWhiteSpace(html) && options.Postprocessors is not null) { foreach (var preprocessor in options.Postprocessors) { html = preprocessor.Process.Invoke(html); } } return(WikiConfig.GetHtmlSanitizer(options).Sanitize(html) ?? string.Empty); }
/// <summary> /// Renders the given <paramref name="markdown"/> as HTML. /// </summary> /// <param name="options">An <see cref="IWikiOptions"/> instance.</param> /// <param name="dataStore">An <see cref="IDataStore"/> instance.</param> /// <param name="markdown">The markdown content.</param> /// <returns>The rendered HTML.</returns> public static string RenderHtml(IWikiOptions options, IDataStore dataStore, string?markdown) { if (string.IsNullOrWhiteSpace(markdown)) { return(string.Empty); } var html = Markdown.ToHtml(markdown, WikiConfig.GetMarkdownPipeline(options, dataStore)); if (string.IsNullOrWhiteSpace(html)) { return(string.Empty); } if (options.Postprocessors is not null) { foreach (var preprocessor in options.Postprocessors) { html = preprocessor.Process.Invoke(html); } } return(WikiConfig.GetHtmlSanitizer(options).Sanitize(html)); }