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

Enhancing Html rendering #105

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.user
*.userosscache
*.sln.docstates
*.bak

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
5 changes: 5 additions & 0 deletions MarkdownViewerPlusPlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarkdownViewerPlusPlus", "MarkdownViewerPlusPlus\MarkdownViewerPlusPlus.csproj", "{E56F6E12-089C-40ED-BCFD-923E5FA121A1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3F324CD2-6E27-4AD6-A0C2-9F714F76A956}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
6 changes: 5 additions & 1 deletion MarkdownViewerPlusPlus/Forms/AbstractRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public abstract partial class AbstractRenderer : Form
/// <summary>
///
/// </summary>
protected MarkdownPipeline markdownPipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
protected MarkdownPipeline markdownPipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.UseBootstrap()
.Build();

/// <summary>
///
Expand Down Expand Up @@ -192,6 +195,7 @@ protected string BuildHtml(string html = "", string title = "")
<meta charset=""UTF-8"" />
<meta name=""author"" content=""{this.assemblyTitle}"" />
<title>{title}</title>
<link rel=""stylesheet"" href=""https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"" type=""text/css""/>
<style type=""text/css"">
{this.getCSS()}
</style>
Expand Down
67 changes: 0 additions & 67 deletions MarkdownViewerPlusPlus/Forms/MarkdownViewerHtmlPanel.cs

This file was deleted.

52 changes: 37 additions & 15 deletions MarkdownViewerPlusPlus/Forms/MarkdownViewerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Net;
using System.Linq;
using System.Threading;
using TheArtOfDev.HtmlRenderer.Core.Entities;
using static com.insanitydesign.MarkdownViewerPlusPlus.MarkdownViewer;
using System.Windows.Forms;

/// <summary>
///
Expand All @@ -18,10 +20,8 @@ namespace com.insanitydesign.MarkdownViewerPlusPlus.Forms
/// </summary>
public class MarkdownViewerRenderer : AbstractRenderer
{
/// <summary>
///
/// </summary>
public MarkdownViewerHtmlPanel markdownViewerHtmlPanel;
public WebBrowser browser;
private int? _previousScrollYPosition = 0;

/// <summary>
///
Expand All @@ -37,13 +37,17 @@ public MarkdownViewerRenderer(MarkdownViewer markdownViewer) : base(markdownView
protected override void Init()
{
base.Init();
//
this.markdownViewerHtmlPanel = new MarkdownViewerHtmlPanel();

this.browser = new WebBrowser
{
Dock = DockStyle.Fill
};

//Add a custom image loader
this.markdownViewerHtmlPanel.ImageLoad += OnImageLoad;

//Add to view
this.Controls.Add(this.markdownViewerHtmlPanel);
this.Controls.SetChildIndex(this.markdownViewerHtmlPanel, 0);
this.Controls.Add(this.browser);
this.Controls.SetChildIndex(this.browser, 0);
}

/// <summary>
Expand All @@ -54,7 +58,29 @@ protected override void Init()
public override void Render(string text, FileInformation fileInfo)
{
base.Render(text, fileInfo);
this.markdownViewerHtmlPanel.Text = BuildHtml(ConvertedText, fileInfo.FileName);

var doc = this.browser.Document?.GetElementsByTagName("HTML")?.OfType<HtmlElement>();

if (doc != null && doc.Any())
{
var htmlElement = doc.First();

_previousScrollYPosition = htmlElement.ScrollTop;
}

this.browser.DocumentText = BuildHtml(ConvertedText, fileInfo.FileName);

this.browser.DocumentCompleted += OnBrowserDocumentCompleted;
}

private void OnBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var browser = sender as WebBrowser;

if (_previousScrollYPosition != null)
{
browser.Document.Window.ScrollTo(0, (int)_previousScrollYPosition);
}
}

/// <summary>
Expand All @@ -64,7 +90,7 @@ public override void Render(string text, FileInformation fileInfo)
/// <param name="scrollRatio"></param>
public override void ScrollByRatioVertically(double scrollRatio)
{
this.markdownViewerHtmlPanel.ScrollByRatioVertically(scrollRatio);

}

/// <summary>
Expand Down Expand Up @@ -181,10 +207,6 @@ protected void OnDownloadDataCompleted(DownloadDataCompletedEventArgs downloadEv
/// </summary>
protected override void Dispose(bool disposing)
{
if (this.markdownViewerHtmlPanel != null)
{
this.markdownViewerHtmlPanel.ImageLoad -= OnImageLoad;
}
base.Dispose(disposing);
}
}
Expand Down
18 changes: 6 additions & 12 deletions MarkdownViewerPlusPlus/MarkdownViewerPlusPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlRenderer, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlRenderer.Core.1.5.1-beta3\lib\net40-client\HtmlRenderer.dll</HintPath>
<HintPath>..\packages\HtmlRenderer.Core.1.5.1-beta1\lib\net40-client\HtmlRenderer.dll</HintPath>
</Reference>
<Reference Include="HtmlRenderer.PdfSharp, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlRenderer.PdfSharp.1.5.1-beta3\lib\net40-client\HtmlRenderer.PdfSharp.dll</HintPath>
</Reference>
<Reference Include="HtmlRenderer.WinForms, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlRenderer.WinForms.1.5.1-beta3\lib\net40-client\HtmlRenderer.WinForms.dll</HintPath>
<HintPath>..\packages\HtmlRenderer.PdfSharp.1.5.1-beta1\lib\net40-client\HtmlRenderer.PdfSharp.dll</HintPath>
</Reference>
<Reference Include="Markdig, Version=0.15.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Markdig.0.15.0\lib\net40\Markdig.dll</HintPath>
Expand All @@ -105,11 +102,11 @@
<Reference Include="Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="PdfSharp, Version=1.50.4845.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL">
<HintPath>..\packages\PDFsharp.1.50.4845-RC2a\lib\net20\PdfSharp.dll</HintPath>
<Reference Include="PdfSharp, Version=1.50.4000.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL">
<HintPath>..\packages\PDFsharp.1.50.4000-beta3b\lib\net20\PdfSharp.dll</HintPath>
</Reference>
<Reference Include="PdfSharp.Charting, Version=1.50.4845.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL">
<HintPath>..\packages\PDFsharp.1.50.4845-RC2a\lib\net20\PdfSharp.Charting.dll</HintPath>
<Reference Include="PdfSharp.Charting, Version=1.50.4000.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb, processorArchitecture=MSIL">
<HintPath>..\packages\PDFsharp.1.50.4000-beta3b\lib\net20\PdfSharp.Charting.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand Down Expand Up @@ -140,9 +137,6 @@
<Compile Include="Forms\AbstractRenderer.Designer.cs">
<DependentUpon>AbstractRenderer.cs</DependentUpon>
</Compile>
<Compile Include="Forms\MarkdownViewerHtmlPanel.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Forms\MarkdownViewerOptions.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
Loading