private static LightWeightHTMLDocument FromIHTMLDocument2(IHTMLDocument2 htmlDocument, string url, string name, bool escapePaths, bool escapeEmptyString) { string escapedHtml = HTMLDocumentHelper.HTMLDocToString(htmlDocument); if (escapedHtml == null) { return(null); } if (escapePaths) { escapedHtml = LightWeightHTMLUrlToAbsolute.ConvertToAbsolute(escapedHtml, url, true, escapeEmptyString); } LightWeightHTMLDocument finalDocument = new LightWeightHTMLDocument(escapedHtml, url, name); // Set the Frames finalDocument.SetFrames(GetLightWeightDocumentForFrames(htmlDocument)); // Set the styles finalDocument.SetStyleReferences(HTMLDocumentHelper.GetStyleReferencesForDocument(htmlDocument, url)); // Set the DocType HTMLDocumentHelper.SpecialHeaders specialHeaders = HTMLDocumentHelper.GetSpecialHeaders(htmlDocument); finalDocument._docType = specialHeaders.DocType; finalDocument._savedFrom = specialHeaders.SavedFrom; finalDocument.Parse(); return(finalDocument); }
public void ConvertAllReferencesToAbsolute(string baseUrl) { foreach (string filePath in Manifest) { if (filePath != null && (filePath.EndsWith(".htm", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".html", StringComparison.OrdinalIgnoreCase))) { string path = string.Empty; // split path at directory|file int lastSlash = filePath.LastIndexOf('/'); if (lastSlash != -1) { path = filePath.Substring(0, lastSlash + 1); } string output; using (StreamReader reader = new StreamReader(OpenFileStreamForRead(filePath), Encoding.UTF8)) { string thisUrl = baseUrl + path; Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Base url: {0} / {1}", thisUrl, filePath)); output = LightWeightHTMLUrlToAbsolute.ConvertToAbsolute(reader.ReadToEnd(), thisUrl); } using (StreamWriter writer = new StreamWriter(OpenFileStreamForWrite(filePath), Encoding.UTF8)) { writer.Write(output); } } } }
public static LightWeightHTMLDocument FromString(string html, string baseUrl, string name, bool escapePaths) { string escapedHtml = html; if (escapePaths) { escapedHtml = LightWeightHTMLUrlToAbsolute.ConvertToAbsolute(html, baseUrl); } LightWeightHTMLDocument escapedDocument = new LightWeightHTMLDocument(escapedHtml, baseUrl, name); HTMLDocumentHelper.SpecialHeaders specialHeaders = HTMLDocumentHelper.GetSpecialHeaders(escapedHtml, baseUrl); escapedDocument._docType = specialHeaders.DocType; escapedDocument._savedFrom = specialHeaders.SavedFrom; escapedDocument.Parse(); return(escapedDocument); }