Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/MarkPad/Preview/HtmlPreview.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CefSharp;
using System;
using System.Web;
using System.Windows;
using System.Windows.Controls;

Expand Down Expand Up @@ -103,7 +104,7 @@ private static void HtmlChanged(DependencyObject d, DependencyPropertyChangedEve
if (htmlPreview.host != null && htmlPreview.host.IsBrowserInitialized)
{
var fileName = (htmlPreview.FileName ?? "blank").Replace(" ", "-");
var fileUrl = string.Format("http://{0}/", fileName);
var fileUrl = string.Format("http://{0}/", MakeUrlSegmentSafe(fileName));

var newValue = e.NewValue as string;
if (newValue == null)
Expand Down Expand Up @@ -157,7 +158,7 @@ private void Host_IsBrowserInitializedChanged(object sender, DependencyPropertyC
private void InitializeData()
{
var fileName = (FileName ?? "blank").Replace(" ", "-");
var fileUrl = string.Format("http://{0}/", fileName);
var fileUrl = string.Format("http://{0}/", MakeUrlSegmentSafe(fileName));

var html = Html ?? string.Empty;

Expand All @@ -181,5 +182,12 @@ public async void UpdateZoomLevel(double fontSize)
});
host.SetZoomLevel(fontSize * scale * 2 / Constants.FONT_SIZE_ENUM_ADJUSTMENT);
}

private static string MakeUrlSegmentSafe(string urlSegment)
{
// it appears that the chromium web browser does not like parens or exclamations in a url
// replace these chars and also do a url path encode to try to avoid other potential problem chars
return HttpUtility.UrlEncode(urlSegment).Replace("(", "%28").Replace(")", "%29").Replace("!", "%21");
}
}
}