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); }
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); }
public static String ToLongFilenameDefault( this LitOptions LO, MDAnnSourceInfo info, MDSourceFile source ) { return(String.Format("{0}\\{1}", info.BaseDir, ToShortFilenameDefault(LO, info, source))); }
public static IEnumerable <IEnumerable <String> > ExtractFromSourceFileDefault( this LitOptions LO, MDSourceFile sourcefile ) { return(ParsingTools.PartitionLines( sourcefile.Lines, line => System.Text.RegularExpressions.Regex.IsMatch(line, @"^#[^#]") )); }
public static String ToShortFilenameDefault( this LitOptions LO, MDAnnSourceInfo info, MDSourceFile source ) { return(ToShortFilenameDefault( LO, info, source.Metadata, source.Author )); }
public static void TagSourceFileDefault( this LitOptions LO, MDSourceFile sourcefile ) { sourcefile.Lines = new List <string>( TagSourceFileDefault( LO, sourcefile.Lines, sourcefile.Metadata.Descriptor, sourcefile.Author.Author ) ); }
//TODO //Make a LitOptionsFactory public static List <MDSourceFile> WriteSourceFileNovel( this LitOptions LO, IEnumerable <String> HeaderAcc, IEnumerable <String> MetadataAcc, LitElm sourceElm, LitAuthor author ) { var retVal = new List <MDSourceFile>(); //Base Case if (sourceElm.Children.Count == 0) { var sourcefile = new MDSourceFile(); sourcefile.Metadata = new LitSceneMetadata() { Text = MetadataAcc.ToList(), Descriptor = sourceElm.TreeTag.Tag.TrimStart('.'), Header = String.Join(" - ", HeaderAcc) }; sourcefile.Author = author; //This is an inelegent way to force the treetag to be the first scene of the novel sourceElm.TreeTag.Tag = String.Format("{0}.01", sourceElm.TreeTag.Tag); sourcefile.Lines = new List <String>( LO.WriteMetadata(sourcefile.Metadata, sourcefile.Author) .Concat(LO.WriteElmSourceLines(sourceElm, author)) ); retVal.Add(sourcefile); } //Inductive Case else { foreach (var child in sourceElm.Children) { var newHeaderAcc = HeaderAcc.Concat(new [] { child.Header }); var newMetadataAcc = MetadataAcc.Concat( LO.WriteElmTextDefault(sourceElm.Source[author]) ); retVal.AddRange(WriteSourceFileNovel( LO, newHeaderAcc, newMetadataAcc, child, author )); } } return(retVal); }
public static void ParseSourceFileDefault( this LitOptions LO, LitNovel novel, MDSourceFile sourceFile ) { var PartitionedElms = LO.ExtractFromSourceFile(sourceFile); //Extract and add the metadata var MetadataLines = LO.ExtractMetadata(PartitionedElms); var LitSceneMetadata = LO.ParseMetadata(novel, MetadataLines); var Author = LO.ParseAuthor(novel, MetadataLines); //Extract and add the scenes var PartitionedElmLines = LO.ExtractElms(PartitionedElms); foreach (var ElmLines in PartitionedElmLines) { var scene = LO.ParseToElm(novel, LitSceneMetadata, Author, ElmLines); novel.AddScene(scene); } }