Exemplo n.º 1
0
        //string BodyHeading = "";
        private string GetHtml(string filename)
        {
            if (HtmlCache.ContainsKey(filename))
            {
                return(HtmlCache[filename]);
            }

            string         html    = "";
            MyHtmlDocument htmlDoc = new MyHtmlDocument();
            var            Stream  = htmlDoc.GetStreamOPF(filename);

            using (Tidy.Document doc = Tidy.Document.FromStream(Stream))
            {
                doc.ShowWarnings            = false;
                doc.Quiet                   = true;
                doc.OutputXhtml             = true;
                doc.InputCharacterEncoding  = Tidy.EncodingType.Utf8;
                doc.OutputCharacterEncoding = Tidy.EncodingType.Utf8;
                doc.IndentAttributes        = false;
                doc.IndentBlockElements     = Tidy.AutoBool.Auto;
                doc.NewBlockLevelTags       = "svg,image";
                doc.WrapAt                  = 0;
                doc.CleanAndRepair();
                html = doc.Save();
                HtmlCache.Add(filename, html);
            }


            return(html);
        }
Exemplo n.º 2
0
    private string TidyHtml(string FullFilePath)
    {
        TidyManaged.Document TidyDocObj = TidyManaged.Document.FromFile(FullFilePath);
        TidyDocObj.OutputHtml   = true;
        TidyDocObj.ShowWarnings = false;
        TidyDocObj.Quiet        = true;
        TidyDocObj.ForceOutput  = true;
        TidyDocObj.CleanAndRepair();

        string TidyHtml = TidyDocObj.Save();

        TidyDocObj.Dispose();
        return(TidyHtml);
    }
Exemplo n.º 3
0
		private void SetUpDefaultTidy(Document document) {
            document.Quiet = true;
		    document.ShowWarnings = false;
			document.CharacterEncoding = EncodingType.Utf8;
			document.NewInlineTags = GetNewInlineElements();
			document.NewBlockLevelTags = GetNewBlockTags();
			document.OutputXml = true;
			document.OutputNumericEntities = true;
			document.DocType = DocTypeMode.Omit;
			document.DropEmptyParagraphs = true;
			document.DropFontTags = true;
			document.DropProprietaryAttributes = true;
			document.MergeDivs = AutoBool.No;
			document.MergeSpans = AutoBool.No;
			document.EscapeCdata = true;
		    document.RemoveComments = true;
		    document.MaximumErrors = 0;
		}
Exemplo n.º 4
0
        public string TidyHtml(string newHtml)
        {
            string ret    = string.Empty;
            Stream stream = newHtml.ToStream();

            using (Tidy.Document doc = Tidy.Document.FromStream(stream))
            {
                doc.ShowWarnings            = false;
                doc.Quiet                   = true;
                doc.OutputXhtml             = true;
                doc.CharacterEncoding       = Tidy.EncodingType.Utf8;
                doc.InputCharacterEncoding  = Tidy.EncodingType.Utf8;
                doc.OutputCharacterEncoding = Tidy.EncodingType.Utf8;
                doc.IndentAttributes        = false;
                doc.IndentBlockElements     = Tidy.AutoBool.Yes;
                doc.WrapAt                  = 0;
                doc.NewBlockLevelTags       = svgElements;
                doc.AddTidyMetaElement      = false;
                doc.MakeClean               = true;
                doc.ForceOutput             = true;
                doc.DocType                 = Tidy.DocTypeMode.Strict;

                doc.PreserveEntities        = true;
                doc.AnchorAsName            = false;
                doc.EncloseBodyText         = true;
                doc.EncloseBlockText        = true;
                doc.EnsureLiteralAttributes = true;
                doc.AddXmlDeclaration       = true;
                //doc.RemoveEndTags = true;
                //doc.UseXmlParser = true;

                doc.CleanAndRepair();
                ret = doc.Save();
                ret = FixSVGCase(ret);
            }

            return(ret);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Opens the full HTML of the page the current issue is on.
        /// Scrolls the editor to the code for that issue as well.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenHTML_Button(object sender, RoutedEventArgs e)
        {
            if (curPage == null)
            {
                e.Handled = true;
                return;
            }
            editor.WordWrap = false;
            var newNode     = HtmlNode.CreateNode(editor.Text);
            var textToMatch = Array.ConvertAll(editor.Text.CleanSplit("\r\n"), s => s.Replace("\t", ""));

            curNode.ParentNode.ReplaceChild(newNode, curNode);
            curNode = newNode;
            MemoryStream str = new MemoryStream(Encoding.UTF8.GetBytes(curPage.Doc.DocumentNode.OuterHtml));

            using (TidyManaged.Document my_doc = Document.FromStream(str))
            {
                my_doc.CharacterEncoding       = EncodingType.Utf8;
                my_doc.InputCharacterEncoding  = EncodingType.Utf8;
                my_doc.OutputCharacterEncoding = EncodingType.Utf8;
                my_doc.ShowWarnings            = false;
                my_doc.Quiet               = true;
                my_doc.OutputXhtml         = true;
                my_doc.OutputXml           = true;
                my_doc.IndentBlockElements = AutoBool.Yes;
                my_doc.IndentAttributes    = false;
                my_doc.IndentCdata         = true;
                my_doc.AddVerticalSpace    = false;
                my_doc.OutputBodyOnly      = AutoBool.Yes;
                my_doc.IndentWithTabs      = true;
                my_doc.WrapAt              = 0;
                my_doc.CleanAndRepair();
                editor.Text = "<body>\r\n" + my_doc.Save() + "\r\n</body>";
            }
            str.Close();
            var compareText = editor.Text.CleanSplit("\r\n");
            int lineNum     = 0;

            for (int i = 0; i < compareText.Length - textToMatch.Length; i++)
            {
                bool foundMatch = false;
                if (compareText[i].Contains(textToMatch[0]))
                {
                    foundMatch = true;
                    for (int j = 0; j < textToMatch.Length; j++)
                    {
                        if (!compareText[i + j].Contains(textToMatch[j]))
                        {
                            foundMatch = false;
                        }
                    }
                }
                if (foundMatch)
                {
                    lineNum = i;
                    break;
                }
            }
            double vertOffset = (editor.TextArea.TextView.DefaultLineHeight) * lineNum;

            editor.ScrollToVerticalOffset(vertOffset);
            editor.WordWrap = true;
            curNode         = curPage.Doc.DocumentNode.SelectSingleNode("//body");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Finds the current node based on the current selected issue
        /// Uses an XPath selector that was saved when the report was generated
        /// </summary>
        private void SetCurrentNode()
        {
            // Get current selected issue
            A11yData row;

            try
            {
                row = (A11yData)IssueGrid.SelectedItem;
            }catch
            {
                return;
            }

            if (row == null || row.Location == null)
            {
                browser.Url = "";
                curPage     = null;
                curNode     = null;
                editor.Clear();
                return;
            }

            // Get issues HTML file
            if (isCanvas)
            {
                var    pageInfo    = course.PageInfoList.Where(item => item.Keys.Count(loc => loc.Contains(row.Location.CleanSplit("?").FirstOrDefault())) > 0).FirstOrDefault();
                string question_id = row.Location.CleanSplit("?").LastOrDefault().CleanSplit("&").FirstOrDefault().CleanSplit("=").LastOrDefault();
                if (!row.Location.Contains("question_num"))
                {
                    question_id = "";
                }
                string answer_id = row.Location.CleanSplit("?").LastOrDefault().CleanSplit("&").LastOrDefault().CleanSplit("=").LastOrDefault();
                if (!row.Location.Contains("answer_num"))
                {
                    answer_id = "";
                }
                bool comment  = row.Location.Contains("answer_comment");
                var  location = pageInfo.Keys.ElementAt(0);
                curCanvasItem = pageInfo;
                curPage       = new DataToParse(location, curCanvasItem[location].getContent(question_id, answer_id, comment));
            }
            else
            {
                var url = (directory.Text + "\\" + row.Location.Split('/').LastOrDefault());
                curPage = new DataToParse(url);
            }



            // Find the issue in the page
            // TODO: Simplify switch statement based on new XPath selector
            switch (row.IssueType)
            {
            case "Link":
                switch (row.DescriptiveError)
                {
                case "Non-Descriptive Link":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                case "JavaScript Link":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                case "Broken Link":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                default:
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                    break;
                }
                break;

            case "Semantics":
                switch (row.DescriptiveError)
                {
                case "Missing title/label":
                    ;
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                case "Improper Headings":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                case "Bad use of <i> and/or <b>":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                    break;

                default:
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                    break;
                }
                break;

            case "Image":
                switch (row.DescriptiveError)
                {
                case "No Alt Attribute":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                case "Non-Descriptive alt tags":
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    break;

                default:
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                    break;
                }
                break;

            case "Media":
                switch (row.DescriptiveError)
                {
                case "Transcript Needed":
                    if (row.Notes.Contains("Video number"))
                    {
                        curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    }
                    else if (row.Notes.Contains("BrightCove video with id"))
                    {
                        curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                    }
                    break;

                default:
                    curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                    break;
                }

                break;

            case "Table":
                int tableIndex = int.Parse(row.Notes.Split(':')[0].Split(' ').LastOrDefault()) - 1;
                curNode = curPage.Doc.DocumentNode.SelectNodes("//table")[tableIndex];
                break;

            case "Misc":
                curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                break;

            case "Color":
                curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                break;

            case "Keyboard":
                curNode = curPage.Doc.DocumentNode.SelectSingleNode(row.html);
                break;

            default:
                curNode = curPage.Doc.DocumentNode.SelectSingleNode("//body");
                break;
            }
            if (curNode == null)
            {
                System.Windows.MessageBox.Show("Issue was not found, report data may be old. You probably want to generate a new report.");
                return;
            }

            // Use a stream as the TidyManaged.Document FromString method does not correctly use encoding.
            MemoryStream str = new MemoryStream(Encoding.UTF8.GetBytes(curNode.OuterHtml));

            using (TidyManaged.Document my_doc = Document.FromStream(str))
            {
                my_doc.ShowWarnings        = false;
                my_doc.Quiet               = true;
                my_doc.OutputXhtml         = true;
                my_doc.OutputXml           = true;
                my_doc.IndentBlockElements = AutoBool.Yes;
                my_doc.IndentAttributes    = false;
                my_doc.IndentCdata         = true;
                my_doc.AddVerticalSpace    = false;
                my_doc.WrapAt              = 0;
                my_doc.OutputBodyOnly      = AutoBool.Yes;
                my_doc.IndentWithTabs      = true;
                my_doc.CleanAndRepair();
                editor.Text = my_doc.Save();
                editor.ScrollToHome();
            }

            // Highlight the element
            var style = curNode.GetAttributeValue("style", "");

            if (style == "")
            {
                style = "border: 5px solid red";
            }
            else
            {
                style += "; border: 5px solid red;";
            }
            curNode.Id = "focus_this";
            curNode.SetAttributeValue("style", style);

            // Reload HTML and scroll to the issue
            browser.LoadHtmlAndWait(curPage.Doc.DocumentNode.OuterHtml);
            browser.QueueScriptCall($"var el = document.getElementById('focus_this'); el.scrollIntoView({{behavior: 'smooth' , block: 'center', inline: 'center'}});");
        }