Md2HtmlFormatter
Converts markdown with the site's custom directives (entity references, role gates, videos, diagrams, styled inlines, site counters) into HTML in two phases: Boolean) collects the external references, ResolvedMarkdownData) substitutes the data resolved for them.
Construtores
public Md2HtmlFormatter()
md2HtmlFormatter = Md2HtmlFormatter()
Initializes both pipelines with the built-in extensions only.
public Md2HtmlFormatter(IEnumerable<IMarkdownExtension> extensions)
md2HtmlFormatter = Md2HtmlFormatter(extensions)
Initializes both pipelines: one that keeps raw HTML for trusted authors and one that strips it for untrusted content.
- extensions
- Host extensions appended after the built-in ones in both pipelines.
Métodos
public string ActivateRule(string text, Dictionary<long, bool> roles)
result = md2HtmlFormatter.ActivateRule(text, roles)
Resolves "@role(id){...}" spans in the raw text: the content is kept when the reader has the role and removed otherwise.
- text
- Markdown source text.
- roles
- Whether the reader has each role, keyed by role id.
Retorna: The text with every role span replaced by its content or removed.
public static string BuildDiagramHost(string src)
result = Md2HtmlFormatter.BuildDiagramHost(src)
Wraps a schema address into the host element the browser-side renderer fills in.
- src
- Address the schema JSON is fetched from.
Retorna: Host element markup.
public static string BuildVideo(ResolvedVideo video)
result = Md2HtmlFormatter.BuildVideo(video)
Renders a resolved video as either a player or the reason it cannot be played.
- video
- Resolved video.
Retorna: Video markup, or an empty string when there is nothing to say.
public string Clean(string text)
result = md2HtmlFormatter.Clean(text)
Converts the markdown text to plain text: directive syntax, markup and HTML are stripped, leaving only the readable content (used for excerpts and search indexing).
- text
- Markdown source text.
Retorna: The plain text.
public HashSet<long> CollectInlineRoleIds(string text)
result = md2HtmlFormatter.CollectInlineRoleIds(text)
Collects the role ids of every "@role(id){...}" span in the raw text.
- text
- Markdown source text.
Retorna: The referenced role ids.
public long? FindPicture(string text)
result = md2HtmlFormatter.FindPicture(text)
Finds the first image reference in the text (used to pick a preview picture).
- text
- Markdown source text.
Retorna: The file id of the first referenced image, or when there is none.
public ParsedMarkdown Parse(string text, bool allowHtml)
result = md2HtmlFormatter.Parse(text, allowHtml)
Parses the markdown text and collects every external reference it makes.
- text
- Markdown source text.
- allowHtml
- Whether raw HTML embedded in the text is kept (trusted authors) or stripped.
Retorna: The syntax tree together with the collected references.
public string Render(ParsedMarkdown parsed, ResolvedMarkdownData data)
result = md2HtmlFormatter.Render(parsed, data)
Renders a parsed document to HTML, substituting the resolved data for the references collected by Boolean).
- parsed
- The parse result.
- data
- Data resolved for the collected references.
Retorna: The rendered HTML.
private static string ResolveCounters(string html, Dictionary<SiteCounters, string> counters)
result = Md2HtmlFormatter.ResolveCounters(html, counters)
Puts the site counters in place of their placeholders. A counter that was not resolved is written back as the source token: a number nobody could obtain must not be invented, and a zero in a sentence reads as a fact, while the token is visible to whoever edits the page.
Campos
public const string ProductNameEntity
value = Md2HtmlFormatter.ProductNameEntity
The entity type that renders as a bare localized name instead of a link.