private static List<string> RunParseCase(string markdown)
 {
     var retVal = new List<string>();
     var parser = new MarkdownParser(new TabAwareCharacterStream(markdown));
     parser.ArtifactFound += (s, e) => retVal.Add(markdown.Substring(e.Artifact.InnerRange.Start, e.Artifact.InnerRange.Length));
     parser.Parse();
     return retVal;
 }
Пример #2
0
        public void GetArtifacts(ITextProvider text, ArtifactCollection artifactCollection)
        {
            var           parser    = new MarkdownParser(new TabAwareCharacterStream(text));
            CodeBlockInfo lastBlock = null;

            parser.ArtifactFound += (s, e) =>
            {
                var cla = e.Artifact as CodeLineArtifact;
                if (cla != null)
                {
                    if (lastBlock == null || lastBlock != cla.BlockInfo)
                    {
                        if (lastBlock != null)
                        {
                            artifactCollection.Add(new BlockBoundaryArtifact(lastBlock, BoundaryType.End));
                        }
                        lastBlock = cla.BlockInfo;
                        artifactCollection.Add(new BlockBoundaryArtifact(cla.BlockInfo, BoundaryType.Start));
                    }

                    // Don't add artifacts for HTML code lines.
                    if ((cla.BlockInfo.Language ?? "").StartsWith("htm", StringComparison.OrdinalIgnoreCase))
                    {
                        cla.BlockInfo.IsExtradited = true;
                        return;
                    }
                }
                // If we got a non-block artifact after a block end, add the end marker.
                else if (lastBlock != null && e.Artifact.Start >= lastBlock.OuterEnd.End)
                {
                    artifactCollection.Add(new BlockBoundaryArtifact(lastBlock, BoundaryType.End));
                    lastBlock = null;
                }
                artifactCollection.Add(e.Artifact);
            };
            parser.Parse();
            if (lastBlock != null)
            {
                artifactCollection.Add(new BlockBoundaryArtifact(lastBlock, BoundaryType.End));
            }
        }
        public void GetArtifacts(ITextProvider text, ArtifactCollection artifactCollection)
        {
            var parser = new MarkdownParser(new TabAwareCharacterStream(text));
            CodeBlockInfo lastBlock = null;
            parser.ArtifactFound += (s, e) =>
            {
                var cla = e.Artifact as CodeLineArtifact;
                if (cla != null)
                {
                    if (lastBlock == null || lastBlock != cla.BlockInfo)
                    {
                        if (lastBlock != null)
                            artifactCollection.Add(new BlockBoundaryArtifact(lastBlock, BoundaryType.End));

                        lastBlock = cla.BlockInfo;
                        artifactCollection.Add(new BlockBoundaryArtifact(cla.BlockInfo, BoundaryType.Start));
                    }

                    // Don't add artifacts for HTML code lines.
                    //if ((cla.BlockInfo.Language ?? "").StartsWith("htm", StringComparison.OrdinalIgnoreCase))
                    //{
                    //    cla.BlockInfo.IsExtradited = true;
                    //    return;
                    //}
                }
                // If we got a non-block artifact after a block end, add the end marker.
                else if (lastBlock != null && e.Artifact.Start >= lastBlock.OuterEnd.End)
                {
                    artifactCollection.Add(new BlockBoundaryArtifact(lastBlock, BoundaryType.End));
                    lastBlock = null;
                }
                artifactCollection.Add(e.Artifact);
            };
            parser.Parse();
            if (lastBlock != null)
                artifactCollection.Add(new BlockBoundaryArtifact(lastBlock, BoundaryType.End));
        }