public void Build(FileModel model, IHostService host) { model.File = Path.ChangeExtension(model.File, ".json"); var toc = (TocViewModel)model.Content; HashSet<string> links = new HashSet<string>(); Dictionary<string, HashSet<string>> tocMap = new Dictionary<string, HashSet<string>>(); UpdateRelativePathAndAddTocMap(toc, model, links, tocMap, host); model.Properties.LinkToFiles = links.ToImmutableArray(); model.Properties.TocMap = tocMap.ToImmutableDictionary(); // todo : metadata. }
public async Task<ImmutableArray<SymbolAndProjectId>> DetermineCascadedSymbolsAsync( SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default(CancellationToken)) { var linkedSymbols = new HashSet<SymbolAndProjectId>(); var symbol = symbolAndProjectId.Symbol; foreach (var location in symbol.DeclaringSyntaxReferences) { var originalDocument = solution.GetDocument(location.SyntaxTree); // GetDocument will return null for locations in #load'ed trees. // TODO: Remove this check and add logic to fetch the #load'ed tree's // Document once https://github.com/dotnet/roslyn/issues/5260 is fixed. if (originalDocument == null) { Debug.Assert(solution.Workspace.Kind == "Interactive"); continue; } foreach (var linkedDocumentId in originalDocument.GetLinkedDocumentIds()) { var linkedDocument = solution.GetDocument(linkedDocumentId); var linkedSyntaxRoot = await linkedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); // Defend against constructed solutions with inconsistent linked documents if (!linkedSyntaxRoot.FullSpan.Contains(location.Span)) { continue; } var linkedNode = linkedSyntaxRoot.FindNode(location.Span, getInnermostNodeForTie: true); var semanticModel = await linkedDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var linkedSymbol = semanticModel.GetDeclaredSymbol(linkedNode, cancellationToken); if (linkedSymbol != null && linkedSymbol.Kind == symbol.Kind && linkedSymbol.Name == symbol.Name) { var linkedSymbolAndProjectId = SymbolAndProjectId.Create(linkedSymbol, linkedDocument.Project.Id); if (!linkedSymbols.Contains(linkedSymbolAndProjectId)) { linkedSymbols.Add(linkedSymbolAndProjectId); } } } } return linkedSymbols.ToImmutableArray(); }
public MarkupResult Markup(string src, string path) { var dependency = new HashSet<string>(); var html = _builder.CreateDfmEngine(new DfmRenderer() { Tokens = _tokens }).Markup(src, path, dependency); var result = new MarkupResult { Html = html, }; if (dependency.Count > 0) { result.Dependency = dependency.ToImmutableArray(); } return result; }
public static ILogger AddOrReplace(ILogger newLogger, ILogger oldLogger, Func<ILogger, bool> predicate) { if (newLogger == null) { return oldLogger; } if (oldLogger == null) { return newLogger; } var aggregateLogger = oldLogger as AggregateLogger; if (aggregateLogger == null) { // replace old logger with new logger if (predicate(oldLogger)) { // this might not aggregate logger return newLogger; } // merge two return new AggregateLogger(ImmutableArray.Create(newLogger, oldLogger)); } var set = new HashSet<ILogger>(); foreach (var logger in aggregateLogger._loggers) { // replace this logger with new logger if (predicate(logger)) { set.Add(newLogger); continue; } // add old one back set.Add(logger); } // add new logger. if we already added one, this will be ignored. set.Add(newLogger); return new AggregateLogger(set.ToImmutableArray()); }
public MarkupResult Markup(string src, string path) { var dependency = new HashSet<string>(); var json = _builder.CreateDfmEngine(new DfmJsonTokenTreeRender()).Markup(src, path, dependency); if (json.Length != 0 && json.EndsWith(",")) { json = json.Remove(json.Length - 1); } var result = new MarkupResult { // TODO: rename Html = $"{{\"name\":\"0>0>markdown\",\"children\":[{json}]}}", }; if (dependency.Count > 0) { result.Dependency = dependency.ToImmutableArray(); } return result; }
public static AggregateLogger Create(params ILogger[] loggers) { var set = new HashSet<ILogger>(); // flatten loggers foreach (var logger in loggers.WhereNotNull()) { var aggregateLogger = logger as AggregateLogger; if (aggregateLogger != null) { set.UnionWith(aggregateLogger.loggers); continue; } set.Add(logger); } return new AggregateLogger(set.ToImmutableArray()); }
private MarkupResult MarkupCore(string markdown, FileAndType ft) { var html = _engine.CreateDfmEngine(DocfxFlavoredMarked.Renderer).Markup(markdown, Path.Combine(ft.BaseDir, ft.File)); var doc = new HtmlDocument(); doc.LoadHtml(html); var result = new MarkupResult(); var node = doc.DocumentNode.SelectSingleNode("//yamlheader"); if (node != null) { using (var sr = new StringReader(StringHelper.HtmlDecode(node.InnerHtml))) { result.YamlHeader = YamlUtility.Deserialize<Dictionary<string, object>>(sr).ToImmutableDictionary(); } node.Remove(); } var linkToFiles = new HashSet<string>(); foreach (var link in from n in doc.DocumentNode.Descendants() where !string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase) from attr in n.Attributes where string.Equals(attr.Name, "src", StringComparison.OrdinalIgnoreCase) || string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase) where !string.IsNullOrWhiteSpace(attr.Value) select attr) { string linkFile; string anchor = null; if (PathUtility.IsRelativePath(link.Value)) { var index = link.Value.IndexOf('#'); if (index == -1) { linkFile = link.Value; } else if (index == 0) { continue; } else { linkFile = link.Value.Remove(index); anchor = link.Value.Substring(index); } var path = (RelativePath)ft.File + (RelativePath)linkFile; var file = path.GetPathFromWorkingFolder(); link.Value = file + anchor; linkToFiles.Add(HttpUtility.UrlDecode(file)); } } result.LinkToFiles = linkToFiles.ToImmutableArray(); result.LinkToUids = (from n in doc.DocumentNode.Descendants() where string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase) from attr in n.Attributes where string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase) where !string.IsNullOrWhiteSpace(attr.Value) select attr.Value).ToImmutableHashSet(); using (var sw = new StringWriter()) { doc.Save(sw); result.Html = sw.ToString(); } return result; }
private async Task<ImmutableArray<PackageWithAssemblyResult>> FindMatchingPackagesAsync( PackageSource source, ISymbolSearchService searchService, IPackageInstallerService installerService, ISet<string> assemblyNames, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var result = new HashSet<PackageWithAssemblyResult>(); foreach (var assemblyName in assemblyNames) { var packagesWithAssembly = await searchService.FindPackagesWithAssemblyAsync( source.Name, assemblyName, cancellationToken).ConfigureAwait(false); result.AddRange(packagesWithAssembly); } // Ensure the packages are sorted by rank. var sortedPackages = result.ToImmutableArray().Sort(); return sortedPackages; }
public MarkupResult MarkupCore(string markdown, FileAndType ft) { var html = DocfxFlavoredMarked.Markup(markdown, Path.Combine(ft.BaseDir, ft.File)); var doc = new HtmlDocument(); doc.LoadHtml(html); var result = new MarkupResult(); // TODO: how to get TITLE // InnerText in HtmlAgilityPack is not decoded, should be a bug var headerNode = doc.DocumentNode.SelectSingleNode("//h1|//h2|//h3"); result.Title = StringHelper.HtmlDecode(headerNode?.InnerText); var node = doc.DocumentNode.SelectSingleNode("//yamlheader"); if (node != null) { using (var sr = new StringReader(StringHelper.HtmlDecode(node.InnerHtml))) { result.YamlHeader = YamlUtility.Deserialize<Dictionary<string, object>>(sr).ToImmutableDictionary(); } node.Remove(); } var linkToFiles = new HashSet<string>(); foreach (var link in from n in doc.DocumentNode.Descendants() where !string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase) from attr in n.Attributes where string.Equals(attr.Name, "src", StringComparison.OrdinalIgnoreCase) || string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase) where !string.IsNullOrWhiteSpace(attr.Value) select attr) { string linkFile; string anchor = null; if (PathUtility.IsRelativePath(link.Value)) { var index = link.Value.IndexOf('#'); if (index == -1) { linkFile = link.Value; } else if (index == 0) { continue; } else { linkFile = link.Value.Remove(index); anchor = link.Value.Substring(index); } var path = (RelativePath)ft.File + (RelativePath)linkFile; if (path.ParentDirectoryCount > 0) { Logger.LogError($"Cannot refer path: \"{path}\" out of project.", file: ft.File); throw new DocumentException($"Cannot refer path \"{path}\" out of project in file \"{ft.File}\"."); } var file = path.GetPathFromWorkingFolder(); link.Value = file + anchor; linkToFiles.Add(HttpUtility.UrlDecode(file)); } } result.LinkToFiles = linkToFiles.ToImmutableArray(); result.LinkToUids = (from n in doc.DocumentNode.Descendants() where string.Equals(n.Name, "xref", StringComparison.OrdinalIgnoreCase) from attr in n.Attributes where string.Equals(attr.Name, "href", StringComparison.OrdinalIgnoreCase) where !string.IsNullOrWhiteSpace(attr.Value) select attr.Value).ToImmutableArray(); using (var sw = new StringWriter()) { doc.Save(sw); result.Html = sw.ToString(); } return result; }