4using System.Threading.Tasks;
16 private static bool allowEncoding =
true;
17 private static bool locked =
false;
27 throw new InvalidOperationException(
"Setting has been locked.");
29 allowEncoding = Allow;
60 private static readonly
string[] contentTypes =
new string[] {
ContentType };
85 if (Array.IndexOf(
this.ContentTypes,
ContentType) >= 0)
108 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
122 string.Empty,
string.Empty, BaseUri.ToString());
163 public async Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
ICodecProgress Progress, params
string[] AcceptedContentTypes)
168 Markdown = Content.Markdown;
172 return new ContentResponse(
new ArgumentException(
"Object not a markdown document.", nameof(Object)));
177 if (Encoding is
null)
180 Bin = Encoding.UTF8.GetBytes(Markdown);
184 ContentType =
"text/markdown; charset=" + Encoding.WebName;
185 Bin = Encoding.GetBytes(Markdown);
199 switch (FileExtension.ToLower())
223 FileExtension =
"md";
227 FileExtension =
string.Empty;
240 ? Grade.Excellent :
Grade.NotAtAll;
249 public void Encode(
object Object,
int? Indent, StringBuilder Json)
Contains information about a response to a content request.
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.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given 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.
Grade Supports(Type ObjectType)
How well the JSON encoder encodes objects of type ObjectType .
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.
void Encode(object Object, int? Indent, StringBuilder Json)
Encodes the Object to JSON.
async Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
static void AllowRawEncoding(bool Allow, bool Lock)
If raw encoding of web script should be allowed.
async Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
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...
string Markdown
Markdown content.
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.
Static class managing binary representations of strings.
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Interface for reporting progress about an encoding or decoding.
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...
Interface for encoding objects of certain types to JSON.