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.Collections.Generic;
2using System.Threading.Tasks;
4
6{
11 {
12 private readonly bool hasBlocks = false;
13
19 public NestedBlock(MarkdownDocument Document, IEnumerable<MarkdownElement> Children)
20 : base(Document, Children)
21 {
22 this.hasBlocks = this.CalcHasBlocks();
23 }
24
31 : base(Document, Children)
32 {
33 this.hasBlocks = this.CalcHasBlocks();
34 }
35
36 private bool CalcHasBlocks()
37 {
38 bool HasBlocks = false;
39 bool HasSpans = false;
40 bool Inconsistent = false;
41
42 foreach (MarkdownElement E in this.Children)
43 {
44 if (E.IsBlockElement)
45 {
46 HasBlocks = true;
47 if (HasSpans)
48 {
49 Inconsistent = true;
50 break;
51 }
52 }
53 else
54 {
55 HasSpans = true;
56 if (HasBlocks)
57 {
58 Inconsistent = true;
59 break;
60 }
61 }
62 }
63
64 if (!Inconsistent)
65 return HasBlocks;
66
67 LinkedList<MarkdownElement> NewChildren = new LinkedList<MarkdownElement>();
68 LinkedList<MarkdownElement> Spans = null;
69
70 foreach (MarkdownElement E in this.Children)
71 {
72 if (E.IsBlockElement)
73 {
74 if (!(Spans is null))
75 {
76 NewChildren.AddLast(new Paragraph(this.Document, Spans, true));
77 Spans = null;
78 }
79
80 NewChildren.AddLast(E);
81 }
82 else
83 {
84 if (Spans is null)
85 Spans = new LinkedList<MarkdownElement>();
86
87 Spans.AddLast(E);
88 }
89 }
90
91 if (!(Spans is null))
92 NewChildren.AddLast(new Paragraph(this.Document, Spans, true));
93
94 this.SetChildren(NewChildren);
95
96 return true;
97 }
98
102 public override bool IsBlockElement => this.hasBlocks;
103
108 public override Task Render(IRenderer Output) => Output.Render(this);
109
113 public override bool InlineSpanElement
114 {
115 get
116 {
117 if (this.HasOneChild)
118 return this.FirstChild.InlineSpanElement;
119 else
120 return false;
121 }
122 }
123
131 public override MarkdownElementChildren Create(IEnumerable<MarkdownElement> Children, MarkdownDocument Document)
132 {
133 return new NestedBlock(Document, Children);
134 }
135
140 public override void IncrementStatistics(MarkdownStatistics Statistics)
141 {
142 Statistics.NrNestedBlocks++;
143 }
144
145 }
146}
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:11
override bool IsBlockElement
If the element is a block element.
Definition: NestedBlock.cs:102
NestedBlock(MarkdownDocument Document, params MarkdownElement[] Children)
Represents a nested block with no special formatting rules in a markdown document.
Definition: NestedBlock.cs:30
override void IncrementStatistics(MarkdownStatistics Statistics)
Increments the property or properties in Statistics corresponding to the element.
Definition: NestedBlock.cs:140
NestedBlock(MarkdownDocument Document, IEnumerable< MarkdownElement > Children)
Represents a nested block with no special formatting rules in a markdown document.
Definition: NestedBlock.cs:19
override Task Render(IRenderer Output)
Renders the element.
override bool InlineSpanElement
If the element is an inline span element.
Definition: NestedBlock.cs:114
override MarkdownElementChildren Create(IEnumerable< 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:131
Abstract base class for all markdown elements with a variable number of child elements.
void SetChildren(IEnumerable< MarkdownElement > Children)
Sets the children of the node.
override IEnumerable< 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.
virtual bool IsBlockElement
If the element is a block element.
abstract bool InlineSpanElement
If the element is an inline span element.
MarkdownDocument Document
Markdown document.
Interface for Markdown renderers.
Definition: IRenderer.cs:12