4using System.Threading.Tasks;
34 "application/xhtml+xml"
88 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
89 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
103 switch (FileExtension.ToLower())
112 ContentType =
"application/xhtml+xml";
116 ContentType =
string.Empty;
129 switch (ContentType.ToLower())
132 FileExtension =
"html";
135 case "application/xhtml+xml":
136 FileExtension =
"xhtml";
140 FileExtension =
string.Empty;
154 if (Object is
HtmlDocument || (Object is
string s && s.TrimEnd().EndsWith(
"</html>", StringComparison.OrdinalIgnoreCase)))
175 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
ICodecProgress Progress, params
string[] AcceptedContentTypes)
178 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object))));
184 Html = HtmlDoc.HtmlText;
185 else if (Object is
string s)
192 if (Encoding is
null)
194 ContentType +=
"; charset=utf-8";
195 Bin = Encoding.UTF8.GetBytes(Html);
199 ContentType +=
"; charset=" + Encoding.WebName;
200 Bin = Encoding.GetBytes(Html);
223 public void Encode(
object Object,
int? Indent, StringBuilder Json)
Contains information about a response to a content request.
Grade Supports(Type ObjectType)
How well the JSON encoder encodes objects of type ObjectType .
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
void Encode(object Object, int? Indent, StringBuilder Json)
Encodes the Object to JSON.
static readonly string[] HtmlFileExtensions
HTML file extensions.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
string[] FileExtensions
Supported file extensions.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
HtmlCodec()
HTML encoder/decoder.
string[] ContentTypes
Supported content types.
static readonly string[] HtmlContentTypes
HTML content types.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
const string DefaultContentType
Default Content-Type for HTML: text/html
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.
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.