@@ -370,11 +376,11 @@ public string Transform(string text)
return text + "\n";
}
-
+ private string RunBlockGamut(string text){return RunBlockGamut(text, true);}
///
/// Perform transformations that form block-level tags like paragraphs, headers, and list items.
///
- private string RunBlockGamut(string text, bool unhash = true)
+ private string RunBlockGamut(string text, bool unhash)
{
text = DoHeaders(text);
text = DoHorizontalRules(text);
@@ -389,7 +395,7 @@ private string RunBlockGamut(string text, bool unhash = true)
// tags around block-level tags.
text = HashHTMLBlocks(text);
- text = FormParagraphs(text, unhash: unhash);
+ text = FormParagraphs(text, unhash);
return text;
}
@@ -427,11 +433,12 @@ private string RunSpanGamut(string text)
private static Regex _htmlBlockHash = new Regex("\x1AH\\d+H", RegexOptions.Compiled);
+ private string FormParagraphs(string text){return FormParagraphs(text, true);}
///
- /// splits on two or more newlines, to form "paragraphs";
+ /// 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
///
- private string FormParagraphs(string text, bool unhash = true)
+ private string FormParagraphs(string text, bool unhash)
{
// split on two or more newlines
string[] grafs = _newlinesMultiple.Split(_newlinesLeadingTrailing.Replace(text, ""));
@@ -463,7 +470,7 @@ private string FormParagraphs(string text, bool unhash = true)
while (keepGoing && sanityCheck > 0)
{
keepGoing = false;
- grafs[i] = _htmlBlockHash.Replace(grafs[i], match =>
+ grafs[i] = _htmlBlockHash.Replace(grafs[i], delegate(Match match)
{
keepGoing = true;
return _htmlBlocks[match.Value];
@@ -509,7 +516,7 @@ private void Cleanup()
private static string _nestedBracketsPattern;
///
- /// Reusable pattern to match balanced [brackets]. See Friedl's
+ /// Reusable pattern to match balanced [brackets]. See Friedl's
/// "Mastering Regular Expressions", 2nd Ed., pp. 328-331.
///
private static string GetNestedBracketsPattern()
@@ -533,7 +540,7 @@ private static string GetNestedBracketsPattern()
private static string _nestedParensPattern;
///
- /// Reusable pattern to match balanced (parens). See Friedl's
+ /// Reusable pattern to match balanced (parens). See Friedl's
/// "Mastering Regular Expressions", 2nd Ed., pp. 328-331.
///
private static string GetNestedParensPattern()
@@ -612,8 +619,8 @@ private static string GetBlockPattern()
// hard-coded:
//
// * List "a" is made of tags which can be both inline or block-level.
- // These will be treated block-level when the start tag is alone on
- // its line, otherwise they're not matched here and will be taken as
+ // These will be treated block-level when the start tag is alone on
+ // its line, otherwise they're not matched here and will be taken as
// inline later.
// * List "b" is made of tags which are always block-level;
//
@@ -633,7 +640,7 @@ private static string GetBlockPattern()
|
'[^']*' # text inside single quotes (tolerate >)
)*
- )?
+ )?
";
string content = RepeatString(@"
@@ -650,7 +657,7 @@ private static string GetBlockPattern()
RepeatString(@"
\2\s*> # closing nested tag
)
- |
+ |
<(?!/\2\s*> # other tags with a different name
)
)*", _nestDepth);
@@ -677,9 +684,9 @@ private static string GetBlockPattern()
)
( # save in $1
- # Match from `\n` to `\n`, handling nested tags
+ # Match from `\n` to `\n`, handling nested tags
# in between.
-
+
<($block_tags_b_re) # start tag = $2
$attr> # attributes followed by > and \n
$content # content, support nesting
@@ -695,19 +702,19 @@ [ ]* # trailing spaces
\3> # the matching end tag
[ ]* # trailing spaces
(?=\n+|\Z) # followed by a newline or end of document
-
- | # Special case just for
. It was easier to make a special
+
+ | # Special case just for
. It was easier to make a special
# case than to make the other regex more complicated.
-
+
[ ]{0,$less_than_tab}
# the matching end tag
[ ]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
-
+
| # Special case for standalone HTML comments:
-
+
(?<=\n\n|\A) # preceded by a blank line or start of document
[ ]{0,$less_than_tab}
(?s:
@@ -715,9 +722,9 @@ [ ]*
)
[ ]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
-
+
| # PHP and ASP-style processor instructions ( and <%)
-
+
[ ]{0,$less_than_tab}
(?s:
<([?%]) # $4
@@ -726,7 +733,7 @@ [ ]*
)
[ ]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
-
+
)
)";
@@ -751,7 +758,7 @@ private string HashHTMLBlocks(string text)
private string HtmlEvaluator(Match match)
{
string text = match.Groups[1].Value;
- string key = GetHashKey(text, isHtmlBlock: true);
+ string key = GetHashKey(text, true);
_htmlBlocks[key] = text;
return string.Concat("\n\n", key, "\n\n");
@@ -759,30 +766,30 @@ private string HtmlEvaluator(Match match)
private static string GetHashKey(string s, bool isHtmlBlock)
{
- var delim = isHtmlBlock ? 'H' : 'E';
+ char delim = isHtmlBlock ? 'H' : 'E';
return "\x1A" + delim + Math.Abs(s.GetHashCode()).ToString() + delim;
}
private static Regex _htmlTokens = new Regex(@"
()| # match
(<\?.*?\?>)| # match " +
- RepeatString(@"
+ RepeatString(@"
(<[A-Za-z\/!$](?:[^<>]|", _nestDepth) + RepeatString(@")*>)", _nestDepth) +
" # match and ",
RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
///
- /// 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
+ /// 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.
///
private List TokenizeHTML(string text)
{
int pos = 0;
int tagStart = 0;
- var tokens = new List();
+ List tokens = new List();
// this regex is derived from the _tokenize() subroutine in Brad Choate's MTRegex plugin.
// http://www.bradchoate.com/past/mtregex.php
@@ -848,9 +855,9 @@ [ ]*
/// Turn Markdown link shortcuts into HTML anchor tags
///
///
- /// [link text](url "title")
- /// [link text][id]
- /// [id]
+ /// [link text](url "title")
+ /// [link text][id]
+ /// [id]
///
private string DoAnchors(string text)
{
@@ -949,7 +956,7 @@ private string AnchorInlineEvaluator(Match match)
url = EncodeProblemUrlChars(url);
url = EscapeBoldItalic(url);
if (url.StartsWith("<") && url.EndsWith(">"))
- url = url.Substring(1, url.Length - 2); // remove <>'s surrounding URL, if present
+ url = url.Substring(1, url.Length - 2); // remove <>'s surrounding URL, if present
result = string.Format("
- /// Turn Markdown image shortcuts into HTML img tags.
+ /// Turn Markdown image shortcuts into HTML img tags.
///
///
/// ![alt text][id]
@@ -1024,7 +1031,7 @@ private string DoImages(string text)
private string EscapeImageAltText(string s)
{
s = EscapeBoldItalic(s);
- s = Regex.Replace(s, @"[\[\]()]", m => _escapeTable[m.ToString()]);
+ s = Regex.Replace(s, @"[\[\]()]", delegate(Match m) {return _escapeTable[m.ToString()];});
return s;
}
@@ -1072,7 +1079,7 @@ private string ImageTag(string url, string altText, string title)
altText = EscapeImageAltText(AttributeEncode(altText));
url = EncodeProblemUrlChars(url);
url = EscapeBoldItalic(url);
- var result = string.Format("
///
- /// Header 1
- /// ========
- ///
- /// Header 2
- /// --------
- ///
- /// # Header 1
- /// ## Header 2
- /// ## Header 2 with closing hashes ##
- /// ...
- /// ###### Header 6
+ /// Header 1
+ /// ========
+ ///
+ /// Header 2
+ /// --------
+ ///
+ /// # Header 1
+ /// ## Header 2
+ /// ## Header 2 with closing hashes ##
+ /// ...
+ /// ###### Header 6
///
private string DoHeaders(string text)
{
@@ -1153,8 +1160,8 @@ [ ]* # Trailing spaces
/// Turn Markdown horizontal rules into HTML hr tags
///
///
- /// ***
- /// * * *
+ /// ***
+ /// * * *
/// ---
/// - - -
///
@@ -1189,10 +1196,11 @@ [ ]*
private static Regex _listTopLevel = new Regex(@"(?:(?<=\n\n)|\A\n?)" + _wholeList,
RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
+ private string DoLists(string text){return DoLists(text, false);}
///
/// Turn Markdown lists into HTML ul and ol and li tags
///
- private string DoLists(string text, bool isInsideParagraphlessListItem = false)
+ private string DoLists(string text, bool isInsideParagraphlessListItem)
{
// We use a different prefix before nested lists than top-level lists.
// See extended comment in _ProcessListItems().
@@ -1204,9 +1212,10 @@ private string DoLists(string text, bool isInsideParagraphlessListItem = false)
return text;
}
- private MatchEvaluator GetListEvaluator(bool isInsideParagraphlessListItem = false)
+ private MatchEvaluator GetListEvaluator(){return GetListEvaluator(false);}
+ private MatchEvaluator GetListEvaluator(bool isInsideParagraphlessListItem)
{
- return new MatchEvaluator(match =>
+ return new MatchEvaluator(delegate(Match match)
{
string list = match.Groups[1].Value;
string listType = Regex.IsMatch(match.Groups[3].Value, _markerUL) ? "ul" : "ol";
@@ -1219,11 +1228,12 @@ private MatchEvaluator GetListEvaluator(bool isInsideParagraphlessListItem = fal
});
}
+ private string ProcessListItems(string list, string marker){return ProcessListItems(list, marker, false);}
///
/// Process the contents of a single ordered or unordered list, splitting it
/// into individual list items.
///
- private string ProcessListItems(string list, string marker, bool isInsideParagraphlessListItem = false)
+ private string ProcessListItems(string list, string marker, bool isInsideParagraphlessListItem)
{
// The listLevel global keeps track of when we're inside a list.
// Each time we enter a list, we increment it; when we leave a list,
@@ -1255,13 +1265,13 @@ private string ProcessListItems(string list, string marker, bool isInsideParagra
@"(^[ ]*) # leading whitespace = $1
({0}) [ ]+ # list marker = $2
((?s:.+?) # list item text = $3
- (\n+))
+ (\n+))
(?= (\z | \1 ({0}) [ ]+))", marker);
bool lastItemHadADoubleNewline = false;
// has to be a closure, so subsequent invocations can share the bool
- MatchEvaluator ListItemEvaluator = (Match match) =>
+ MatchEvaluator ListItemEvaluator = delegate(Match match)
{
string item = match.Groups[3].Value;
@@ -1270,11 +1280,11 @@ private string ProcessListItems(string list, string marker, bool isInsideParagra
if (containsDoubleNewline || lastItemHadADoubleNewline)
// we could correct any bad indentation here..
- item = RunBlockGamut(Outdent(item) + "\n", unhash: false);
+ item = RunBlockGamut(Outdent(item) + "\n", false);
else
{
// recursion for sub-lists
- item = DoLists(Outdent(item), isInsideParagraphlessListItem: true);
+ item = DoLists(Outdent(item), true);
item = item.TrimEnd('\n');
if (!isInsideParagraphlessListItem) // only the outer-most item should run this, otherwise it's run multiple times for the inner ones
item = RunSpanGamut(item);
@@ -1372,7 +1382,7 @@ private string DoCodeSpans(string text)
//
// Turns to:
//
- // ... type `bar` ...
+ // ... type `bar` ...
//
return _codeSpan.Replace(text, new MatchEvaluator(CodeSpanEvaluator));
@@ -1464,7 +1474,7 @@ private string BlockQuoteEvaluator(Match match)
bq = Regex.Replace(bq, @"(\s*.+?
)", new MatchEvaluator(BlockQuoteEvaluator2), RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
bq = string.Format("\n{0}\n
", bq);
- string key = GetHashKey(bq, isHtmlBlock: true);
+ string key = GetHashKey(bq, true);
_htmlBlocks[key] = bq;
return "\n\n" + key + "\n\n";
@@ -1493,11 +1503,11 @@ private static string handleTrailingParens(Match match)
if (match.Groups[1].Success)
return match.Value;
- var protocol = match.Groups[2].Value;
- var link = match.Groups[3].Value;
+ string protocol = match.Groups[2].Value;
+ string link = match.Groups[3].Value;
if (!link.EndsWith(")"))
return "<" + protocol + link + ">";
- var level = 0;
+ int level = 0;
foreach (Match c in Regex.Matches(link, "[()]"))
{
if (c.Value == "(")
@@ -1512,14 +1522,14 @@ private static string handleTrailingParens(Match match)
level--;
}
}
- var tail = "";
+ string tail = "";
if (level < 0)
{
- link = Regex.Replace(link, @"\){1," + (-level) + "}$", m => { tail = m.Value; return ""; });
+ link = Regex.Replace(link, @"\){1," + (-level) + "}$", delegate(Match m) { tail = m.Value; return ""; });
}
if (tail.Length > 0)
{
- var lastChar = link[link.Length - 1];
+ char lastChar = link[link.Length - 1];
if (!_endCharRegex.IsMatch(lastChar.ToString()))
{
tail = lastChar + tail;
@@ -1593,7 +1603,7 @@ private string EmailEvaluator(Match match)
//
email = "mailto:" + email;
- // leave ':' alone (to spot mailto: later)
+ // leave ':' alone (to spot mailto: later)
email = EncodeEmailAddress(email);
email = string.Format("{0}", email);
@@ -1619,14 +1629,14 @@ private string Outdent(string block)
///
- /// encodes email address randomly
- /// roughly 10% raw, 45% hex, 45% dec
+ /// encodes email address randomly
+ /// roughly 10% raw, 45% hex, 45% dec
/// note that @ is always encoded and : never is
///
private string EncodeEmailAddress(string addr)
{
- var sb = new StringBuilder(addr.Length * 5);
- var rand = new Random();
+ StringBuilder sb = new StringBuilder(addr.Length * 5);
+ Random rand = new Random();
int r;
foreach (char c in addr)
{
@@ -1730,13 +1740,13 @@ private static string AttributeEncode(string s)
private static readonly char[] _problemUrlChars = @"""'*()[]$:_".ToCharArray();
///
- /// hex-encodes some unusual "problem" chars in URLs to avoid URL detection problems
+ /// hex-encodes some unusual "problem" chars in URLs to avoid URL detection problems
///
private string EncodeProblemUrlChars(string url)
{
if (!_encodeProblemUrlCharacters) return url;
- var sb = new StringBuilder(url.Length);
+ StringBuilder sb = new StringBuilder(url.Length);
bool encode;
char c;
@@ -1758,20 +1768,20 @@ private string EncodeProblemUrlChars(string url)
///
- /// 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
+ /// 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.
///
private string EscapeSpecialCharsWithinTagAttributes(string text)
{
- var tokens = TokenizeHTML(text);
+ List tokens = TokenizeHTML(text);
// now, rebuild text from the tokens
- var sb = new StringBuilder(text.Length);
+ StringBuilder sb = new StringBuilder(text.Length);
- foreach (var token in tokens)
+ foreach (Token token in tokens)
{
string value = token.Value;
@@ -1793,15 +1803,15 @@ private string EscapeSpecialCharsWithinTagAttributes(string text)
}
///
- /// 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;
+ /// 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
///
private string Normalize(string text)
{
- var output = new StringBuilder(text.Length);
- var line = new StringBuilder();
+ StringBuilder output = new StringBuilder(text.Length);
+ StringBuilder line = new StringBuilder();
bool valid = false;
for (int i = 0; i < text.Length; i++)
@@ -1849,7 +1859,7 @@ private string Normalize(string text)
///
private static string RepeatString(string text, int count)
{
- var sb = new StringBuilder(text.Length * count);
+ StringBuilder sb = new StringBuilder(text.Length * count);
for (int i = 0; i < count; i++)
sb.Append(text);
return sb.ToString();
diff --git a/README.md b/README.md
index e29ec46..f279b21 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
MarkdownSharp - With Github style code blocks
=========================================
+新建2.0.5分支,修改为兼容.net版本2.0.5的语法。
+=========================================
The original MarkdownSharp can be found on google code here [https://code.google.com/p/markdownsharp/](https://code.google.com/p/markdownsharp/)
@@ -34,10 +36,10 @@ Then you can use a library like [HighlightJS](http://highlightjs.org/) to sytnax
Whatever is after the 3 ticks will be put in the class name
-so
+so
```mylanguage
-
-would transform to
+
+would transform to
```html
```