Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dyn 5497 markdown not loading #13703

Merged
merged 12 commits into from
Feb 6, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected virtual void Dispose(bool disposing)

async void InitializeAsync()
{
string virtualFolder = string.Empty;
// Only initialize once
if (!hasBeenInitialized)
{
Expand All @@ -141,12 +142,10 @@ async void InitializeAsync()
UserDataFolder = WebBrowserUserDataFolder
};
}

//Initialize the CoreWebView2 component otherwise we can't navigate to a web page
await documentationBrowser.EnsureCoreWebView2Async();

//Due that the Web Browser(WebView2 - Chromium) security CORS is blocking the load of resources like images then we need to create a virtual folder in which the image are located.
this.documentationBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(VIRTUAL_FOLDER_MAPPING, FallbackDirectoryName, CoreWebView2HostResourceAccessKind.DenyCors);

this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived;
comScriptingObject = new ScriptingObject(this.viewModel);
//register the interop object into the browser.
Expand All @@ -158,6 +157,24 @@ async void InitializeAsync()
hasBeenInitialized = true;
}

try
{
if (viewModel.Link != null && !string.IsNullOrEmpty(viewModel.Name))
{
virtualFolder = HttpUtility.UrlDecode(viewModel.Link.AbsolutePath).Replace(viewModel.Name + ".md", "");
}
else
virtualFolder = FallbackDirectoryName;
}
catch (Exception ex)
{
virtualFolder = string.Empty;
}

if(Directory.Exists(virtualFolder))
//Due that the Web Browser(WebView2 - Chromium) security CORS is blocking the load of resources like images then we need to create a virtual folder in which the image are located.
this.documentationBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(VIRTUAL_FOLDER_MAPPING, virtualFolder, CoreWebView2HostResourceAccessKind.DenyCors);

string htmlContent = this.viewModel.GetContent();

Dispatcher.BeginInvoke(new Action(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Markup;
using Dynamo.Core;
using Dynamo.DocumentationBrowser.Properties;
using Dynamo.Logging;
Expand Down Expand Up @@ -32,7 +33,7 @@ public string Name
{
get { return name; }
}
}
}

public class DocumentationBrowserViewModel : NotificationObject, IDisposable
{
Expand Down Expand Up @@ -89,6 +90,22 @@ private set
private string content;
private string name;


/// <summary>
/// Package Name
/// </summary>
internal string Name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more intuitive name would be PackageName... What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or graph name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipeotero yes, I think is a better idea to use PackageName, then updated in the next commit: 0e3c928

{
get
{
return name;
}
set
{
name = value;
}
}

private MarkdownHandler MarkdownHandlerInstance => markdownHandler ?? (markdownHandler = new MarkdownHandler());
public bool HasContent => !string.IsNullOrWhiteSpace(this.content);

Expand Down Expand Up @@ -226,9 +243,9 @@ private void HandleLocalResource(OpenDocumentationLinkEventArgs e)
else
{
this.content = targetContent;
this.Link = link;
this.graphPath = graph;
this.name = graphName;
this.Link = link;
}
}
catch (FileNotFoundException)
Expand Down