本文整理汇总了C#中CommonMark.Syntax.Block类的典型用法代码示例。如果您正苦于以下问题:C# Block类的具体用法?C# Block怎么用?C# Block使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Block类属于CommonMark.Syntax命名空间,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PositionSafeForSmartLink
public static bool PositionSafeForSmartLink(Block ast, int start, int length)
{
if (ast == null) return true;
var end = start + length;
var blockTags = new[] {BlockTag.FencedCode, BlockTag.HtmlBlock, BlockTag.IndentedCode, BlockTag.ReferenceDefinition};
var inlineTags = new[] {InlineTag.Code, InlineTag.Link, InlineTag.RawHtml, InlineTag.Image};
var lastBlockTag = BlockTag.Document;
foreach (var block in EnumerateBlocks(ast.FirstChild))
{
if (block.SourcePosition + block.SourceLength < start)
{
lastBlockTag = block.Tag;
continue;
}
if (block.SourcePosition >= end) return !blockTags.Any(tag => tag == lastBlockTag);
if (blockTags.Any(tag => tag == block.Tag)) return false;
return !EnumerateInlines(block.InlineContent)
.TakeWhile(il => il.SourcePosition < end)
.Where(il => il.SourcePosition + il.SourceLength > start)
.Any(il => inlineTags.Any(tag => tag == il.Tag));
}
return true;
}
示例2: WriteAsync
public async Task WriteAsync(Block block)
{
await WriteStartElementAsync("para");
await WriteStartElementAsync("command");
await WriteChildInlinesAsync(block);
await WriteEndElementAsync(); //command
await WriteEndElementAsync(); //para
}
示例3: TopicParserResult
/// <summary>
/// Initializes a new instance of the <see cref="TopicParserResult"/> class.
/// </summary>
/// <param name="doc">Document block.</param>
internal TopicParserResult(Block doc)
{
if (doc == null)
throw new ArgumentNullException("doc");
if (doc.Tag != BlockTag.Document)
throw new InvalidOperationException("Unexpected block tag: " + doc.Tag);
Document = doc;
}
示例4: GetTitle
private static string GetTitle(TopicData topic, Block block)
{
if (block == null || block.HeaderLevel != 1)
return topic.Name;
var title = string.Empty;
for (var inline = block.InlineContent; inline != null; inline = inline.NextSibling)
title += inline.LiteralContent;
return title;
}
示例5: CreateDocument
/// <summary>
/// Creates a new top-level document block.
/// </summary>
internal static Block CreateDocument()
{
#pragma warning disable 0618
Block e = new Block(BlockTag.Document, 1, 1, 0);
#pragma warning restore 0618
e.ReferenceMap = new Dictionary<string, Reference>();
e.Top = e;
return e;
}
示例6: DoWriteStartSectionAsync
internal override async Task<SectionState> DoWriteStartSectionAsync(Block block, string title)
{
await WriteStartElementAsync("glossaryEntry");
await WriteStartElementAsync("terms");
foreach (var term in title.Split(','))
await WriteTermAsync(term);
await WriteEndElementAsync(); //terms
await WriteStartElementAsync("definition");
return SectionState.Content;
}
示例7: PrintPosition
private static void PrintPosition(bool enabled, TextWriter writer, Block block)
{
if (enabled)
{
writer.Write(" [");
writer.Write(block.SourcePosition);
writer.Write('-');
writer.Write(block.SourceLastPosition);
writer.Write(']');
}
}
示例8: WriteChainedInlineHeader
public void WriteChainedInlineHeader()
{
// Process
Block block = new Block(BlockTag.AtxHeader, 0);
block.InlineContent = new Inline("Title");
block.InlineContent.NextSibling = new Inline(" in many");
block.InlineContent.NextSibling.NextSibling = new Inline(" siblings");
string output = this.Process(block);
// Assert
Assert.AreEqual(string.Format(@"<!--UT [Title in many siblings](page-title-in-many-siblings)-->{0}<h0>Title in many siblings</h0>{0}", Environment.NewLine), output);
}
示例9: EnumerateBlocks
public static IEnumerable<Block> EnumerateBlocks(Block block)
{
if (block == null) yield break;
var stack = new Stack<Block>();
stack.Push(block);
while (stack.Any())
{
var next = stack.Pop();
yield return next;
if (next.NextSibling != null) stack.Push(next.NextSibling);
if (next.FirstChild != null) stack.Push(next.FirstChild);
}
}
示例10: WriteListItemAsync
internal override async Task WriteListItemAsync(Block block)
{
if (GetSectionState() != SectionState.Sections)
{
await base.WriteListItemAsync(block);
return;
}
await WriteStartElementAsync("step");
await WriteStartElementAsync("content");
await WriteChildBlocksAsync(block);
await WriteEndElementAsync(); //content
await WriteEndElementAsync(); //step
}
示例11: EndsWithBlankLine
/// <summary>
/// Check to see if a block ends with a blank line, descending if needed into lists and sublists.
/// </summary>
private static bool EndsWithBlankLine(Block block)
{
while (true)
{
if (block.IsLastLineBlank)
return true;
if (block.Tag != BlockTag.List && block.Tag != BlockTag.ListItem)
return false;
block = block.LastChild;
if (block == null)
return false;
}
}
示例12: WriteChainedInlineHeader
public void WriteChainedInlineHeader()
{
// Process
Block block = new Block(BlockTag.AtxHeader, 0);
block.InlineContent = new Inline("Title");
block.InlineContent.NextSibling = new Inline(" in many");
block.InlineContent.NextSibling.NextSibling = new Inline(" siblings");
string output = this.Process(block);
// Assert
Assert.IsTrue(output.StartsWith(@"<a name=""page-title+in+many+siblings"">"));
Assert.AreEqual(1, this.Formatter.Anchors.Length);
Assert.AreEqual("page-title+in+many+siblings", this.Formatter.Anchors[0].Value);
Assert.AreEqual("Title in many siblings", this.Formatter.Anchors[0].Label);
Assert.AreEqual(0, this.Formatter.Anchors[0].Level);
}
示例13: WriteListAsync
internal override async Task WriteListAsync(Block block)
{
if (SectionLevel < 2)
{
await base.WriteListAsync(block);
return;
}
await WriteEndIntroductionAsync();
//TODO procedure?
await WriteStartElementAsync("steps");
await WriteListClassAsync(block, ListClass.Bullet);
SetSectionState(SectionState.Sections);
await WriteChildBlocksAsync(block);
await WriteEndElementAsync(); //steps
}
示例14: WriteBlock
/// <summary>
/// Specializes block writing for anchor injection.
/// For each formatted header we generate an anchor based on the context name, the header content and eventually add an integer suffix in order to prevent conflicts.
/// </summary>
/// <param name="block">The block to process.</param>
/// <param name="isOpening">Define whether the block is opening.</param>
/// <param name="isClosing">Defines whether the block is closing.</param>
/// <param name="ignoreChildNodes">return whether the processing ignored child nodes.</param>
protected override void WriteBlock(Block block, bool isOpening, bool isClosing, out bool ignoreChildNodes)
{
// Filter opening header
if (isOpening && null != block && block.Tag == BlockTag.AtxHeader)
{
// Retrieve header content
string headerContent;
if (null != block.InlineContent && null != block.InlineContent.LiteralContent)
{
// Read the whole content
Inline inline = block.InlineContent;
StringBuilder stringBuilder = new StringBuilder();
do
{
stringBuilder.Append(inline.LiteralContent);
inline = inline.NextSibling;
} while (null != inline);
headerContent = stringBuilder.ToString();
}
else
{
headerContent = "unknown";
}
// Compute the anchor value
string sectionId = HttpUtility.UrlEncode(headerContent.ToLower());
sectionId = string.Format("{0}-{1}", this.ContextName, sectionId)
.Replace('+', '-');
// Detect anchor conflict
if (sectionConflict.ContainsKey(sectionId))
{
// Append the index
sectionId = string.Format("{0}-{1}", sectionId, ++sectionConflict[sectionId]);
}
// Write anchor
this.Write(string.Format(@"<!--{0} [{1}]({2})-->", this.PageSplittingIdentifier, headerContent, sectionId));
sectionConflict[sectionId] = 1;
}
// Trigger parent rendering for the default html rendering
base.WriteBlock(block, isOpening, isClosing, out ignoreChildNodes);
}
示例15: WriteDocument
/// <summary>
/// Writes the given CommonMark document to the output stream as HTML.
/// </summary>
public void WriteDocument(Block document)
{
if (document == null)
throw new ArgumentNullException(nameof(document));
bool ignoreChildNodes;
Block ignoreUntilBlockCloses = null;
Inline ignoreUntilInlineCloses = null;
foreach (var node in document.AsEnumerable())
{
if (node.Block != null)
{
if (ignoreUntilBlockCloses != null)
{
if (ignoreUntilBlockCloses != node.Block)
continue;
ignoreUntilBlockCloses = null;
}
WriteBlock(node.Block, node.IsOpening, node.IsClosing, out ignoreChildNodes);
if (ignoreChildNodes && !node.IsClosing)
ignoreUntilBlockCloses = node.Block;
}
else if (ignoreUntilBlockCloses == null && node.Inline != null)
{
if (ignoreUntilInlineCloses != null)
{
if (ignoreUntilInlineCloses != node.Inline)
continue;
ignoreUntilInlineCloses = null;
}
WriteInline(node.Inline, node.IsOpening, node.IsClosing, out ignoreChildNodes);
if (ignoreChildNodes && !node.IsClosing)
ignoreUntilInlineCloses = node.Inline;
}
}
}