public static IEnumerable <IEnumerable <String> > ExtractFromSourceFileDefault(
     this LitOptions LO,
     MDSourceFile sourcefile
     )
 {
     return(ParsingTools.PartitionLines(
                sourcefile.Lines,
                line => System.Text.RegularExpressions.Regex.IsMatch(line, @"^#[^#]")
                ));
 }
Example #2
0
        public static IEnumerable <IEnumerable <String> > ExtractSubElmsDefault(
            this LitOptions LO,
            IEnumerable <String> lines
            )
        {
            //Partition the events
            int headerLevel = LO.ParseHeader(lines.First()).HeaderLevel + 1;
            var pattern     = String.Format(@"^{0}[^#]", new String('#', headerLevel));

            return(ParsingTools.PartitionLines(lines, line => System.Text.RegularExpressions.Regex.IsMatch(line, pattern)));
        }
Example #3
0
        public static LitRef ParseToLitRefDefault(this LitOptions LO, LitNovel novel, IEnumerable <String> lines)
        {
            if (lines.Count() == 0)
            {
                return(null);
            }
            var PartitionedLines = ParsingTools.PartitionLines(lines, l => System.Text.RegularExpressions.Regex.IsMatch(l, @"^##[^#]"));
            var link             = PartitionedLines.First().Select(s => LO.ParseLink(s)).Where(l => l != null).First();

            var retVal = new LitRef();

            //Do the specific things for this style of reference
            if (link.Link.Equals("Reference"))
            {
                if (link.Tag.Equals("Character"))
                {
                    retVal = new LitChar();
                    (retVal as LitChar).ParseLitChar(PartitionedLines);
                }
                else if (link.Tag.Equals("Place"))
                {
                    retVal = new LitPlace();
                }
                else if (link.Tag.Equals("Myth"))
                {
                    retVal = new LitMyth();
                }
                else if (link.Tag.Equals("Object"))
                {
                    retVal = new LitObject();
                }
            }

            //Get the first tag of the reference
            string pattern = @"^# (.+)";
            var    match   = System.Text.RegularExpressions.Regex.Match(lines.First(), pattern);

            retVal.Tags.Add(new LitTag(match.Groups[1].Value));

            //Save the commentary
            retVal.Commentary = LO.SourceLinesToString(PartitionedLines.First());

            //Save the tags
            pattern = "^## Tags$";
            var tagsList = PartitionedLines.Where(list => System.Text.RegularExpressions.Regex.IsMatch(list.First(), pattern)).First();

            foreach (var tagline in tagsList.Where(s => LO.IsSourceLine(s)))
            {
                retVal.AddTag(new LitTag(tagline));
            }

            return(novel.AddReferenceDistinct(retVal));
        }
        public static IEnumerable <IEnumerable <String> > ExtractNotesRefsDefault(
            this LitOptions LO,
            MDNotesFile notesfile
            )
        {
            string pattern = @"^#[^#]";

            return(ParsingTools.PartitionLines(
                       notesfile.Lines,
                       (s => System.Text.RegularExpressions.Regex.IsMatch(s, pattern))
                       ));
        }
        /// <summary>
        /// Default implentation to takes all of the source lines of a list of arbitrary strings and turns them into a string
        /// GOOD!
        /// </summary>
        public static String SourceLinesToStringDefault(this LitOptions LO, IEnumerable <string> lines)
        {
            var           paragraphs = ParsingTools.PartitionLines(lines.Where(s => LO.IsSourceLine(s)), line => String.IsNullOrWhiteSpace(line));
            StringBuilder sb         = new StringBuilder();

            foreach (var paralist in paragraphs)
            {
                foreach (var paraline in paralist.Where(l => !String.IsNullOrEmpty(l)))
                {
                    sb.Append(paraline.TrimEnd('\r', '\n'));
                    sb.Append(" ");
                }
                sb.Append("\r\n");
            }
            return(sb.ToString().Trim());
        }