help the tags
This commit is contained in:
parent
f0c1442bfa
commit
6fc44cf50f
3 changed files with 49 additions and 6 deletions
|
|
@ -2,22 +2,65 @@ using System;
|
||||||
using Microsoft.AspNetCore.Html;
|
using Microsoft.AspNetCore.Html;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Yavsc.Models.Drawing;
|
using Yavsc.Models.Drawing;
|
||||||
|
using AsciiDocNet;
|
||||||
|
using Yavsc.Models.Blog;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
|
||||||
|
public static class AsciiDocHelpers
|
||||||
|
{
|
||||||
|
public static IHtmlContent AsciiDocFor<TModel> (this IHtmlHelper<TModel> html,
|
||||||
|
Expression<Func<TModel, string>> expression)
|
||||||
|
{
|
||||||
|
var span = new TagBuilder("p"){ TagRenderMode = TagRenderMode.SelfClosing };
|
||||||
|
span.InnerHtml.Append (
|
||||||
|
html.ValueFor<string>(expression, "{0}"));
|
||||||
|
return span.RenderBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string AsciiDoc(IHtmlHelper<BlogPost> htmlHelper, string text)
|
||||||
|
{
|
||||||
|
return AsciiDoc(htmlHelper, text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string AsciiDoc(IHtmlHelper<BlogPost> htmlHelper, string text, object htmlAttributes)
|
||||||
|
{
|
||||||
|
// Create tag builder
|
||||||
|
var builder = new TagBuilder("div");
|
||||||
|
var document = Document.Parse(text);
|
||||||
|
|
||||||
|
// builder.InnerHtml = .
|
||||||
|
|
||||||
|
// Add attributes
|
||||||
|
builder.MergeAttribute("class", "ascii");
|
||||||
|
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
|
||||||
|
|
||||||
|
// Render tag
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Yavsc.Helpers
|
namespace Yavsc.Helpers
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public static class HtmlHelpers
|
public static class HtmlHelpers
|
||||||
{
|
{
|
||||||
public static HtmlString Color(this Color c)
|
public static HtmlString Color(this Color c)
|
||||||
{
|
{
|
||||||
if (c==null) return new HtmlString("#000");
|
if (c == null) return new HtmlString("#000");
|
||||||
return new HtmlString(String.Format("#{0:X2}{1:X2}{2:X2}", c.Red, c.Green, c.Blue));
|
return new HtmlString(String.Format("#{0:X2}{1:X2}{2:X2}", c.Red, c.Green, c.Blue));
|
||||||
}
|
}
|
||||||
public static string ToAbsolute(this HttpRequest request, string url)
|
public static string ToAbsolute(this HttpRequest request, string url)
|
||||||
{
|
{
|
||||||
var host = request.Host;
|
var host = request.Host;
|
||||||
var isSecure = request.Headers[Constants.SshHeaderKey]=="on";
|
var isSecure = request.Headers[Constants.SshHeaderKey] == "on";
|
||||||
return (isSecure ? "https" : "http") + $"://{host}/{url}";
|
return (isSecure ? "https" : "http") + $"://{host}/{url}";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,8 @@ $('span.field-validation-valid[data-valmsg-for="Content"]').html(
|
||||||
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
<h1 class="blogtitle" ismarkdown>@Model.Title</h1>
|
||||||
<img class="blogphoto" alt="" src="@Model.Photo" >
|
<img class="blogphoto" alt="" src="@Model.Photo" >
|
||||||
<div class="blogpost">
|
<div class="blogpost">
|
||||||
|
@Html.AsciiDocFor(model => model.Content)
|
||||||
<div markdown="@Model.Content" class="blog"></div>
|
<p class="blog" asp-for="Content"></p>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@
|
||||||
@using Yavsc.Helpers;
|
@using Yavsc.Helpers;
|
||||||
|
|
||||||
@using PayPal.PayPalAPIInterfaceService.Model;
|
@using PayPal.PayPalAPIInterfaceService.Model;
|
||||||
|
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
@addTagHelper *, Yavsc
|
||||||
@inject IAuthorizationService AuthorizationService
|
@inject IAuthorizationService AuthorizationService
|
||||||
@inject Microsoft.AspNetCore.Mvc.Localization.IHtmlLocalizer<Yavsc.Startup> SR
|
@inject Microsoft.AspNetCore.Mvc.Localization.IHtmlLocalizer<Yavsc.Startup> SR
|
||||||
@inject Microsoft.Extensions.Options.IOptions<SiteSettings> SiteSettings
|
@inject Microsoft.Extensions.Options.IOptions<SiteSettings> SiteSettings
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue