Md2HtmlFormatter

Ecng.Markdown

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.

Constructores

Md2HtmlFormatter
public Md2HtmlFormatter()
md2HtmlFormatter = Md2HtmlFormatter()

Initializes both pipelines with the built-in extensions only.

Md2HtmlFormatter
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

ActivateRule
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.

Devuelve: The text with every role span replaced by its content or removed.

BuildDiagramHost
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.

Devuelve: Host element markup.

BuildVideo
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.

Devuelve: Video markup, or an empty string when there is nothing to say.

Clean
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.

Devuelve: The plain text.

CollectInlineRoleIds
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.

Devuelve: The referenced role ids.

FindPicture
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.

Devuelve: The file id of the first referenced image, or when there is none.

Parse
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.

Devuelve: The syntax tree together with the collected references.

Render
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.

Devuelve: The rendered HTML.

ResolveCounters
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

ProductNameEntity
public const string ProductNameEntity
value = Md2HtmlFormatter.ProductNameEntity

The entity type that renders as a bare localized name instead of a link.