Skip to content

Commit

Permalink
Merge pull request poppastring#664 from thousandtyone/main
Browse files Browse the repository at this point in the history
Support for Markdown in Comments
  • Loading branch information
poppastring authored Dec 20, 2022
2 parents 3807103 + cb7fb94 commit deb7265
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public interface ISiteConfig

bool EnableComments { get; set; }

bool AllowMarkdownInComments {get; set;}

bool EnableCommentApi { get; set; }

bool EnableConfigEditService { get; set; }
Expand Down
1 change: 1 addition & 0 deletions source/DasBlog.Services/ConfigFile/SiteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public SiteConfig() { }
public string TinyMCEApiKey { get; set; }
public bool EnableBloggerApi { get; set; }
public bool EnableComments { get; set; }
public bool AllowMarkdownInComments {get; set;}
public bool EnableCommentApi { get; set; }
public bool EnableConfigEditService { get; set; }
public bool EnableEditService { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion source/DasBlog.Tests/UnitTests/Config/site.config
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<DaysCommentsAllowed>360</DaysCommentsAllowed>
<EnableCommentDays>true</EnableCommentDays>
<EnableComments>true</EnableComments>
<AllowMarkdownInComments>true</AllowMarkdownInComments>
<CommentsRequireApproval>false</CommentsRequireApproval>
<CheesySpamQ>2+5=?</CheesySpamQ>
<CheesySpamA>7</CheesySpamA>
Expand All @@ -83,6 +84,7 @@
<tag name="ul" attributes="" allowed="true" />
<tag name="ol" attributes="" allowed="true" />
<tag name="li" attributes="" allowed="true" />
<tag name="p" attributes="" allowed="true" />
</validCommentTags>

<ChannelImageUrl>images/zenicon.jpg</ChannelImageUrl>
Expand Down Expand Up @@ -194,4 +196,4 @@
<BypassSpamOpenIdComment>false</BypassSpamOpenIdComment>
<AMPPagesEnabled>false</AMPPagesEnabled>
<RSSEndPointRewrite></RSSEndPointRewrite>
</SiteConfig>
</SiteConfig>
3 changes: 2 additions & 1 deletion source/DasBlog.Tests/UnitTests/SiteConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,6 @@ public class SiteConfigTest : ISiteConfig
public string DefaultSources { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string MastodonServerUrl { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string MastodonAccount { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
public bool AllowMarkdownInComments { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
}
3 changes: 3 additions & 0 deletions source/DasBlog.Web.UI/Config/site.Development.config
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<DaysCommentsAllowed>360</DaysCommentsAllowed>
<EnableCommentDays>true</EnableCommentDays>
<EnableComments>true</EnableComments>
<AllowMarkdownInComments>false</AllowMarkdownInComments>

<CommentsRequireApproval>false</CommentsRequireApproval>
<CheesySpamQ>2+5=?</CheesySpamQ>
<CheesySpamA>7</CheesySpamA>
Expand All @@ -87,6 +89,7 @@
<tag name="ul" attributes="" allowed="true" />
<tag name="ol" attributes="" allowed="true" />
<tag name="li" attributes="" allowed="true" />
<tag name="p" attributes="" allowed="true" />
</validCommentTags>

<ChannelImageUrl>images/zenicon.jpg</ChannelImageUrl>
Expand Down
2 changes: 2 additions & 0 deletions source/DasBlog.Web.UI/Config/site.config
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<DaysCommentsAllowed>360</DaysCommentsAllowed>
<EnableCommentDays>true</EnableCommentDays>
<EnableComments>true</EnableComments>
<AllowMarkdownInComments>false</AllowMarkdownInComments>
<CommentsRequireApproval>false</CommentsRequireApproval>
<CheesySpamQ>2+5=?</CheesySpamQ>
<CheesySpamA>7</CheesySpamA>
Expand All @@ -87,6 +88,7 @@
<tag name="ul" attributes="" allowed="true" />
<tag name="ol" attributes="" allowed="true" />
<tag name="li" attributes="" allowed="true" />
<tag name="p" attributes="" allowed="true" />
</validCommentTags>

<ChannelImageUrl>images/zenicon.jpg</ChannelImageUrl>
Expand Down
8 changes: 7 additions & 1 deletion source/DasBlog.Web.UI/Controllers/BlogPostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Linq;
using System.Net;
using reCAPTCHA.AspNetCore;
using Markdig;

namespace DasBlog.Web.Controllers
{
Expand All @@ -36,7 +37,6 @@ public class BlogPostController : DasBlogBaseController
private readonly IMemoryCache memoryCache;
private readonly IRecaptchaService recaptcha;


public BlogPostController(IBlogManager blogManager, IHttpContextAccessor httpContextAccessor, IDasBlogSettings dasBlogSettings,
IMapper mapper, ICategoryManager categoryManager, IFileSystemBinaryManager binaryManager, ILogger<BlogPostController> logger,
IBlogPostViewModelCreator modelViewCreator, IMemoryCache memoryCache, IRecaptchaService recaptcha)
Expand Down Expand Up @@ -409,6 +409,12 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
errors.Add("Comments are disabled on the site.");
}

if(dasBlogSettings.SiteConfiguration.AllowMarkdownInComments)
{
var pipeline = new MarkdownPipelineBuilder().UseReferralLinks("nofollow").Build();
addcomment.Content = Markdown.ToHtml(addcomment.Content, pipeline);
}

// Optional in case of Captcha. Commenting the settings in the config file
// Will disable this check. People will typically disable this when using captcha.
if (!string.IsNullOrEmpty(dasBlogSettings.SiteConfiguration.CheesySpamQ) &&
Expand Down
1 change: 1 addition & 0 deletions source/DasBlog.Web.UI/DasBlog.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Coravel" Version="4.1.2" />
<PackageReference Include="Markdig" Version="0.30.4" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" />
Expand Down
4 changes: 4 additions & 0 deletions source/DasBlog.Web.UI/Models/AdminViewModels/SiteViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public class SiteViewModel
[Description("Allow comments on your blog posts")]
public bool EnableComments { get; set; }

[DisplayName("Allow Markdown in comments")]
[Description("Allow the use of Markdown In Comments")]
public bool AllowMarkdownInComments { get; set; }

[DisplayName("Enable comment days limitation")]
[Description("Once enabled comments are allowed as defined by 'Days Comments Allowed'")]
public bool EnableCommentDays { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions source/DasBlog.Web.UI/Views/Admin/Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@
</div>
</div>

<div class="form-check row mb-3">
<div class="col-sm-10 offset-sm-2">
<div class="col-sm-10">
@Html.CheckBoxFor(m => @Model.SiteConfig.AllowMarkdownInComments, new { @class = "form-check-input form-check-input" })
</div>
@Html.LabelFor(m => @Model.SiteConfig.AllowMarkdownInComments, null, new { @class = "col-check-label col-sm-2" })
</div>
</div>

<div class="form-check row mb-3">
<div class="col-sm-10 offset-sm-2">
<div class="col-sm-2">
Expand Down

0 comments on commit deb7265

Please sign in to comment.