예제 #1
0
        /// <summary>
        /// 格式化习题
        /// </summary>
        /// <param name="selecter"></param>
        /// <returns></returns>
        public void formatQuestion(string color, string title, int index, int size)
        {
            this.RemoveAttr("p", "style", "class");
            this.RemoveAttr("span", "style", "class");

            var body = HtmlDoc.QuerySelector("body");

            if (body == null)
            {
                body           = HtmlDoc.CreateElement("body");
                body.InnerHtml = HtmlDoc.DocumentNode.InnerHtml;
                HtmlDoc.DocumentNode.RemoveAll();
                HtmlDoc.DocumentNode.AppendChild(body);
            }

            var css = new StringBuilder();

            css.AppendLine("body {" + $"color:{color};font-size:30px;font-weight:bold;line-height:1.5;font-family:'微软雅黑';" + "}");
            css.AppendLine("p {margin:0 0 20px 0;}");
            css.AppendLine("p:first-child {margin-bottom:50px;}");
            var style = HtmlDoc.CreateElement("style");

            style.InnerHtml = css.ToString();

            var head = HtmlDoc.QuerySelector("head");

            if (head == null)
            {
                head = HtmlDoc.CreateElement("head");
                HtmlDoc.DocumentNode.InsertBefore(head, body);
            }
            head.AppendChild(style);

            body.InnerHtml = $"<p><span style=\"color:#226cfb\">{index}</span>/{size}.{title}</p>" + body.InnerHtml;
        }