public void CssParseTest() { var doc = new document(new container_test(), null, null); var c = new css(); c.parse_stylesheet("/*Comment*/", null, doc, null); c.parse_stylesheet("html { display: none }", null, doc, null); // https://www.w3schools.com/cssref/pr_import_rule.asp c.parse_stylesheet("@import \"navigation.css\"; /* Using a string */", null, doc, null); c.parse_stylesheet("@import url(\"navigation.css\"); /* Using a url */", null, doc, null); c.parse_stylesheet("@import \"navigation.css\"", null, doc, null); c.parse_stylesheet("@import \"printstyle.css\" print;", null, doc, null); c.parse_stylesheet("@import \"mobstyle.css\" screen and (max-width: 768px);", null, doc, null); // https://www.w3schools.com/cssref/css3_pr_mediaquery.asp c.parse_stylesheet("@media only screen and (max-width: 600px) { body { background-color: lightblue; } }", null, doc, null); }
public static document createFromString(string str, Icontainer container, script_engine script, context ctx, css user_styles = null) => createFromUTF8(Encoding.UTF8.GetString(Encoding.Default.GetBytes(str)), container, script, ctx, user_styles);
public static document createFromUTF8(string str, Icontainer container, script_engine script, context ctx, css user_styles = null) { var doc = new document(container, script, ctx); // Create litehtml::document var root_elements = new List <element>(); using (var gumbo = new Gumbo.Gumbo(str)) // parse document into GumboOutput doc.create_node(gumbo.Document.Root, root_elements, true); // Create litehtml::elements. if (root_elements.Count != 0) { doc._root = root_elements.Back(); } // Let's process created elements tree if (doc._root != null) { doc.container.get_media_features(doc._media); doc._root.apply_stylesheet(ctx.master_css); // apply master CSS doc._root.parse_attributes(); // parse elements attributes foreach (var css in doc._css) // parse style sheets linked in document { doc._styles.parse_stylesheet(css.text, css.baseurl, doc, !string.IsNullOrEmpty(css.media) ? media_query_list.create_from_string(css.media, doc) : null); } doc._styles.sort_selectors(); // Sort css selectors using CSS rules. if (doc._media_lists.Count != 0) { doc.update_media_lists(doc._media); // get current media features } doc._root.apply_stylesheet(doc._styles); // Apply parsed styles. if (user_styles != null) { doc._root.apply_stylesheet(user_styles); // Apply user styles if any } doc._root.parse_styles(); // Parse applied styles in the elements doc.fix_tables_layout(); // Now the _tabular_elements is filled with tabular elements. We have to check the tabular elements for missing table elements and create the anonymous boxes in visual table layout doc._root.init(); // Fanaly initialize elements } return(doc); }
public override void apply_stylesheet(css stylesheet) { }