private string CreateNodeAnnotationContent(OpenNodeAnnotationEventArgs e) { var writer = new StringWriter(); try { writer.WriteLine(DocumentationBrowserUtils.GetContentFromEmbeddedResource(STYLE_RESOURCE)); // Get the Node info section var nodeDocumentation = NodeDocumentationHtmlGenerator.FromAnnotationEventArgs(e); writer.WriteLine(nodeDocumentation); // Convert the markdown file to html MarkdownHandlerInstance.ParseToHtml(ref writer, e.MinimumQualifiedName, e.PackageName); writer.Flush(); var output = writer.ToString(); // Sanitize html and warn if any changes where made if (MarkdownHandlerInstance.SanitizeHtml(ref output)) { LogWarning(Resources.ScriptTagsRemovalWarning, WarningLevel.Mild); } // inject the syntax highlighting script at the bottom at the document. output += DocumentationBrowserUtils.GetDPIScript(); output += DocumentationBrowserUtils.GetSyntaxHighlighting(); return(output); } finally { writer?.Dispose(); } }
private string CreateNodeAnnotationContent(OpenNodeAnnotationEventArgs e) { var writer = new StringWriter(); try { writer.WriteLine(DocumentationBrowserUtils.GetContentFromEmbeddedResource(STYLE_RESOURCE)); // Get the Node info section and remove script tags if any var nodeDocumentation = NodeDocumentationHtmlGenerator.FromAnnotationEventArgs(e); if (MarkdownHandlerInstance.SanitizeHtml(ref nodeDocumentation)) { LogWarning(Resources.ScriptTagsRemovalWarning, WarningLevel.Mild); } writer.WriteLine(nodeDocumentation); // Convert the markdown file to html and remove script tags if any if (MarkdownHandlerInstance.ParseToHtml(ref writer, e.MinimumQualifiedName)) { LogWarning(Resources.ScriptTagsRemovalWarning, WarningLevel.Mild); } writer.Flush(); return(writer.ToString()); } finally { writer?.Dispose(); } }
private string RequestNodeDocs(Dynamo.Graph.Nodes.NodeModel node) { var docBrowserviewExtension = this.View.viewExtensionManager.ViewExtensions.OfType <DocumentationBrowserViewExtension>().FirstOrDefault(); var nodeAnnotationEventArgs = new OpenNodeAnnotationEventArgs(node, this.ViewModel); docBrowserviewExtension.HandleRequestOpenDocumentationLink(nodeAnnotationEventArgs); return(GetSidebarDocsBrowserContents()); }
private static string CreateHeader(OpenNodeAnnotationEventArgs e) { StringBuilder sb = new StringBuilder(); sb.AppendLine($"<h1>{e.Type}</h1>"); sb.AppendLine($"<p><i>{e.MinimumQualifiedName}</i></p>"); sb.Append("<hr>"); return(sb.ToString()); }
void ViewModel_RequestShowNodeHelp(object sender, NodeDialogEventArgs e) { if (e.Handled) { return; } e.Handled = true; var nodeAnnotationEventArgs = new OpenNodeAnnotationEventArgs(viewModel.NodeModel, viewModel.DynamoViewModel); ViewModel.DynamoViewModel.OpenDocumentationLink(nodeAnnotationEventArgs); }
/// <summary> /// Creates the Node information section which all nodes have /// even if they dont have additional markdown documentation. /// </summary> /// <param name="e"></param> /// <returns></returns> internal static string FromAnnotationEventArgs(OpenNodeAnnotationEventArgs e) { if (e is null) { throw new ArgumentNullException(nameof(e)); } StringBuilder sb = new StringBuilder(); sb.AppendLine(CreateHeader(e)); sb.AppendLine(CreateNodeInfo(e)); return(sb.ToString()); }
public void CanCreateNodeDocumenationHtmlFromNodeAnnotationEventArgsWithPackageNodeWithAddtionalDocumentation() { // Arrange RaiseLoadedEvent(this.View); var testDirectory = GetTestDirectory(this.ExecutingDirectory); var localImagePath = Path.Combine(testDirectory, @"core\docbrowser\pkgs\PackageWithNodeDocumentation\doc\icon.png"); var localImagePathHtml = localImagePath.Replace("\\", @"%5C"); var docBrowserviewExtension = this.View.viewExtensionManager.ViewExtensions.OfType <DocumentationBrowserViewExtension>().FirstOrDefault(); var nodeName = "Package.Hello"; var expectedNodeDocumentationTitle = $"<h1>{nodeName}</h1>"; var expectedNodeDocumentationNamespace = $"<p><i>Package.{nodeName}</i></p>"; var expectedAddtionalNodeDocumentationHeader = @"<h1 id=""hello-dynamo"">Hello Dynamo!</h1>"; var expectedAddtionalNodeDocumentationImage = String.Format(@"<p><img src=""file:///{0}"" alt=""Dynamo Icon image"" /></p>", localImagePathHtml); // Act this.ViewModel.ExecuteCommand( new DynamoModel.CreateNodeCommand( Guid.NewGuid().ToString(), nodeName, 0, 0, false, false) ); var node = this.ViewModel.Model.CurrentWorkspace.Nodes.FirstOrDefault(); var nodeAnnotationEventArgs = new OpenNodeAnnotationEventArgs(node, this.ViewModel); var tabsBeforeExternalEventTrigger = this.View.ExtensionTabItems.Count; docBrowserviewExtension.HandleRequestOpenDocumentationLink(nodeAnnotationEventArgs); var tabsAfterExternalEventTrigger = this.View.ExtensionTabItems.Count; var htmlContent = GetSidebarDocsBrowserContents(); // Assert Assert.AreEqual(0, tabsBeforeExternalEventTrigger); Assert.AreEqual(1, tabsAfterExternalEventTrigger); Assert.IsTrue(htmlContent.Contains(expectedNodeDocumentationTitle)); Assert.IsTrue(htmlContent.Contains(expectedNodeDocumentationNamespace)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoHeader)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeDescription)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeType)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeInputs)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeOutputs)); Assert.IsTrue(htmlContent.Contains(expectedAddtionalNodeDocumentationHeader)); Assert.IsTrue(htmlContent.Contains(expectedAddtionalNodeDocumentationImage)); }
private static string CreateNodeInfo(OpenNodeAnnotationEventArgs e) { StringBuilder sb = new StringBuilder(); sb.AppendLine($"<h2>{Resources.NodeDocumentationNodeInfo}</h2>"); sb.AppendLine("<table>"); sb.AppendLine("<tbody>"); sb.AppendLine("<tr>"); sb.AppendLine($"<td>{Resources.NodeDocumentationNodeType}</td>"); sb.AppendLine($"<td>{e.Type}</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr>"); sb.AppendLine($"<td>{Resources.NodeDocumentationDescription}</td>"); sb.AppendLine($"<td>{Regex.Replace(e.Description, @"\r\n?|\n", "<br>")}</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr>"); sb.AppendLine($"<td>{Resources.NodeDocumentationCategory}</td>"); sb.AppendLine($"<td>{e.Category}</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr>"); sb.AppendLine($"<td>{Resources.NodeDocumentationInputs}</td>"); sb.AppendLine("<td>"); for (int i = 0; i < e.InputNames.Count(); i++) { sb.AppendLine( $"<li style=\"margin-bottom: 5px\"><b><u>{e.InputNames.ElementAt(i)}</u></b><br>{Regex.Replace(e.InputDescriptions.ElementAt(i), @"\r\n?|\n", "<br>")}</li>"); } sb.AppendLine("</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr>"); sb.AppendLine($"<td>{Resources.NodeDocumentationOutputs}</td>"); sb.AppendLine("<td>"); for (int i = 0; i < e.OutputNames.Count(); i++) { sb.AppendLine( $"<li style=\"margin-bottom: 5px\"><b><u>{e.OutputNames.ElementAt(i)}</u></b><br>{Regex.Replace(e.OutputDescriptions.ElementAt(i), @"\r\n?|\n", "<br>")}</li>"); } sb.AppendLine("</td>"); sb.AppendLine("</tr>"); sb.AppendLine("</tbody>"); sb.AppendLine("</table>"); sb.Append("<hr>"); return(sb.ToString()); }
public void CanCreateNodeDocumenationHtmlFromNodeAnnotationEventArgsWithOOTBNodeWithoutAddtionalDocumentation() { // Arrange RaiseLoadedEvent(this.View); var docBrowserviewExtension = this.View.viewExtensionManager.ViewExtensions.OfType <DocumentationBrowserViewExtension>().FirstOrDefault(); var nodeName = "+"; var expectedNodeDocumentationTitle = $"<h1>{nodeName}</h1>"; var expectedNodeDocumentationNamespace = "<p><i>.%add</i></p>"; var expectedAddtionalNodeDocumentation = @"<h2 id=""no-further-documentation-provided-for-this-node"">No further documentation provided for this node.</h2>"; // Act this.ViewModel.ExecuteCommand( new DynamoModel.CreateNodeCommand( Guid.NewGuid().ToString(), nodeName, 0, 0, false, false) ); var node = this.ViewModel.Model.CurrentWorkspace.Nodes.FirstOrDefault(); var nodeAnnotationEventArgs = new OpenNodeAnnotationEventArgs(node, this.ViewModel); var tabsBeforeExternalEventTrigger = this.View.ExtensionTabItems.Count; docBrowserviewExtension.HandleRequestOpenDocumentationLink(nodeAnnotationEventArgs); var tabsAfterExternalEventTrigger = this.View.ExtensionTabItems.Count; var htmlContent = GetSidebarDocsBrowserContents(); // Assert Assert.AreEqual(0, tabsBeforeExternalEventTrigger); Assert.AreEqual(1, tabsAfterExternalEventTrigger); Assert.IsTrue(htmlContent.Contains(expectedNodeDocumentationTitle)); Assert.IsTrue(htmlContent.Contains(expectedNodeDocumentationNamespace)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoHeader)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeDescription)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeType)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeInputs)); Assert.IsTrue(htmlContent.Contains(nodeDocumentationInfoNodeOutputs)); Assert.IsTrue(htmlContent.Contains(expectedAddtionalNodeDocumentation)); }