Exemple #1
0
 internal HtmlForm(HtmlObject element, string name, string action, HtmlFormMethod method, ContentType encType)
 {
     Element = element;
     Name    = name;
     Action  = action;
     Method  = method;
     EncType = encType;
 }
Exemple #2
0
        static IEnumerable <T> TableRowsCore <T>(HtmlObject table, Func <HtmlObject, IEnumerable <HtmlObject>, T> rowSelector)
        {
            // TODO https://www.w3.org/TR/html5/tabular-data.html#processing-model-1

            var spans = new ArrayList <CellSpan>();

            foreach (var e in
                     from g in table.ChildElements
                     where g.IsNamed("tbody") || g.IsNamed("thead") || g.IsNamed("tfoot") || g.IsNamed("tr")
                     from tr in g.IsNamed("tr")
                         ? new[] { g } :
                     g.ChildElements.Where(e => e.IsNamed("tr"))
                     select new
            {
                Row = tr,
                Cells = tr.ChildElements.Where(e => e.IsNamed("td") || e.IsNamed("th")).ToArray(),
            })
            {
                var tds = e.Cells;
                spans.EnsureCapacity(tds.Length);

                var cells = new ArrayList <HtmlObject>();
                cells.EnsureCapacity(tds.Length);

                var i = 0;
                foreach (var td in tds)
                {
                    while (true)
                    {
                        var rspan = spans[i, CellSpan.Zero];
                        if (rspan.Rows == 0)
                        {
                            break;
                        }
                        i += rspan.Cols;
                    }

                    var colspan = int.TryParse(td.GetAttributeValue("colspan"), NumberStyles.Integer & ~NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var cn) ? cn : 1;
                    var rowspan = int.TryParse(td.GetAttributeValue("rowspan"), NumberStyles.Integer & ~NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var rn) ? rn : 1;
                    var span    = colspan > 1 || rowspan > 1 ? new CellSpan(colspan, rowspan) : CellSpan.One;

                    spans[i] = span;
                    cells[i] = td;

                    i += span.Cols;
                }

                for (i = 0; i < spans.Count; i++)
                {
                    var span    = spans[i];
                    var rowspan = span.Rows - 1;
                    spans[i] = rowspan > 0 ? new CellSpan(span.Cols, rowspan) : CellSpan.Zero;
                }

                yield return(rowSelector(e.Row, cells.ToArray()));
            }
        }
Exemple #3
0
 public static IEnumerable <T> TableRows <T>(this HtmlObject table, Func <HtmlObject, IEnumerable <HtmlObject>, T> rowSelector)
 {
     if (table == null)
     {
         throw new ArgumentNullException(nameof(table));
     }
     if (!table.IsNamed("table"))
     {
         throw new ArgumentException($"Element is <{table.Name}> and not an HTML table.", nameof(table));
     }
     if (rowSelector == null)
     {
         throw new ArgumentNullException(nameof(rowSelector));
     }
     return(TableRowsCore(table, rowSelector));
 }
Exemple #4
0
 public override IEnumerable <HtmlObject> QuerySelectorAll(string selector, HtmlObject context) =>
 from node in (((HapHtmlObject)context)?.Node ?? _document.DocumentNode).QuerySelectorAll(selector)
 orderby node.StreamPosition
 select GetPublicObject(node);
Exemple #5
0
 public virtual HtmlObject QuerySelector(string selector, HtmlObject context) =>
 QuerySelectorAll(selector, context).FirstOrDefault();
Exemple #6
0
 public abstract IEnumerable <HtmlObject> QuerySelectorAll(string selector, HtmlObject context);