C# Class MarkdownSharp.Markdown

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).
ファイルを表示 Open project: xamarin/mac-samples Class Usage Examples

Public Methods

Method Description
Markdown ( ) : System

Create a new Markdown instance using default options

Markdown ( MarkdownOptions options ) : System

Create a new Markdown instance and set the options from the MarkdownOptions object.

Markdown ( bool loadOptionsFromConfigFile ) : System

Create a new Markdown instance and optionally load options from a configuration file. There they should be stored in the appSettings section, available options are: Markdown.StrictBoldItalic (true/false) Markdown.EmptyElementSuffix (">" or " />" without the quotes) Markdown.LinkEmails (true/false) Markdown.AutoNewLines (true/false) Markdown.AutoHyperlink (true/false) Markdown.EncodeProblemUrlCharacters (true/false)

Transform ( string text ) : string

Transforms the provided Markdown-formatted text to HTML; see http://en.wikipedia.org/wiki/Markdown

The order in which other subs are called here is essential. Link and image substitutions need to happen before EscapeSpecialChars(), so that any *'s or _'s in the a and img tags get encoded.

Private Methods

Method Description
AnchorInlineEvaluator ( Match match ) : string
AnchorRefEvaluator ( Match match ) : string
AnchorRefShortcutEvaluator ( Match match ) : string
AttributeEncode ( string s ) : string
AtxHeaderEvaluator ( Match match ) : string
BlockQuoteEvaluator ( Match match ) : string
BlockQuoteEvaluator2 ( Match match ) : string
Cleanup ( ) : void
CodeBlockEvaluator ( Match match ) : string
CodeSpanEvaluator ( Match match ) : string
DoAnchors ( string text ) : string

Turn Markdown link shortcuts into HTML anchor tags

[link text](url "title") [link text][id] [id]

DoAutoLinks ( string text ) : string

Turn angle-delimited URLs into HTML anchor tags

<http://www.example.com>

DoBlockQuotes ( string text ) : string

Turn Markdown > quoted blocks into HTML blockquote blocks

DoCodeBlocks ( string text ) : string

/// Turn Markdown 4-space indented code into HTML pre code blocks

DoCodeSpans ( string text ) : string

Turn Markdown `code spans` into HTML code tags

DoHardBreaks ( string text ) : string

Turn markdown line breaks (two space at end of line) into HTML break tags

DoHeaders ( string text ) : string

Turn Markdown headers into HTML header tags

Header 1 ======== Header 2 -------- # Header 1 ## Header 2 ## Header 2 with closing hashes ## ... ###### Header 6

DoHorizontalRules ( string text ) : string

Turn Markdown horizontal rules into HTML hr tags

*** * * * --- - - -

DoImages ( string text ) : string

Turn Markdown image shortcuts into HTML img tags.

![alt text][id] ![alt text](url "optional title")

DoItalicsAndBold ( string text ) : string

Turn Markdown *italics* and **bold** into HTML strong and em tags

DoLists ( string text, bool isInsideParagraphlessListItem = false ) : string

Turn Markdown lists into HTML ul and ol and li tags

EmailEvaluator ( Match match ) : string
EncodeAmpsAndAngles ( string s ) : string

Encode any ampersands (that aren't part of an HTML entity) and left or right angle brackets

EncodeCode ( string code ) : string

Encode/escape certain Markdown characters inside code blocks and spans where they are literals

EncodeCodeEvaluator ( Match match ) : string
EncodeEmailAddress ( string addr ) : string

encodes email address randomly roughly 10% raw, 45% hex, 45% dec note that @ is always encoded and : never is

EncodeProblemUrlChars ( string url ) : string

hex-encodes some unusual "problem" chars in URLs to avoid URL detection problems

EscapeBackslashes ( string s ) : string

Encodes any escaped characters such as \`, \*, \[ etc

EscapeBackslashesEvaluator ( Match match ) : string
EscapeBoldItalic ( string s ) : string

escapes Bold [ * ] and Italic [ _ ] characters

EscapeImageAltText ( string s ) : string
EscapeSpecialCharsWithinTagAttributes ( string text ) : string

Within tags -- meaning between < and > -- encode [\ ` * _] so they don't conflict with their use in Markdown for code, italics and strong. We're replacing each such character with its corresponding hash value; this is likely overkill, but it should prevent us from colliding with the escape values by accident.

FormParagraphs ( string text, bool unhash = true ) : string

splits on two or more newlines, to form "paragraphs"; each paragraph is then unhashed (if it is a hash and unhashing isn't turned off) or wrapped in HTML p tag

GetBlockPattern ( ) : string

derived pretty much verbatim from PHP Markdown

GetHashKey ( string s, bool isHtmlBlock ) : string
GetListEvaluator ( bool isInsideParagraphlessListItem = false ) : MatchEvaluator
GetNestedBracketsPattern ( ) : string

Reusable pattern to match balanced [brackets]. See Friedl's "Mastering Regular Expressions", 2nd Ed., pp. 328-331.

GetNestedParensPattern ( ) : string

Reusable pattern to match balanced (parens). See Friedl's "Mastering Regular Expressions", 2nd Ed., pp. 328-331.

HashHTMLBlocks ( string text ) : string

replaces any block-level HTML blocks with hash entries

HtmlEvaluator ( Match match ) : string
HyperlinkEvaluator ( Match match ) : string
ImageInlineEvaluator ( Match match ) : string
ImageReferenceEvaluator ( Match match ) : string
ImageTag ( string url, string altText, string title ) : string
LinkEvaluator ( Match match ) : string
Normalize ( string text ) : string

convert all tabs to _tabWidth spaces; standardizes line endings from DOS (CR LF) or Mac (CR) to UNIX (LF); makes sure text ends with a couple of newlines; removes any blank lines (only spaces) in the text

Outdent ( string block ) : string

Remove one level of line-leading spaces

ProcessListItems ( string list, string marker, bool isInsideParagraphlessListItem = false ) : string

Process the contents of a single ordered or unordered list, splitting it into individual list items.

RepeatString ( string text, int count ) : string

this is to emulate what's evailable in PHP

RunBlockGamut ( string text, bool unhash = true ) : string

Perform transformations that form block-level tags like paragraphs, headers, and list items.

RunSpanGamut ( string text ) : string

Perform transformations that occur *within* block-level tags like paragraphs, headers, and list items.

SaveFromAutoLinking ( string s ) : string
SetextHeaderEvaluator ( Match match ) : string
Setup ( ) : void
StripLinkDefinitions ( string text ) : string

Strips link definitions from text, stores the URLs and titles in hash references.

^[id]: url "optional title"

TokenizeHTML ( string text ) : List

returns an array of HTML tokens comprising the input string. Each token is either a tag (possibly with nested, tags contained therein, such as <a href="<MTFoo>">, or a run of text between tags. Each element of the array is a two-element array; the first is either 'tag' or 'text'; the second is the actual value.

Unescape ( string s ) : string

swap back in all the special characters we've hidden

UnescapeEvaluator ( Match match ) : string
handleTrailingParens ( Match match ) : string

Method Details

Markdown() public method

Create a new Markdown instance using default options
public Markdown ( ) : System
return System

Markdown() public method

Create a new Markdown instance and set the options from the MarkdownOptions object.
public Markdown ( MarkdownOptions options ) : System
options MarkdownOptions
return System

Markdown() public method

Create a new Markdown instance and optionally load options from a configuration file. There they should be stored in the appSettings section, available options are: Markdown.StrictBoldItalic (true/false) Markdown.EmptyElementSuffix (">" or " />" without the quotes) Markdown.LinkEmails (true/false) Markdown.AutoNewLines (true/false) Markdown.AutoHyperlink (true/false) Markdown.EncodeProblemUrlCharacters (true/false)
public Markdown ( bool loadOptionsFromConfigFile ) : System
loadOptionsFromConfigFile bool
return System

Transform() public method

Transforms the provided Markdown-formatted text to HTML; see http://en.wikipedia.org/wiki/Markdown
The order in which other subs are called here is essential. Link and image substitutions need to happen before EscapeSpecialChars(), so that any *'s or _'s in the a and img tags get encoded.
public Transform ( string text ) : string
text string
return string