private static List<Tuple<string, string>> RunParseCase(string markdown, Span? subSpan = null) { var artifacts = new ArtifactCollection(new MarkdownCodeArtifactProcessor()); artifacts.Build(markdown); var classifier = new MarkdownClassifier(artifacts, new MockClassificationTypeRegistry()); return classifier.GetClassificationSpans(new SnapshotSpan(new MockSnapshot(markdown), subSpan ?? new Span(0, markdown.Length))) .Select(cs => Tuple.Create(cs.ClassificationType.Classification, markdown.Substring(cs.Span.Start, cs.Span.Length))) .ToList(); }
private static List <Tuple <string, string> > RunParseCase(string markdown, Span?subSpan = null) { var artifacts = new ArtifactCollection(new MarkdownCodeArtifactProcessor()); artifacts.Build(markdown); var classifier = new MarkdownClassifier(artifacts, new MockClassificationTypeRegistry()); return(classifier.GetClassificationSpans(new SnapshotSpan(new MockSnapshot(markdown), subSpan ?? new Span(0, markdown.Length))) .Select(cs => Tuple.Create(cs.ClassificationType.Classification, markdown.Substring(cs.Span.Start, cs.Span.Length))) .ToList()); }
public void GetArtifacts(ITextProvider text, ArtifactCollection artifactCollection) { var reader = new TextProviderReader(text); var tokenizer = new TemplateTokenizer(reader); foreach (var token in tokenizer.GetTokens()) { if (token.Kind != TemplateTokenKind.Text) { var range = TextRange.FromBounds(token.Start, token.End + 1); var artifact = TemplateArtifact.Create(token.Kind, range, token.IsClosed); artifactCollection.Add(artifact); } } }
private static void RunTestCase(string markdown, Tuple <string, string[]>[] expectedOutlines) { markdown = newline.Replace(markdown, "\r\n"); var snapshot = new MockSnapshot(markdown.Replace("{[", "").Replace("]}", "")); var expected = new List <TagSpan <IOutliningRegionTag> >(); var lastIndex = 0; for (int i = 0; i < expectedOutlines.Length; i++) { var spanStart = markdown.IndexOf("{[", lastIndex); if (spanStart < 0) { throw new ArgumentException("Not enough test delimiters"); } markdown = markdown.Remove(spanStart, 2); var spanEnd = markdown.IndexOf("]}", spanStart); markdown = markdown.Remove(spanEnd, 2); expected.Add(new TagSpan <IOutliningRegionTag>( new SnapshotSpan(snapshot, Span.FromBounds(spanStart, spanEnd)), new SimpleOutlineTag(expectedOutlines[i]) )); lastIndex = spanEnd; } if (markdown != snapshot.GetText()) { throw new ArgumentException("Unexpected test delimiters"); } var artifacts = new ArtifactCollection(new MarkdownCodeArtifactProcessor()); artifacts.Build(markdown); var tagger = new MarkdownOutlineTagger(artifacts, (c, t) => new SimpleOutlineTag(c, t)); var actual = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan( snapshot, new Span(0, markdown.Length) ))); actual .Select(ts => new { ts.Span.Span, ts.Tag }) .ShouldAllBeEquivalentTo(expected.Select(ts => new { ts.Span.Span, ts.Tag })); }
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 ArtifactCollectionTests() { _underTest = new ArtifactCollection(); _actionList = new[] { new TestAction() { User = new User() { FirstName = "John", LastName = "Doe" } }, new TestAction() { User = new User() { FirstName = "Jane", LastName = "Doe" } } }; }
private static void RunTestCase(string markdown, Tuple<string, string[]>[] expectedOutlines) { markdown = newline.Replace(markdown, "\r\n"); var snapshot = new MockSnapshot(markdown.Replace("{[", "").Replace("]}", "")); var expected = new List<TagSpan<IOutliningRegionTag>>(); var lastIndex = 0; for (int i = 0; i < expectedOutlines.Length; i++) { var spanStart = markdown.IndexOf("{[", lastIndex); if (spanStart < 0) throw new ArgumentException("Not enough test delimiters"); markdown = markdown.Remove(spanStart, 2); var spanEnd = markdown.IndexOf("]}", spanStart); markdown = markdown.Remove(spanEnd, 2); expected.Add(new TagSpan<IOutliningRegionTag>( new SnapshotSpan(snapshot, Span.FromBounds(spanStart, spanEnd)), new SimpleOutlineTag(expectedOutlines[i]) )); lastIndex = spanEnd; } if (markdown != snapshot.GetText()) throw new ArgumentException("Unexpected test delimiters"); var artifacts = new ArtifactCollection(new MarkdownCodeArtifactProcessor()); artifacts.Build(markdown); var tagger = new MarkdownOutlineTagger(artifacts, (c, t) => new SimpleOutlineTag(c, t)); var actual = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan( snapshot, new Span(0, markdown.Length) ))); actual .Select(ts => new { ts.Span.Span, ts.Tag }) .ShouldAllBeEquivalentTo(expected.Select(ts => new { ts.Span.Span, ts.Tag })); }
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 loadCollectionsXML() { doc = XDocument.Load(docPath); foreach (var collection in collections) { foreach (XElement e in doc.Root.Descendants(collection).Descendants("item")) { switch (collection) { case "pageone": PageOneCollection.Add(newItem(e, "shippeditems")); break; case "pagetwo": PageTwoCollection.Add(newItem(e, "shippeditems")); break; case "fish": FishCollection.Add(newItem(e, collection)); break; case "artifacts": ArtifactCollection.Add(newItem(e, collection)); break; case "minerals": MineralCollection.Add(newItem(e, collection)); break; case "cooking": CookingCollection.Add(newItem(e, collection)); break; } } } }
public MarkdownClassifier(ArtifactCollection artifacts, IClassificationTypeRegistryService registry) : this(() => artifacts, registry) { }
///<summary>Classifies an entire code block from any artifact in the block.</summary> /// <param name="index">The index of the artifact that the classifier is up to. The method will update this parameter to point to the last artifact in the block.</param> private IEnumerable<ClassificationSpan> ClassifyArtifacts(ITextSnapshot snapshot, ArtifactCollection artifacts, ref int index) { var blockArtifact = artifacts[index] as ICodeBlockArtifact; if (blockArtifact == null) { if (artifacts[index].TreatAs == ArtifactTreatAs.Code) return ClassifyArtifact(snapshot, artifacts[index]); else return Enumerable.Empty<ClassificationSpan>(); } IEnumerable<IArtifact> toClassify = blockArtifact.BlockInfo.CodeLines; // Find the end of the artifacts for this code block for (; index < artifacts.Count; index++) { var boundary = artifacts[index] as BlockBoundaryArtifact; // If we reached the end boundary, consume it & stop if (boundary != null && boundary.Boundary == BoundaryType.End) break; // If a non-code artifact is interspersed inside a // code block (eg, quote prefixes), handle it too. if (boundary == null && !(artifacts[index] is CodeLineArtifact)) toClassify = toClassify.Concat(new[] { artifacts[index] }); } return toClassify.SelectMany(a => ClassifyArtifact(snapshot, a)); }
///<summary>Classifies an entire code block from any artifact in the block.</summary> /// <param name="index">The index of the artifact that the classifier is up to. The method will update this parameter to point to the last artifact in the block.</param> private IEnumerable <ClassificationSpan> ClassifyArtifacts(ITextSnapshot snapshot, ArtifactCollection artifacts, ref int index) { var blockArtifact = artifacts[index] as ICodeBlockArtifact; if (blockArtifact == null) { if (artifacts[index].TreatAs == ArtifactTreatAs.Code) { return(ClassifyArtifact(snapshot, artifacts[index])); } else { return(Enumerable.Empty <ClassificationSpan>()); } } IEnumerable <IArtifact> toClassify = blockArtifact.BlockInfo.CodeLines; // Find the end of the artifacts for this code block for (; index < artifacts.Count; index++) { var boundary = artifacts[index] as BlockBoundaryArtifact; // If we reached the end boundary, consume it & stop if (boundary != null && boundary.Boundary == BoundaryType.End) { break; } // If a non-code artifact is interspersed inside a // code block (eg, quote prefixes), handle it too. if (boundary == null && !(artifacts[index] is CodeLineArtifact)) { toClassify = toClassify.Concat(new[] { artifacts[index] }); } } return(toClassify.SelectMany(a => ClassifyArtifact(snapshot, a))); }
public MarkdownOutlineTagger(ArtifactCollection artifacts, OutlineTagCreator tagCreator) : this(() => artifacts, tagCreator) { }