예제 #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
 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
 public static bool IsHeader(Section section)
 {
     return new[] { "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8" }.Contains(section.Name);
 }
예제 #5
0
 public static List<Section> GetHeaderSections(Section section)
 {
     return GetHeaderSectionsRec(section, new List<Section>());
 }