Example #1
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));
        }
Example #2
0
        public static List <String> WriteNotesObjectLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitObject obj
            )
        {
            var retVal  = new List <String>();
            var AllElms = novel.AllElms();

            //Show speaker instances
            var itemHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Speaker in"
            };

            retVal.Add(itemHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.Items.Contains(obj))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            //Show mentions
            var objectHeader = new MDHeader()
            {
                HeaderLevel = 2,
                Text        = "Mentioned in"
            };

            retVal.Add(objectHeader.ToString());
            retVal.AddRange(
                AllElms
                .Where(e => e.References.Contains(obj))
                .Select(e => e.TreeTag.ToHyperlink())
                );

            return(retVal);
        }