/// <summary>
        /// Checks Opening Marker for Unique End Marker 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        public List<LinterResult> CheckOpenMarker(Marker input, USFMDocument root)
        {
            List<int> markerPositions = new List<int>();
            List<Marker> hierarchy = root.GetHierarchyToMarker(input);
            List<Marker> siblingMarkers = new List<Marker>(hierarchy[hierarchy.Count - 2].Contents);
            siblingMarkers.Reverse();
            foreach (Marker sibling in siblingMarkers)
            {
                if (sibling.GetType() == input.GetType())
                {
                    markerPositions.Add(sibling.Position);
                }
                else if (sibling.GetType() == markerPairs[input.GetType()])
                {
                    if (markerPositions.Count > 0)
                    {
                        markerPositions.RemoveAt(markerPositions.Count - 1);
                    }
                }
            }
            List<LinterResult> results = new List<LinterResult>();
            foreach (int loneMarkerPosition in markerPositions)
            {
                results.Add(new LinterResult
                {
                    Position = loneMarkerPosition,
                    Level = LinterLevel.Error,
                    Message = $"Missing Opening marker for {input.GetType().Name}"
                });

            }
            return results;

        }
Exemple #2
0
        /// <summary>
        /// Checks if Table Cells/Headers are contained within a Table Row
        /// </summary>
        /// <param name="input"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        private LinterResult ValidateTable(Marker input, USFMDocument root)
        {
            List <Marker> hierarchy    = root.GetHierarchyToMarker(input);
            Marker        parentMarker = hierarchy[hierarchy.Count - 2];

            if (!(parentMarker is TRMarker))
            {
                return(new LinterResult
                {
                    Position = input.Position,
                    Level = LinterLevel.Warning,
                    Message = $"Missing Table Row container"
                });
            }
            return(null);
        }
        /// <summary>
        /// Write the contents of the usfm document to a CSV
        /// </summary>
        /// <param name="document">The document whose contents to write</param>
        /// <param name="csv">The CSV writer to write the content to</param>
        private static void WriteContent(USFMDocument document, CsvWriter csv)
        {
            var book     = document.GetChildMarkers <TOC3Marker>().First().BookAbbreviation;
            var chapters = document.GetChildMarkers <CMarker>();

            foreach (var chapter in chapters)
            {
                var verses = chapter.GetChildMarkers <VMarker>();
                foreach (var verse in verses)
                {
                    var textBlocks = verse.GetChildMarkers <TextBlock>()
                                     .Where(m => !document.GetHierarchyToMarker(m).Any(i => i is FMarker));
                    var text = string.Join(string.Empty, textBlocks.Select(b => b.Text));
                    csv.WriteField(book);
                    csv.WriteField(chapter.Number);
                    csv.WriteField(verse.VerseNumber);
                    csv.WriteField(text.TrimEnd());
                    csv.NextRecord();
                }
            }
        }