public virtual XDocument Generate() { var mainDocument = new HTMLDocument(Compatibility); GenerateHead(); GenerateBody(); var encoding = new UTF8Encoding(); foreach (var file in _styles) { IHTMLItem styleElement; if (EmbedStyles) { var styleElementEntry = new Style(Compatibility); styleElement = styleElementEntry; styleElementEntry.Type.Value = CSSFile.MediaType.GetAsSerializableString(); try { using (var outStream = new MemoryStream()) { file.Write(outStream); styleElementEntry.InternalTextItem.Text = encoding.GetString(outStream.ToArray()); } } catch { // ignored } } else { var cssStyleSheet = new Link(Compatibility); styleElement = cssStyleSheet; cssStyleSheet.Relation.Value = "stylesheet"; cssStyleSheet.Type.Value = file.GetMediaType().GetAsSerializableString(); cssStyleSheet.HRef.Value = file.PathInEPUB.GetRelativePath(FileEPubInternalPath, FlatStructure); } HeadElement.Add(styleElement); } mainDocument.RootHTML.Add(HeadElement); mainDocument.RootHTML.Add(BodyElement); if (!mainDocument.RootHTML.IsValid()) { throw new Exception("Document content is not valid"); } var titleElm = new Title(Compatibility); titleElm.InternalTextItem.Text = InternalPageTitle; HeadElement.Add(titleElm); _generatedCodeXDocument = mainDocument.Generate(); Durty = false; return(_generatedCodeXDocument); }
public HtmlTag AddScript(string scriptType, string scriptContents) { var key = Guid.NewGuid().ToString(); _alterations.Add(html => html.Replace(key, System.Environment.NewLine + scriptContents + System.Environment.NewLine)); return(Head.Add("script").Attr("type", scriptType).Text(key)); }
public HtmlTag AddStyle(string styling) { var key = Guid.NewGuid().ToString(); _alterations.Add(html => html.Replace(key, styling)); return(Head.Add("style").Text(key)); }
public void Should_ThrowArgumentNullException_WhenAddNullParameter_AndCollectionIsEmpty() { var head = new Head(); Assert.Throws <ArgumentNullException>(() => head.Add(null)); Assert.IsFalse(head.Any()); }
public HtmlTag ReferenceStyle(string path) { return(Head.Add("link") .Attr("media", "screen") .Attr("href", path) .Attr("type", "text/css") .Attr("rel", "stylesheet")); }
public void Should_AddCorrectComponent_HeadIsNotEmpty() { var head = new Head(); Assert.DoesNotThrow(() => head.Add(new Component("asd", ComponentType.DRY, false))); Assert.IsTrue(head.Any()); }
public HtmlDocument() { RootTag = new HtmlTag("html"); DocType = "<!DOCTYPE html>"; Head = RootTag.Add("head"); _title = Head.Add("title"); Body = RootTag.Add("body"); Last = Body; }
public void Add(int Address) { Count++; if (Head == null) { Head = new Node() { Address = Address } } ; else { Head.Add(Address); } }
public HtmlTag ReferenceScriptFile(string scriptType, string path) => Head.Add("script").Attr("type", scriptType).Attr("src", path);
public void Should_ThrowArgumentNullException_WhenAddNullParameter() { var head = new Head(); Assert.Throws <ArgumentNullException>(() => head.Add(null)); }
public bool Insert(int data) { return(Head.Add(data)); }