-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathContractsExtensions.cs
66 lines (61 loc) · 2.59 KB
/
ContractsExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Waher.Content.Xml;
namespace Waher.Content.Markdown.Contracts
{
/// <summary>
/// Markdown rendering extensions for Smart Contracts.
/// Ref: https://neuro-foundation.io/SmartContracts.md#humanReadableText
/// </summary>
public static class ContractsExtensions
{
/// <summary>
/// Generates Human-Readable XML for Smart Contracts from the markdown text.
/// Ref: https://neuro-foundation.io/SmartContracts.md#humanReadableText
/// </summary>
/// <returns>Smart Contract XML</returns>
public static Task<string> GenerateSmartContractXml(this MarkdownDocument Document)
{
return Document.GenerateSmartContractXml(XML.WriterSettings(false, true));
}
/// <summary>
/// Generates Human-Readable XML for Smart Contracts from the markdown text.
/// Ref: https://neuro-foundation.io/SmartContracts.md#humanReadableText
/// </summary>
/// <param name="Document">Markdown document being rendered.</param>
/// <param name="XmlSettings">XML settings.</param>
/// <returns>Smart Contract XML</returns>
public static async Task<string> GenerateSmartContractXml(this MarkdownDocument Document, XmlWriterSettings XmlSettings)
{
StringBuilder Output = new StringBuilder();
await Document.GenerateSmartContractXml(Output, XmlSettings);
return Output.ToString();
}
/// <summary>
/// Generates Human-Readable XML for Smart Contracts from the markdown text.
/// Ref: https://neuro-foundation.io/SmartContracts.md#humanReadableText
/// </summary>
/// <param name="Document">Markdown document being rendered.</param>
/// <param name="Output">Smart Contract XML will be output here.</param>
public static Task GenerateSmartContractXml(this MarkdownDocument Document, StringBuilder Output)
{
return Document.GenerateSmartContractXml(Output, XML.WriterSettings(false, true));
}
/// <summary>
/// Generates Human-Readable XML for Smart Contracts from the markdown text.
/// Ref: https://neuro-foundation.io/SmartContracts.md#humanReadableText
/// </summary>
/// <param name="Document">Markdown document being rendered.</param>
/// <param name="Output">Smart Contract XML will be output here.</param>
/// <param name="XmlSettings">XML settings.</param>
public static async Task GenerateSmartContractXml(this MarkdownDocument Document, StringBuilder Output, XmlWriterSettings XmlSettings)
{
XmlSettings.ConformanceLevel = ConformanceLevel.Fragment;
using (ContractsRenderer Renderer = new ContractsRenderer(Output, XmlSettings, null))
{
await Document.RenderDocument(Renderer);
}
}
}
}