本文整理汇总了C#中CommonMark.Parser.Subject类的典型用法代码示例。如果您正苦于以下问题:C# Subject类的具体用法?C# Subject怎么用?C# Subject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Subject类属于CommonMark.Parser命名空间,在下文中一共展示了Subject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: handle_newline
// Parse a hard or soft linebreak, returning an inline.
// Assumes the subject has a newline at the current position.
static Syntax.Inline handle_newline(Subject subj)
{
int nlpos = subj.Position;
// skip over newline
advance(subj);
// skip spaces at beginning of line
while (peek_char(subj) == ' ')
{
advance(subj);
}
if (nlpos > 1 &&
BString.bchar(subj.Buffer, nlpos - 1) == ' ' &&
BString.bchar(subj.Buffer, nlpos - 2) == ' ')
{
return make_linebreak();
}
else
{
return make_softbreak();
}
}
开发者ID:boombuler,项目名称:CommonMark.NET,代码行数:23,代码来源:InlineMethods.cs
示例2: handle_pointy_brace
// Parse an autolink or HTML tag.
// Assumes the subject has a '<' character at the current position.
static Inline handle_pointy_brace(Subject subj)
{
int matchlen;
string contents;
// advance past first <
subj.Position++;
// first try to match a URL autolink
matchlen = Scanner.scan_autolink_uri(subj.Buffer, subj.Position, subj.Length);
if (matchlen > 0)
{
contents = subj.Buffer.Substring(subj.Position, matchlen - 1);
var resultContents = ParseStringEntities(contents);
var result = Inline.CreateLink(resultContents, contents, string.Empty);
result.SourcePosition = subj.Position - 1;
resultContents.SourcePosition = subj.Position;
subj.Position += matchlen;
result.SourceLastPosition = subj.Position;
resultContents.SourceLastPosition = subj.Position - 1;
return result;
}
// next try to match an email autolink
matchlen = Scanner.scan_autolink_email(subj.Buffer, subj.Position, subj.Length);
if (matchlen > 0)
{
contents = subj.Buffer.Substring(subj.Position, matchlen - 1);
var resultContents = ParseStringEntities(contents);
var result = Inline.CreateLink(resultContents, "mailto:" + contents, string.Empty);
result.SourcePosition = subj.Position - 1;
resultContents.SourcePosition = subj.Position;
subj.Position += matchlen;
result.SourceLastPosition = subj.Position;
resultContents.SourceLastPosition = subj.Position - 1;
return result;
}
// finally, try to match an html tag
matchlen = Scanner.scan_html_tag(subj.Buffer, subj.Position, subj.Length);
if (matchlen > 0)
{
var result = new Inline(InlineTag.RawHtml, subj.Buffer, subj.Position - 1, matchlen + 1);
result.SourcePosition = subj.Position - 1;
subj.Position += matchlen;
result.SourceLastPosition = subj.Position;
return result;
}
else
{
// if nothing matches, just return the opening <:
return new Inline("<", subj.Position - 1, subj.Position);
}
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:60,代码来源:InlineMethods.cs
示例3: Finalize
public static void Finalize(Block b, LineInfo line)
{
// don't do anything if the block is already closed
if (!b.IsOpen)
return;
b.IsOpen = false;
if (line.IsTrackingPositions)
{
// (b.SourcePosition >= line.LineOffset) determines if the block started on this line.
if (b.SourcePosition >= line.LineOffset && line.Line != null)
b.SourceLastPosition = line.CalculateOrigin(line.Line.Length, false);
else
b.SourceLastPosition = line.CalculateOrigin(0, false);
}
#pragma warning disable 0618
b.EndLine = (line.LineNumber > b.StartLine) ? line.LineNumber - 1 : line.LineNumber;
#pragma warning restore 0618
switch (b.Tag)
{
case BlockTag.Paragraph:
var sc = b.StringContent;
if (!sc.StartsWith('['))
break;
var subj = new Subject(b.Top.ReferenceMap);
sc.FillSubject(subj);
var origPos = subj.Position;
while (subj.Position < subj.Buffer.Length
&& subj.Buffer[subj.Position] == '['
&& 0 != InlineMethods.ParseReference(subj))
{
}
if (subj.Position != origPos)
{
sc.Replace(subj.Buffer, subj.Position, subj.Buffer.Length - subj.Position);
if (sc.PositionTracker != null)
sc.PositionTracker.AddBlockOffset(subj.Position - origPos);
if (Utilities.IsFirstLineBlank(subj.Buffer, subj.Position))
b.Tag = BlockTag.ReferenceDefinition;
}
break;
case BlockTag.IndentedCode:
b.StringContent.RemoveTrailingBlankLines();
break;
case BlockTag.FencedCode:
// first line of contents becomes info
var firstlinelen = b.StringContent.IndexOf('\n') + 1;
b.FencedCodeData.Info = InlineMethods.Unescape(b.StringContent.TakeFromStart(firstlinelen, true).Trim());
break;
case BlockTag.List: // determine tight/loose status
b.ListData.IsTight = true; // tight by default
var item = b.FirstChild;
Block subitem;
while (item != null)
{
// check for non-final non-empty list item ending with blank line:
if (item.IsLastLineBlank && item.NextSibling != null)
{
b.ListData.IsTight = false;
break;
}
// recurse into children of list item, to see if there are spaces between them:
subitem = item.FirstChild;
while (subitem != null)
{
if (EndsWithBlankLine(subitem) && (item.NextSibling != null || subitem.NextSibling != null))
{
b.ListData.IsTight = false;
break;
}
subitem = subitem.NextSibling;
}
if (!b.ListData.IsTight)
break;
item = item.NextSibling;
}
break;
}
}
开发者ID:aggieben,项目名称:CommonMark.NET,代码行数:97,代码来源:BlockMethods.cs
示例4: handle_backslash
// Parse backslash-escape or just a backslash, returning an inline.
private static Inline handle_backslash(Subject subj)
{
subj.Position++;
if (subj.Position >= subj.Length)
return new Inline("\\", subj.Position - 1, subj.Position);
var nextChar = subj.Buffer[subj.Position];
if (Utilities.IsEscapableSymbol(nextChar))
{
// only ascii symbols and newline can be escaped
// the exception is the unicode bullet char since it can be used for defining list items
subj.Position++;
return new Inline(nextChar.ToString(), subj.Position - 2, subj.Position);
}
else if (nextChar == '\n')
{
subj.Position++;
return new Inline(InlineTag.LineBreak)
{
SourcePosition = subj.Position - 2,
SourceLastPosition = subj.Position
};
}
else
{
return new Inline("\\", subj.Position - 1, subj.Position);
}
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:31,代码来源:InlineMethods.cs
示例5: ParseEntity
/// <summary>
/// Parses the entity at the current position.
/// Assumes that there is a <c>&</c> at the current position.
/// </summary>
private static string ParseEntity(Subject subj)
{
int match;
string entity;
int numericEntity;
var origPos = subj.Position;
match = Scanner.scan_entity(subj.Buffer, subj.Position, subj.Length - subj.Position, out entity, out numericEntity);
if (match > 0)
{
subj.Position += match;
if (entity != null)
{
entity = EntityDecoder.DecodeEntity(entity);
if (entity != null)
return entity;
return subj.Buffer.Substring(origPos, match);
}
else if (numericEntity > 0)
{
entity = EntityDecoder.DecodeEntity(numericEntity);
if (entity != null)
return entity;
}
return "\uFFFD";
}
else
{
subj.Position++;
return "&";
}
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:38,代码来源:InlineMethods.cs
示例6: HandleLeftSquareBracket
private static Inline HandleLeftSquareBracket(Subject subj, CommonMarkSettings settings)
{
return HandleLeftSquareBracket(subj, false, settings);
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:4,代码来源:InlineMethods.cs
示例7: MatchSquareBracketStack
internal static void MatchSquareBracketStack(InlineStack opener, Subject subj, Reference details, InlineParserParameters parameters)
{
if (details != null)
{
var inl = opener.StartingInline;
var isImage = 0 != (opener.Flags & InlineStack.InlineStackFlags.ImageLink);
inl.Tag = isImage ? InlineTag.Image : InlineTag.Link;
inl.FirstChild = inl.NextSibling;
inl.NextSibling = null;
inl.SourceLastPosition = subj.Position;
inl.TargetUrl = details.Url;
inl.LiteralContent = details.Title;
if (!isImage)
{
// since there cannot be nested links, remove any other link openers before this
var temp = opener.Previous;
while (temp != null && temp.Priority <= InlineStack.InlineStackPriority.Links)
{
if (temp.Delimeter == '[' && temp.Flags == opener.Flags)
{
// mark the previous entries as "inactive"
if (temp.DelimeterCount == -1)
break;
temp.DelimeterCount = -1;
}
temp = temp.Previous;
}
}
InlineStack.RemoveStackEntry(opener, subj, null, parameters);
subj.LastInline = inl;
}
else
{
// this looked like a link, but was not.
// remove the opener stack entry but leave the inbetween intact
InlineStack.RemoveStackEntry(opener, subj, opener, parameters);
var inl = new Inline("]", subj.Position - 1, subj.Position);
subj.LastInline.LastSibling.NextSibling = inl;
subj.LastInline = inl;
}
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:48,代码来源:InlineMethods.cs
示例8: parse_inlines
public static Inline parse_inlines(Subject subj, Dictionary<string, Reference> refmap, InlineParserParameters parameters)
{
var len = subj.Length;
if (len == 0)
return null;
var first = ParseInline(subj, parameters);
subj.LastInline = first.LastSibling;
Inline cur;
while (subj.Position < len)
{
cur = ParseInline(subj, parameters);
if (cur != null)
{
subj.LastInline.NextSibling = cur;
subj.LastInline = cur.LastSibling;
}
}
InlineStack.PostProcessInlineStack(subj, subj.FirstPendingInline, subj.LastPendingInline, InlineStack.InlineStackPriority.Maximum, parameters);
return first;
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:25,代码来源:InlineMethods.cs
示例9: spnl
// Parse zero or more space characters, including at most one newline.
private static void spnl(Subject subj)
{
var seenNewline = false;
var len = subj.Length;
while (subj.Position < len)
{
var c = subj.Buffer[subj.Position];
if (c == ' ' || (!seenNewline && (seenNewline = c == '\n')))
subj.Position++;
else
return;
}
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:14,代码来源:InlineMethods.cs
示例10: handle_newline
// Parse a hard or soft linebreak, returning an inline.
// Assumes the subject has a newline at the current position.
static Inline handle_newline(Subject subj)
{
int nlpos = subj.Position;
// skip over newline
subj.Position++;
// skip spaces at beginning of line
var len = subj.Length;
while (subj.Position < len && subj.Buffer[subj.Position] == ' ')
subj.Position++;
if (nlpos > 1 && subj.Buffer[nlpos - 1] == ' ' && subj.Buffer[nlpos - 2] == ' ')
return new Inline(InlineTag.LineBreak) { SourcePosition = nlpos - 2, SourceLastPosition = nlpos + 1 };
else
return new Inline(InlineTag.SoftBreak) { SourcePosition = nlpos, SourceLastPosition = nlpos + 1 };
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:19,代码来源:InlineMethods.cs
示例11: ParseInline
/// <summary>
/// Parse an inline element from the subject. The subject position is updated to after the element.
/// </summary>
public static Inline ParseInline(Subject subj, InlineParserParameters parameters)
{
var parsers = parameters.Parsers;
var specialCharacters = parameters.SpecialCharacters;
var c = subj.Buffer[subj.Position];
var parser = c < parsers.Length ? parsers[c] : null;
if (parser != null)
return parser(subj);
var startpos = subj.Position;
// we read until we hit a special character
// +1 is so that any special character at the current position is ignored.
var endpos = subj.Buffer.IndexOfAny(specialCharacters, startpos + 1, subj.Length - startpos - 1);
if (endpos == -1)
endpos = subj.Length;
subj.Position = endpos;
// if we're at a newline, strip trailing spaces.
if (endpos < subj.Length && subj.Buffer[endpos] == '\n')
while (endpos > startpos && subj.Buffer[endpos - 1] == ' ')
endpos--;
return new Inline(subj.Buffer, startpos, endpos - startpos, startpos, endpos, c);
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:33,代码来源:InlineMethods.cs
示例12: spnl
// Parse zero or more space characters, including at most one newline.
private static void spnl(Subject subj)
{
bool seen_newline = false;
while (peek_char(subj) == ' ' ||
(!seen_newline &&
(seen_newline = peek_char(subj) == '\n')))
{
advance(subj);
}
}
开发者ID:boombuler,项目名称:CommonMark.NET,代码行数:11,代码来源:InlineMethods.cs
示例13: parse_inline
// Parse an inline, advancing subject, and add it to last element.
// Adjust tail to point to new last element of list.
// Return 0 if no inline can be parsed, 1 otherwise.
public static Syntax.Inline parse_inline(Subject subj)
{
Syntax.Inline inew = null;
string contents;
string special_chars;
char? c;
int endpos;
c = peek_char(subj);
if (c == null)
return null;
switch (c)
{
case '\n':
inew = handle_newline(subj);
break;
case '`':
inew = handle_backticks(subj);
break;
case '\\':
inew = handle_backslash(subj);
break;
case '&':
inew = handle_entity(subj);
break;
case '<':
inew = handle_pointy_brace(subj);
break;
case '_':
inew = HandleEmphasis(subj, '_');
break;
case '*':
inew = HandleEmphasis(subj, '*');
break;
case '[':
inew = handle_left_bracket(subj);
break;
case '!':
advance(subj);
if (peek_char(subj) == '[')
{
inew = handle_left_bracket(subj);
if (inew != null && inew.Tag == InlineTag.Link)
{
inew.Tag = InlineTag.Image;
}
else
{
inew = append_inlines(make_str("!"), inew);
}
}
else
{
inew = make_str("!");
}
break;
default:
// we read until we hit a special character
special_chars = "\n\\`&_*[]<!";
endpos = BString.binchr(subj.Buffer, subj.Position, special_chars);
if (endpos == subj.Position)
{
// current char is special: read a 1-character str
contents = take_one(subj);
}
else if (endpos == -1)
{
// special char not found, take whole rest of buffer:
endpos = subj.Buffer.Length;
contents = BString.bmidstr(subj.Buffer, subj.Position, endpos - subj.Position);
subj.Position = endpos;
}
else
{
// take buffer from subj.pos to endpos to str.
contents = BString.bmidstr(subj.Buffer, subj.Position, endpos - subj.Position);
subj.Position = endpos;
// if we're at a newline, strip trailing spaces.
if (peek_char(subj) == '\n')
contents = contents.TrimEnd();
}
inew = make_str(contents);
break;
}
return inew;
}
开发者ID:boombuler,项目名称:CommonMark.NET,代码行数:90,代码来源:InlineMethods.cs
示例14: parse_inlines_while
// Parse inlines while a predicate is satisfied. Return inlines.
public static Syntax.Inline parse_inlines_while(Subject subj)
{
Syntax.Inline first = null;
Syntax.Inline cur;
while (!is_eof(subj))
{
cur = parse_inline(subj);
if (first == null)
{
first = cur;
subj.LastInline = cur.LastSibling;
}
else
{
subj.LastInline.Next = cur;
subj.LastInline = cur.LastSibling;
}
}
return first;
}
开发者ID:boombuler,项目名称:CommonMark.NET,代码行数:22,代码来源:InlineMethods.cs
示例15: HandleOpenerCloser
private static Inline HandleOpenerCloser(Subject subj, InlineTag singleCharTag, InlineTag doubleCharTag, InlineParserParameters parameters)
{
bool canOpen, canClose;
var c = subj.Buffer[subj.Position];
var numdelims = ScanEmphasisDelimeters(subj, c, out canOpen, out canClose);
if (canClose)
{
// walk the stack and find a matching opener, if there is one
var istack = InlineStack.FindMatchingOpener(subj.LastPendingInline, InlineStack.InlineStackPriority.Emphasis, c, out canClose);
if (istack != null)
{
var useDelims = MatchInlineStack(istack, subj, numdelims, null, singleCharTag, doubleCharTag, parameters);
// if the closer was not fully used, move back a char or two and try again.
if (useDelims < numdelims)
{
subj.Position = subj.Position - numdelims + useDelims;
// use recursion only if it will not be very deep.
if (numdelims < 10)
return HandleOpenerCloser(subj, singleCharTag, doubleCharTag, parameters);
}
return null;
}
}
var inlText = new Inline(subj.Buffer, subj.Position - numdelims, numdelims, subj.Position - numdelims, subj.Position, c);
if (canOpen || canClose)
{
var istack = new InlineStack();
istack.DelimeterCount = numdelims;
istack.Delimeter = c;
istack.StartingInline = inlText;
istack.Priority = InlineStack.InlineStackPriority.Emphasis;
istack.Flags = (canOpen ? InlineStack.InlineStackFlags.Opener : 0)
| (canClose ? InlineStack.InlineStackFlags.Closer : 0);
InlineStack.AppendStackEntry(istack, subj);
}
return inlText;
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:45,代码来源:InlineMethods.cs
示例16: ParseReferenceLabel
/// <summary>
/// Parses the contents of [..] for a reference label. Only used for parsing
/// reference definition labels for use with the reference dictionary because
/// it does not properly parse nested inlines.
///
/// Assumes the source starts with '[' character or spaces before '['.
/// Returns null and does not advance if no matching ] is found.
/// Note the precedence: code backticks have precedence over label bracket
/// markers, which have precedence over *, _, and other inline formatting
/// markers. So, 2 below contains a link while 1 does not:
/// 1. [a link `with a ](/url)` character
/// 2. [a link *with emphasized ](/url) text* /// </summary>
private static StringPart? ParseReferenceLabel(Subject subj)
{
var startPos = subj.Position;
var source = subj.Buffer;
var len = subj.Length;
while (subj.Position < len)
{
var c = subj.Buffer[subj.Position];
if (c == ' ' || c == '\n')
{
subj.Position++;
continue;
}
else if (c == '[')
{
subj.Position++;
break;
}
else
{
subj.Position = startPos;
return null;
}
}
var labelStartPos = subj.Position;
len = subj.Position + Reference.MaximumReferenceLabelLength;
if (len > source.Length)
len = source.Length;
subj.Position = source.IndexOfAny(BracketSpecialCharacters, subj.Position, len - subj.Position);
while (subj.Position > -1)
{
var c = source[subj.Position];
if (c == '\\')
{
subj.Position += 2;
if (subj.Position >= len)
break;
subj.Position = source.IndexOfAny(BracketSpecialCharacters, subj.Position, len - subj.Position);
}
else if (c == '[')
{
break;
}
else
{
var label = new StringPart(source, labelStartPos, subj.Position - labelStartPos);
subj.Position++;
return label;
}
}
subj.Position = startPos;
return null;
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:71,代码来源:InlineMethods.cs
示例17: HandleExclamation
private static Inline HandleExclamation(Subject subj, CommonMarkSettings settings)
{
subj.Position++;
if (peek_char(subj) == '[')
return HandleLeftSquareBracket(subj, true, settings);
else
return new Inline("!", subj.Position - 1, subj.Position);
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:8,代码来源:InlineMethods.cs
示例18: ParseReference
// Parse reference. Assumes string begins with '[' character.
// Modify refmap if a reference is encountered.
// Return 0 if no reference found, otherwise position of subject
// after reference is parsed.
public static int ParseReference(Subject subj, CommonMarkSettings settings)
{
string title;
var startPos = subj.Position;
// parse label:
var lab = ParseReferenceLabel(subj);
if (lab == null || lab.Value.Length > Reference.MaximumReferenceLabelLength)
goto INVALID;
if (!Scanner.HasNonWhitespace(lab.Value))
goto INVALID;
// colon:
if (peek_char(subj) == ':')
subj.Position++;
else
goto INVALID;
// parse link url:
spnl(subj);
var matchlen = Scanner.scan_link_url(subj.Buffer, subj.Position, subj.Length);
if (matchlen == 0)
goto INVALID;
var url = subj.Buffer.Substring(subj.Position, matchlen);
url = CleanUrl(url);
subj.Position += matchlen;
// parse optional link_title
var beforetitle = subj.Position;
spnl(subj);
matchlen = Scanner.scan_link_title(subj.Buffer, subj.Position, subj.Length);
if (matchlen > 0)
{
title = subj.Buffer.Substring(subj.Position, matchlen);
title = CleanTitle(title);
subj.Position += matchlen;
}
else
{
subj.Position = beforetitle;
title = string.Empty;
}
char c;
// parse final spaces and newline:
while ((c = peek_char(subj)) == ' ') subj.Position++;
if (c == '\n')
{
subj.Position++;
}
else if (c != '\0')
{
if (matchlen > 0)
{ // try rewinding before title
subj.Position = beforetitle;
while ((c = peek_char(subj)) == ' ') subj.Position++;
if (c == '\n')
subj.Position++;
else if (c != '\0')
goto INVALID;
}
else
{
goto INVALID;
}
}
// insert reference into refmap
AddReference(subj.ReferenceMap, lab.Value, url, title, settings);
return subj.Position;
INVALID:
subj.Position = startPos;
return 0;
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:84,代码来源:InlineMethods.cs
示例19: peek_char
private static char peek_char(Subject subj)
{
return subj.Length <= subj.Position ? '\0' : subj.Buffer[subj.Position];
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:4,代码来源:InlineMethods.cs
示例20: HandleRightSquareBracket
private static Inline HandleRightSquareBracket(Subject subj, CommonMarkSettings settings)
{
// move past ']'
subj.Position++;
bool canClose;
var istack = InlineStack.FindMatchingOpener(subj.LastPendingInline, InlineStack.InlineStackPriority.Links, '[', out canClose);
if (istack != null)
{
// if the opener is "inactive" then it means that there was a nested link
if (istack.DelimeterCount == -1)
{
InlineStack.RemoveStackEntry(istack, subj, istack, settings.InlineParserParameters);
return new Inline("]", subj.Position - 1, subj.Position);
}
var endpos = subj.Position;
// try parsing details for '[foo](/url "title")' or '[foo][bar]'
var details = ParseLinkDetails(subj, settings);
// try lookup of the brackets themselves
if (details == null || details == Reference.SelfReference)
{
var startpos = istack.StartPosition;
var label = new StringPart(subj.Buffer, startpos, endpos - startpos - 1);
details = LookupReference(subj.ReferenceMap, label, settings);
}
if (details == Reference.InvalidReference)
details = null;
MatchSquareBracketStack(istack, subj, details, settings.InlineParserParameters);
return null;
}
var inlText = new Inline("]", subj.Position - 1, subj.Position);
if (canClose)
{
// note that the current implementation will not work if there are other inlines with priority
// higher than Links.
// to fix this the parsed link details should be added to the closer element in the stack.
throw new NotSupportedException("It is not supported to have inline stack priority higher than Links.");
////istack = new InlineStack();
////istack.Delimeter = '[';
////istack.StartingInline = inlText;
////istack.StartPosition = subj.Position;
////istack.Priority = InlineStack.InlineStackPriority.Links;
////istack.Flags = InlineStack.InlineStackFlags.Closer;
////InlineStack.AppendStackEntry(istack, subj);
}
return inlText;
}
开发者ID:AMDL,项目名称:CommonMark.NET,代码行数:60,代码来源:InlineMethods.cs
注:本文中的CommonMark.Parser.Subject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论