5using System.Text.RegularExpressions;
6using System.Threading.Tasks;
25 private static readonly Regex processingInstructionData=
new Regex(
26 @"(\s*((type=['""](?'Type'[^'""]*)['""])|(href=['""](?'HRef'[^'""]*)['""])|([^ =]+=['""]([^'""]*)['""])))*",
27 RegexOptions.Singleline | RegexOptions.Compiled);
58 byte[] Bin = await State.
From.ReadAllAsync();
65 s = s.Substring(0, i);
68 SKEncodedImageFormat Format;
74 Format = SKEncodedImageFormat.Png;
79 Format = SKEncodedImageFormat.Bmp;
84 Format = SKEncodedImageFormat.Gif;
89 Format = SKEncodedImageFormat.Jpeg;
95 Format = SKEncodedImageFormat.Webp;
100 Format = SKEncodedImageFormat.Ico;
110 Extension =
XmlLayout.DefaultFileExtension;
111 State.ToContentType =
XmlLayout.DefaultContentType;
119 bool ValidXml =
true;
125 Graph = await
XmlLayout.GetFileName(
"layout", Xml,
Variables, Format, Quality, Extension);
127 if (!Graph.Converted && !(Graph.Xml is
null))
129 foreach (XmlNode N
in Graph.Xml)
131 if (N is XmlProcessingInstruction PI &&
132 PI.Name ==
"xml-stylesheet")
134 Match M = processingInstructionData.Match(PI.Data);
135 if (M.Success && M.Groups[
"Type"].Value ==
"text/xsl")
137 string HRef = M.Groups[
"HRef"].Value;
140 File.Exists(FileName))
142 using (FileStream fs = File.OpenRead(FileName))
156 IsHtml = !(Doc.Html is
null) && !(Doc.
Body is
null);
169 ResourceMap = State.ResourceMap
185 while (!Graph.Converted && Transformed && ValidXml);
187 if (!Graph.Converted)
190 Bin = Encoding.UTF8.GetBytes(Xml);
192 await State.
To.WriteAsync(Bin, 0, Bin.Length);
193 State.ToContentType = ContentType;
196 else if (Graph.Dynamic)
198 await State.
To.WriteAsync(Graph.DynamicContent, 0, Graph.DynamicContent.Length);
205 await State.
To.WriteAsync(Data, 0, Data.Length);
Contains the state of a content conversion process.
Variables Session
Session states.
string ToContentType
Content type of the content to convert to. This value might be changed, in case the converter finds a...
string LocalResourceName
Local resource name of file, if accessed from a web server.
string FromContentType
Content type of the content to convert from.
Stream To
Stream pointing to where binary representation of content is to be sent.
string FromFileName
If the content is coming from a file, this parameter contains the name of that file....
bool TryGetLocalResourceFileName(string Resource, string Host, out string FileName)
Tries to get a file name for a resource, if local.
string URL
URL of resource, if accessed from a web server.
Stream From
Stream pointing to binary representation of content.
const string DefaultContentType
Default Content-Type for HTML: text/html
Body Body
First BODY element of document, if found, null otherwise.
const string FileExtensionJpg
jpg
const string ContentTypeJpg
image/jpeg
const string ContentTypeIcon
image/x-icon
const string ContentTypeWebP
image/webp
const string ContentTypeEmf
image/x-emf
const string ContentTypeGif
image/gif
const string FileExtensionPng
png
const string FileExtensionWebP
webp
const string FileExtensionIcon
ico
const string ContentTypePng
image/png
const string ContentTypeBmp
image/bmp
const string ContentTypeTiff
image/tiff
const string ContentTypeWmf
image/x-wmf
const string ContentTypeSvg
image/svg+xml
const string FileExtensionGif
gif
const string FileExtensionBmp
bmp
static readonly string[] ImageContentTypes
Image content types.
Converts GraphViz documents to images.
async Task< bool > ConvertAsync(ConversionState State)
Performs the actual conversion.
Layout2DXmlToImageConverter()
Converts GraphViz documents to images.
string[] FromContentTypes
Converts content from these content types.
virtual Grade ConversionGrade
How well the content is converted.
virtual string[] ToContentTypes
Converts content to these content types.
Class managing 2D XML Layout integration into Markdown documents.
Contains a markdown document. This markdown document class supports original markdown,...
static ? int HeaderEndPosition(string Markdown)
Gets the end position of the header, if one is found, null otherwise.
async Task< string > GenerateHTML()
Generates HTML 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 readonly string[] XmlContentTypes
XML content types.
Helps with common XML-related tasks.
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Static class managing loading of XSL resources stored as embedded resources or in content files.
static XslCompiledTransform LoadTransform(string ResourceName)
Loads an XSL transformation from an embedded resource.
static string Transform(string XML, XslCompiledTransform Transform)
Transforms an XML document using an XSL transform.
static async Task< byte[]> ReadAllBytesAsync(string FileName)
Reads a binary file asynchronously.
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.
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...