Esempio n. 1
0
            private void Initialise(string text, TableHeaderRowType tableHeaderType, Dictionary <String, String> customAttributes)
            {
                Clear();

                if (String.IsNullOrWhiteSpace(text))
                {
                    return;
                }

                try
                {
                    // Defaults
                    this.TaskHtml         = text;
                    this.TableHeaderRow   = TableHeaderRowType.NotRequired;
                    this.CustomAttributes = customAttributes;

                    var doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(text);

                    // Remove everything before the first bit of text
                    // or the first major structural element
                    var elm = doc.DocumentNode.FirstChild;

                    while (elm != null)
                    {
                        // get next sibling in case we need to delete this node
                        var nextElm = elm.NextSibling;

                        if (AgilityUtils.ElementHasContent(elm))
                        {
                            break;
                        }

                        elm.Remove();
                        elm = nextElm;
                    }

                    if (elm != null)
                    {
                        switch (elm.Name.ToUpper())
                        {
                        case "TABLE":
                            CleanTableCellContents(elm);

                            this.Style          = StyleType.Table;
                            this.TableHeaderRow = tableHeaderType;
                            break;

                        case "UL":
                            this.Style = StyleType.UnorderedList;
                            break;

                        case "OL":
                            this.Style = StyleType.OrderedList;
                            break;
                        }

                        if (this.Style != StyleType.None)
                        {
                            String taskHtml = GetTaskHtml(elm);

                            int taskStart = elm.OuterHtml.IndexOf(taskHtml);

                            this.StartHtml = elm.OuterHtml.Substring(0, taskStart);
                            this.EndHtml   = elm.OuterHtml.Substring(taskStart + taskHtml.Length);

                            // Handle table header row
                            if (this.Style == StyleType.Table)
                            {
                                if (tableHeaderType != TableHeaderRowType.NotRequired)
                                {
                                    // Prefix 'Table:Tbody' with header row
                                    int tbodyStart = this.StartHtml.ToUpper().IndexOf("<TBODY>");

                                    if (tbodyStart != -1)
                                    {
                                        if (tableHeaderType == TableHeaderRowType.AutoGenerate)
                                        {
                                            var theadStyle = "style=font-weight:bold;font-size:1.5em;display:table-header-group;";

                                            var header    = FormatHeader(taskHtml);
                                            var theadHtml = String.Format("\n<thead {0}>{1}</thead>", theadStyle, header);

                                            this.StartHtml = this.StartHtml.Insert(tbodyStart, theadHtml);
                                        }
                                        else if (tableHeaderType == TableHeaderRowType.FirstRow)
                                        {
                                            // Move the first row from 'TaskHtml' to 'StartHtml' and
                                            // change its type to 'thead'
                                            var tableBody = AgilityUtils.FindElement(elm, "TBODY");
                                            var firstRow  = AgilityUtils.FindElement(tableBody, "TR");

                                            if (firstRow != null)
                                            {
                                                var theadHtml = String.Format("\n<thead>{0}</thead>", firstRow.OuterHtml);
                                                this.StartHtml = this.StartHtml.Insert(tbodyStart, theadHtml);

                                                tableBody.ChildNodes.Remove(firstRow);
                                            }
                                        }
                                    }

                                    this.TableHeaderRow = tableHeaderType;
                                }
                            }
                        }

                        this.TaskHtml = InjectTextColourPlaceholder(elm).Trim();
                    }
                }
                catch
                {
                    this.Clear();
                }
            }
            // ------------------------------------------------------

            public Layout(String text, TableHeaderRowType type)
            {
                Initialise(text, type);
            }
Esempio n. 3
0
            // ------------------------------------------------------

            public Layout(String text, TableHeaderRowType type, Dictionary <String, String> customAttributes)
            {
                Initialise(text, type, customAttributes);
            }
            // ------------------------------------------------------

            public Layout(String text, TableHeaderRowType type, HtmlReportUtils.CustomAttributes customAttributes)
            {
                Initialise(text, type, customAttributes);
            }