This commit is contained in:
2020-04-29 20:36:58 +00:00
parent f9ec52df9d
commit d6ca437a00
4 changed files with 34 additions and 5 deletions

View File

@@ -39,9 +39,16 @@
<AssemblyOriginatorKeyFile>AyaNova.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>AyaNova.snk</AssemblyOriginatorKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.11.23.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>libs\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\3rdprtylibs\json.net.40\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\..\3rdprtylibs\json.net.40\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="ReverseMarkdown">
<HintPath>libs\ReverseMarkdown.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />

View File

@@ -15,6 +15,8 @@ using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
//using HtmlAgilityPack;
//using ReverseMarkdown;
namespace AyaNova.PlugIn.V8 namespace AyaNova.PlugIn.V8
@@ -746,6 +748,7 @@ namespace AyaNova.PlugIn.V8
WikiPage w = WikiPage.GetItem(tid); WikiPage w = WikiPage.GetItem(tid);
var content = w.GetContentAsString; var content = w.GetContentAsString;
if (string.IsNullOrWhiteSpace(content)) return null;
//TODO: fixup internal urls using MAP of file attachment uploads //TODO: fixup internal urls using MAP of file attachment uploads
@@ -756,12 +759,31 @@ namespace AyaNova.PlugIn.V8
content = content.Replace(m.Value, "<img src=\"" + "[ATTACH:" + RavenId.ToString() + "]" + "\">"); content = content.Replace(m.Value, "<img src=\"" + "[ATTACH:" + RavenId.ToString() + "]" + "\">");
} }
//TODO: Convert to Markdown format //todo: fixup font size, try to convert to heading tags instead
if (!string.IsNullOrWhiteSpace(content)) //TODO: Convert to Markdown format
return content; //found 2 likely candidate libs to do this
else //https://www.nuget.org/packages/Html2Markdown/
return null; //https://www.nuget.org/packages/ReverseMarkdown/
//Not much difference at first glance, very similar stats, reverse markdown is a little more widely used and seems to have more config options
//built in, the other has to make some kind of processor for some stuff maybe so going with reverse for now
//NOTE: for this to work had to add an assembly redirect in app.config for ayanova project as it was looking for a really old version of
//the HtmlAgilityPack
var config = new ReverseMarkdown.Config
{
UnknownTags = ReverseMarkdown.Config.UnknownTagsOption.Bypass,
GithubFlavored = true, // generate GitHub flavoured markdown, supported for BR, PRE and table tags
RemoveComments = true, // will ignore all comments
SmartHrefHandling = true // remove markdown output for links where appropriate
};
var converter = new ReverseMarkdown.Converter(config);
string res = converter.Convert(content);
return res;
} }