public Chapter(string id, int position, string match, Chapter parent, string text, int level, bool showInToc)
     : base(id, position, match, text)
 {
     this.level = level;
     this.showInToc = showInToc;
     this.parent = parent;
 }
Exemple #2
0
        void ExtractChapters()
        {
            Regex re = new Regex("^([#$]+) ([^\\|]+?)( \\| (.+?))?$", RegexOptions.Multiline);
            MatchCollection mc = re.Matches(document);

            Chapter previousChapter = null;

            foreach (Match m in mc)
            {
                string id = m.Groups[4].ToString().Trim();
                string text = m.Groups[2].ToString().Trim();
                int level = m.Groups[1].Length;
                bool showInToc = m.Groups[1].ToString()[0] == '#';

                Chapter parent = previousChapter;

                while (parent != null && level <= parent.level)
                    parent = parent.parent;

                if (id == "")
                {
                    if (parent != null)
                        id = parent.GetFullTitle() + " - " + text;
                    else
                        id = text;
                }

                if (text == "")
                {
                    log.Add(new LogLine(LogLine.Level.WARN, "Chapter with no text", m.ToString().Trim(), m.Index));
                    continue;
                }

                Chapter h = new Chapter(id, m.Index, m.ToString(), parent, text, level, showInToc);

                if (chapters.ContainsKey(h.id))
                {
                    log.Add(new LogLine(LogLine.Level.ERR, m.ToString(), "Skipping duplicate chapter id '" + id + "'", m.Index));
                    continue;
                }

                chapters[h.id] = h;
                previousChapter = h;
            }
        }