Пример #1
0
 public static String ToShortNotesFilenameDefault(
     this LitOptions LO,
     MDAnnSourceInfo info
     )
 {
     return(String.Format("{0}notes.md", info.Prefix));
 }
Пример #2
0
        public static List <String> WriteTextGQQ(this LitOptions LO, String Text, int LineLength)
        {
            var retVal = new List <String>();
            var paragraphs = System.Text.RegularExpressions.Regex.Split(Text, "\r\n");
            int fromIndex, toIndex, seekIndex;

            foreach (var paragraph in paragraphs)
            {
                fromIndex = 0;
                toIndex   = 0;
                seekIndex = 1;
                while (fromIndex < paragraph.Length)
                {
                    while (toIndex + seekIndex < paragraph.Length && toIndex + seekIndex - fromIndex < LineLength)
                    {
                        if (paragraph[toIndex + seekIndex] == ' ')
                        {
                            toIndex   = toIndex + seekIndex;
                            seekIndex = 0;
                        }
                        seekIndex++;
                    }
                    if (toIndex + seekIndex >= paragraph.Length)
                    {
                        toIndex = toIndex + seekIndex;
                    }
                    retVal.Add(paragraph.Substring(fromIndex, toIndex - fromIndex).Trim());
                    toIndex++;                     //Skip the space
                    fromIndex = toIndex;
                    seekIndex = 1;
                }
                retVal.Add("");
            }
            return(retVal);
        }
Пример #3
0
 public static String WriteLinkDefault(
     this LitOptions LO,
     MDLinkLine link
     )
 {
     return(String.Format(@"[{0}]: # {{{1}}}", link.Link, link.Tag));
 }
Пример #4
0
        public static MDSourceFile WriteSourceFileDefault(
            this LitOptions LO,
            LitNovel novel,
            LitSceneMetadata metadata,
            LitAuthor author
            )
        {
            //Write all of the lines of the file
            var lines = LO.WriteMetadata(metadata, author);
            var query = novel.Scenes
                        .Where(s => s.Metadata == metadata)
                        .Select(s => LO.WriteElmSourceLines(s, author));

            foreach (var scenelines in query)
            {
                lines.AddRange(scenelines);
            }
            //Create the file
            var SourceFile = new MDSourceFile()
            {
                Metadata = metadata,
                Author   = author,
                Lines    = lines
            };

            return(SourceFile);
        }
Пример #5
0
        public static List <String> WriteNotesLinesDefault(
            this LitOptions LO,
            LitNovel novel,
            LitRef reference
            )
        {
            var retVal = new List <String>();

            retVal.Add(LO.WriteNotesHeader(novel, reference));
            retVal.Add(LO.WriteNotesLink(novel, reference));
            retVal.AddRange(LO.WriteNotesCommentary(novel, reference));
            retVal.AddRange(LO.WriteNotesTags(novel, reference));

            if (reference is LitChar)
            {
                retVal.AddRange(LO.WriteNotesCharLines(novel, reference as LitChar));
            }
            if (reference is LitPlace)
            {
                retVal.AddRange(LO.WriteNotesPlaceLines(novel, reference as LitPlace));
            }
            if (reference is LitMyth)
            {
                retVal.AddRange(LO.WriteNotesMythLines(novel, reference as LitMyth));
            }
            if (reference is LitObject)
            {
                retVal.AddRange(LO.WriteNotesObjectLines(novel, reference as LitObject));
            }

            return(retVal);
        }
Пример #6
0
 public static String WriteRefTagEXDefault(
     this LitOptions LO,
     LitRef reference
     )
 {
     return(String.Format(@"/\v^# {0}$", SanitizeForRegex(reference.Tags.First().Tag)));
 }
 public static IEnumerable <String> BuildSourceFilenamesNovel(
     this LitOptions LO,
     MDAnnSourceInfo info
     )
 {
     return(new String[] { String.Format("{0}\\{1}", info.BaseDir, info.Prefix) });
 }
Пример #8
0
        /// <summary>
        /// Takes a litelm and writes the links for it that go under the header
        /// </summary>
        /// <param name="litelm"></param>
        /// <returns></returns>
        public static List <String> WriteElmLinksDefault(this LitOptions LO, LitElm litelm)
        {
            var retVal = new List <String>();

            retVal.Add(MakeLinkLine("TreeTag", litelm.TreeTag.Tag));
            retVal.AddRange(litelm.UserTags.Select(t =>
                                                   MakeLinkLine("UserTag", t.Tag)
                                                   ));
            retVal.AddRange(litelm.Actors.Select(a =>
                                                 MakeLinkLine("Actor", a.Tags.First().Tag)
                                                 ));
            retVal.AddRange(litelm.Speakers.Select(a =>
                                                   MakeLinkLine("Speaker", a.Tags.First().Tag)
                                                   ));
            retVal.AddRange(litelm.Locations.Select(p =>
                                                    MakeLinkLine("Location", p.Tags.First().Tag)
                                                    ));
            retVal.AddRange(litelm.Events.Select(a =>
                                                 MakeLinkLine("Event", a.Tags.First().Tag)
                                                 ));
            retVal.AddRange(litelm.Items.Select(a =>
                                                MakeLinkLine("Item", a.Tags.First().Tag)
                                                ));
            foreach (var reference in litelm.References)
            {
                retVal.Add(LO.WriteReferenceLink(reference));
            }
            return(retVal);
        }
Пример #9
0
 public static String ToLongTagFilenameDefault(
     this LitOptions LO,
     MDAnnSourceInfo info
     )
 {
     return(String.Format("{0}\\{1}", info.BaseDir, LO.ToShortTagFilename(info)));
 }
Пример #10
0
        public static IEnumerable <String> BuildSourceFilenamesDefault(this LitOptions LO, MDAnnSourceInfo info)
        {
            var files = System.IO.Directory.GetFiles(info.BaseDir, info.Prefix + "*.md");

            Array.Sort(files);
            return(files);
        }
Пример #11
0
        public static List <MDSourceFile> BuildSourceFilesDefault(this LitOptions LO, MDAnnSourceInfo info, IEnumerable <String> files)
        {
            var    retVal  = new List <MDSourceFile>();
            string pattern = String.Format(@"{0}(\d[\d\.]+)\.([^\.]+)\.md", info.Prefix);
            var    query   = files
                             .Select(s => new {
                File  = s,
                Match = System.Text.RegularExpressions.Regex.Match(s, pattern)
            })
                             .Where(f => f.Match.Success);
            MDSourceFile SourceObj;

            foreach (var file in query)
            {
                SourceObj       = new MDSourceFile();
                SourceObj.Lines = new List <String>(
                    System.IO.File.ReadAllLines(file.File)
                    );
                SourceObj.Metadata = new LitSceneMetadata()
                {
                    Descriptor = file.Match.Groups[1].Value
                };
                SourceObj.Author = new LitAuthor()
                {
                    Author = file.Match.Groups[2].Value
                };
                retVal.Add(SourceObj);
            }
            return(retVal);
        }
Пример #12
0
 public static void TagAnnSourceDefault(this LitOptions LO, MDAnnSource source)
 {
     foreach (var sourceFile in source.Sources)
     {
         LO.TagSourceFile(sourceFile);
     }
 }
Пример #13
0
 public static String WriteTagLineDefault(
     this LitOptions LO,
     MDTag tag
     )
 {
     return(String.Format("{0}\t{1}\t{2}", tag.TagName, tag.TagFile, tag.TagLine));
 }
Пример #14
0
 public static String ToShortTagFilenameDefault(
     this LitOptions LO,
     MDAnnSourceInfo info
     )
 {
     return("tags");
 }
Пример #15
0
        public static String WriteReferenceLinkDefault(
            this LitOptions LO,
            LitRef reference
            )
        {
            string link = "";

            if (reference is LitChar)
            {
                link = "Character";
            }
            else if (reference is LitPlace)
            {
                link = "Place";
            }
            else if (reference is LitMyth)
            {
                link = "Myth";
            }
            else if (reference is LitObject)
            {
                link = "Object";
            }
            return(LO.WriteLink(new MDLinkLine()
            {
                Tag = reference.Tags.First().Tag,
                Link = link
            }));
        }
Пример #16
0
        public static String WriteNotesLinkDefault(
            this LitOptions LO,
            LitNovel novel,
            LitRef reference
            )
        {
            var retVal = new MDLinkLine();

            retVal.Link = "Reference";
            if (reference is LitChar)
            {
                retVal.Tag = "Character";
            }
            else if (reference is LitPlace)
            {
                retVal.Tag = "Place";
            }
            else if (reference is LitMyth)
            {
                retVal.Tag = "Myth";
            }
            else if (reference is LitObject)
            {
                retVal.Tag = "Object";
            }
            else
            {
                retVal.Tag = "Reference";
            }
            return(retVal.ToString());
        }
Пример #17
0
 public static String ToLongFilenameDefault(
     this LitOptions LO,
     MDAnnSourceInfo info,
     MDSourceFile source
     )
 {
     return(String.Format("{0}\\{1}", info.BaseDir, ToShortFilenameDefault(LO, info, source)));
 }
Пример #18
0
 public static List <String> WriteNotesCommentaryDefault(
     this LitOptions LO,
     LitNovel novel,
     LitRef reference
     )
 {
     return(new List <string>(new String[] { reference.Commentary }));
 }
Пример #19
0
 public static String ToShortFilenameDefault(
     this LitOptions LO,
     String Prefix,
     String descriptor,
     String author
     )
 {
     return(String.Format("{0}{1}.{2}.md", Prefix, descriptor, author));
 }
Пример #20
0
 public static IEnumerable <MDLinkLine> ExtractElmLinkLinesDefault(
     this LitOptions LO,
     IEnumerable <String> lines
     )
 {
     return(lines
            .Select(l => LO.ParseLink(l))
            .Where(l => l != null));
 }
 public static IEnumerable <String> ExtractMetadataDefault(this LitOptions LO, IEnumerable <IEnumerable <String> > PartitionedScenes)
 {
     return(PartitionedScenes.Where(lines =>
                                    lines.Select(l => LO.ParseLink(l))
                                    .Where(link => link != null)
                                    .Where(link => link.Link.Equals("Metadata"))
                                    .Count() > 0
                                    ).FirstOrDefault());
 }
Пример #22
0
 public static IEnumerable <IEnumerable <String> > ExtractFromSourceFileDefault(
     this LitOptions LO,
     MDSourceFile sourcefile
     )
 {
     return(ParsingTools.PartitionLines(
                sourcefile.Lines,
                line => System.Text.RegularExpressions.Regex.IsMatch(line, @"^#[^#]")
                ));
 }
Пример #23
0
        public static String SourceLinesToStringIdentity(this LitOptions LO, IEnumerable <string> lines)
        {
            var sb = new StringBuilder();

            foreach (var line in lines)
            {
                sb.AppendLine(line);
            }
            return(sb.ToString().Trim());
        }
Пример #24
0
        public static MDNotesFile WriteNotesFileDefault(this LitOptions LO, LitNovel novel)
        {
            var retVal = new MDNotesFile();

            foreach (var reference in novel.References)
            {
                retVal.Lines.AddRange(LO.WriteNotesLines(novel, reference));
            }
            return(retVal);
        }
Пример #25
0
 public static void ParseElmTextDefault(
     this LitOptions LO,
     LitNovel novel,
     LitElm elm,
     LitAuthor author,
     IEnumerable <String> lines
     )
 {
     elm.Source[author] = LO.SourceLinesToString(lines);
 }
        public static List <String> WriteMetadataDefault(this LitOptions LO, LitSceneMetadata metadata, LitAuthor sourceinfo)
        {
            var retVal = new List <String>();

            retVal.Add(String.Format("# {0}", metadata.Header));
            retVal.Add(MakeLinkLine("Metadata", metadata.Descriptor));
            retVal.Add(MakeLinkLine("Descriptor", metadata.Descriptor));
            retVal.Add(sourceinfo.ToSourceLine());
            retVal.AddRange(metadata.Text);
            return(retVal);
        }
Пример #27
0
        public static void ParseElmHeaderDefault(
            this LitOptions LO,
            LitNovel novel,
            LitElm elm,
            IEnumerable <String> SceneLines
            )
        {
            var headerInfo = LO.ParseHeader(SceneLines.First());

            elm.Header = headerInfo.Text;
        }
Пример #28
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)));
        }
Пример #29
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));
        }
Пример #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="LO"></param>
 /// <param name="PartitionedScenes"></param>
 /// <returns></returns>
 public static IEnumerable <IEnumerable <String> > ExtractElmsDefault(
     this LitOptions LO,
     IEnumerable <IEnumerable <String> > PartitionedScenes
     )
 {
     return(PartitionedScenes.Where(lines =>
                                    lines.Select(l => LO.ParseLink(l))
                                    .Where(link => link != null)
                                    .Where(link => link.Link.Equals("TreeTag"))
                                    .Count() > 0
                                    ));
 }