Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NestedBlock.cs
1using System.Threading.Tasks;
5
7{
12 {
13 private readonly bool hasBlocks = false;
14
21 : base(Document, Children)
22 {
23 this.hasBlocks = this.CalcHasBlocks();
24 }
25
32 : base(Document, Children)
33 {
34 this.hasBlocks = this.CalcHasBlocks();
35 }
36
37 private bool CalcHasBlocks()
38 {
40 bool HasBlocks = false;
41 bool HasSpans = false;
42 bool Inconsistent = false;
43 int i, c;
44
45 while (!(Loop is null))
46 {
47 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
48 {
49 if (Loop[i].IsBlockElement)
50 {
51 HasBlocks = true;
52 if (HasSpans)
53 {
54 Inconsistent = true;
55 Loop = null;
56 break;
57 }
58 }
59 else
60 {
61 HasSpans = true;
62 if (HasBlocks)
63 {
64 Inconsistent = true;
65 Loop = null;
66 break;
67 }
68 }
69 }
70
71 Loop = Loop?.Next;
72 }
73
74 if (!Inconsistent)
75 return HasBlocks;
76
80
81 Loop = this.Children.FirstChunk;
82
83 while (!(Loop is null))
84 {
85 for (i = Loop.Start, c = Loop.Pos; i < c; i++)
86 {
87 E = Loop[i];
88
89 if (E.IsBlockElement)
90 {
91 if (!(Spans is null))
92 {
93 NewChildren.Add(new Paragraph(this.Document, Spans, true));
94 Spans = null;
95 }
96
97 NewChildren.Add(E);
98 }
99 else
100 {
101 if (Spans is null)
102 Spans = new ChunkedList<MarkdownElement>();
103
104 Spans.Add(E);
105 }
106 }
107
108 Loop = Loop?.Next;
109 }
110
111 if (!(Spans is null))
112 NewChildren.Add(new Paragraph(this.Document, Spans, true));
113
114 this.SetChildren(NewChildren);
115
116 return true;
117 }
118
122 public override bool IsBlockElement => this.hasBlocks;
123
128 public override Task Render(IRenderer Output) => Output.Render(this);
129
133 public override bool InlineSpanElement
134 {
135 get
136 {
137 if (this.HasOneChild)
138 return this.FirstChild.InlineSpanElement;
139 else
140 return false;
141 }
142 }
143
152 {
153 return new NestedBlock(Document, Children);
154 }
155
160 public override void IncrementStatistics(MarkdownStatistics Statistics)
161 {
162 Statistics.NrNestedBlocks++;
163 }
164
165 }
166}
Contains a markdown document. This markdown document class supports original markdown,...
Contains some basic statistical information about a Markdown document.
int NrNestedBlocks
Number of nested blocks.
Abstract base class for block elements with children.
Represents a nested block with no special formatting rules in a markdown document.
Definition: NestedBlock.cs:12
override bool IsBlockElement
If the element is a block element.
Definition: NestedBlock.cs:122
NestedBlock(MarkdownDocument Document, params MarkdownElement[] Children)
Represents a nested block with no special formatting rules in a markdown document.
Definition: NestedBlock.cs:31
override MarkdownElementChildren Create(ChunkedList< MarkdownElement > Children, MarkdownDocument Document)
Creates an object of the same type, and meta-data, as the current object, but with content defined by...
Definition: NestedBlock.cs:151
NestedBlock(MarkdownDocument Document, ChunkedList< MarkdownElement > Children)
Represents a nested block with no special formatting rules in a markdown document.
Definition: NestedBlock.cs:20
override void IncrementStatistics(MarkdownStatistics Statistics)
Increments the property or properties in Statistics corresponding to the element.
Definition: NestedBlock.cs:160
override Task Render(IRenderer Output)
Renders the element.
override bool InlineSpanElement
If the element is an inline span element.
Definition: NestedBlock.cs:134
Abstract base class for all markdown elements with a variable number of child elements.
void SetChildren(ChunkedList< MarkdownElement > Children)
Sets the children of the node.
override ChunkedList< MarkdownElement > Children
Any children of the element.
bool HasOneChild
If the element has only one child.
MarkdownElement FirstChild
First child, or null if none.
Abstract base class for all markdown elements.
abstract bool InlineSpanElement
If the element is an inline span element.
MarkdownDocument Document
Markdown document.
MarkdownElement(MarkdownDocument Document)
Abstract base class for all markdown elements.
Node referencing a chunk in a ChunkedList<T>
Definition: ChunkNode.cs:11
ChunkNode< T > Next
Next chunk
Definition: ChunkNode.cs:26
int Pos
Index after the last element in chunk.
Definition: ChunkNode.cs:51
int Start
Index of first element in chunk.
Definition: ChunkNode.cs:46
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
ChunkNode< T > FirstChunk
First chunk
Definition: ChunkedList.cs:259
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
Euler's number.
Definition: E.cs:12
Interface for Markdown renderers.
Definition: IRenderer.cs:12