asciidoc tag

This commit is contained in:
Paul Schneider 2023-04-08 01:10:36 +01:00
commit ec6424803b
6 changed files with 218 additions and 125 deletions

View file

@ -1,53 +1,8 @@
using System;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
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
{
public static class HtmlHelpers
{
public static HtmlString Color(this Color c)
@ -61,6 +16,5 @@ namespace Yavsc.Helpers
var isSecure = request.Headers[Constants.SshHeaderKey] == "on";
return (isSecure ? "https" : "http") + $"://{host}/{url}";
}
}
}