2using System.Collections.Generic;
4using System.Threading.Tasks;
14 private static bool allowEncoding =
true;
15 private static bool locked =
false;
25 throw new InvalidOperationException(
"Setting has been locked.");
27 allowEncoding = Allow;
81 if (Array.IndexOf(
this.ContentTypes,
ContentType) >= 0)
103 public async Task<object>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
147 public async Task<KeyValuePair<byte[], string>>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
152 Markdown = Content.Markdown;
156 throw new ArgumentException(
"Object not a markdown document.", nameof(Object));
161 if (Encoding is
null)
164 Bin = Encoding.UTF8.GetBytes(Markdown);
168 ContentType =
"text/markdown; charset=" + Encoding.WebName;
169 Bin = Encoding.GetBytes(Markdown);
172 return new KeyValuePair<byte[], string>(Bin,
ContentType);
183 switch (FileExtension.ToLower())
207 FileExtension =
"md";
211 FileExtension =
string.Empty;
Helps with parsing of commong data types.
static string GetString(byte[] Data, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
async Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
static bool IsRawEncodingAllowed
If Raw encoding is allowed. Can be changed calling AllowRawEncoding(bool, bool).
static bool IsRawEncodingAllowedLocked
If the IsRawEncodingAllowed setting is locked.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
const string ContentType
Markdown content type.
string[] ContentTypes
Supported content types.
async Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
static void AllowRawEncoding(bool Allow, bool Lock)
If raw encoding of web script should be allowed.
string[] FileExtensions
Supported file extensions.
MarkdownCodec()
Markdown encoder/decoder.
Class that can be used to encapsulate Markdown to be returned from a Web Service, bypassing any encod...
Contains a markdown document. This markdown document class supports original markdown,...
Task< string > GenerateMarkdown()
Generates Markdown from the markdown text.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...