コード例 #1
0
ファイル: Resume.cs プロジェクト: jeswin/JobHunt
        private Section FindParent(Section header, Section currentSection)
        {
            Func<Section,int> getLevel = sec => Convert.ToInt32(sec.Name.Substring(1));

            //Start from top, and see move on until the header refused to fit.
            //To start from top, reverse the sectionChain
            List<Section> sections = new List<Section>();
            sections.Add(currentSection);
            Section section = currentSection;
            while((section = section.Parent) != null)
                sections.Add(section);
            sections.Reverse();

            Section compatible = null;
            foreach (Section s in sections)
            {
                if (HtmlHelper.IsHeader(s.HtmlNode) && (getLevel(s) >= getLevel(header)))
                    break; //If we encounter a header that is smaller than our target header, return the last compatible section.

                if (new []{"body", "div"}.Contains(s.Name) ||
                    (HtmlHelper.IsHeader(s.HtmlNode) && (getLevel(s) < getLevel(header))))
                {
                    compatible = s;
                }
            }
            return compatible;
        }
コード例 #2
0
ファイル: HtmlHelper.cs プロジェクト: jeswin/JobHunt
 private static List<Section> GetHeaderSectionsRec(Section section, List<Section> headersList)
 {
     foreach (Section child in section.ChildSections)
     {
         if (IsHeader(section))
             headersList.Add(child);
         GetHeaderSectionsRec(child, headersList);
     }
     return headersList;
 }
コード例 #3
0
ファイル: Resume.cs プロジェクト: jeswin/JobHunt
        private void ParseTree(XmlNode node, Section currentSection)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                Section section = new Section();
                section.Name = child.Name.ToLower();
                section.HtmlNode = child;

                if (!HtmlHelper.IsHeader(child))
                {
                    section.Parent = currentSection;
                    currentSection.ChildSections.Add(section);
                    ParseTree(child, section);
                }
                else
                {
                    Section parent = FindParent(section, currentSection);
                    section.Parent = parent;
                    parent.ChildSections.Add(section);
                    currentSection = section;
                }
            }
        }
コード例 #4
0
ファイル: HtmlHelper.cs プロジェクト: jeswin/JobHunt
 public static bool IsHeader(Section section)
 {
     return new[] { "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8" }.Contains(section.Name);
 }
コード例 #5
0
ファイル: HtmlHelper.cs プロジェクト: jeswin/JobHunt
 public static List<Section> GetHeaderSections(Section section)
 {
     return GetHeaderSectionsRec(section, new List<Section>());
 }